From 78995cd20340b0a913870b10c096eb85fdc5f1a9 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 24 Dec 2019 00:49:00 +0000 Subject: [PATCH] doctests: Extract and use Include the doctests from the toplevel Subdir.sd.mk. In check, extract the doctests, and seddery the expected output into the combined expected output file. This involves adding a comment in Subdir.mk.expected to indicate where the doctests will appear. In update-expected, contrive to strip the doctest output back out of the actual output so we can update only the manually-edited part. Consequential changes to MAKEFILE_TEMPLATES in main.mk.expected and .gitignore. Signed-off-by: Ian Jackson --- tests/filter/.gitignore | 3 +++ tests/filter/Subdir.mk.expected | 1 + tests/filter/Subdir.sd.mk | 2 ++ tests/filter/check | 13 ++++++++++++- tests/filter/main.mk.expected | 1 + tests/filter/update-expected | 12 ++++++++++-- 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/tests/filter/.gitignore b/tests/filter/.gitignore index 08c232c..802a3e6 100644 --- a/tests/filter/.gitignore +++ b/tests/filter/.gitignore @@ -1,2 +1,5 @@ Makefile *.mk.tmp +*.mk.expected.tmp +doctest.sd.mk +doctest.mk.part diff --git a/tests/filter/Subdir.mk.expected b/tests/filter/Subdir.mk.expected index 84f7309..c0bc70f 100644 --- a/tests/filter/Subdir.mk.expected +++ b/tests/filter/Subdir.mk.expected @@ -1,5 +1,6 @@ # autogenerated - do not edit # test cases for generate script +# doctests: all:: $(TOP_TARGETS) sub/all .PHONY: all diff --git a/tests/filter/Subdir.sd.mk b/tests/filter/Subdir.sd.mk index f942367..9e51e23 100644 --- a/tests/filter/Subdir.sd.mk +++ b/tests/filter/Subdir.sd.mk @@ -1 +1,3 @@ # test cases for generate script +# doctests: +&:include doctest.sd.mk diff --git a/tests/filter/check b/tests/filter/check index 2a5a8ee..18ead3e 100755 --- a/tests/filter/check +++ b/tests/filter/check @@ -2,8 +2,19 @@ set -e cd tests/filter + +expand <../../README | ./extract-doctest . >/dev/null + ../../generate sub/dir files=$(find -name \*.expected) -for f in $files; do diff -u $f ${f%.expected}.tmp; done +for f in $files; do + sed <$f >$f.tmp ' + /^# doctests:/ { + r '"${f%/*}/doctest.mk.part"' + a + } + ' + diff -u $f.tmp ${f%.expected}.tmp +done echo ok. diff --git a/tests/filter/main.mk.expected b/tests/filter/main.mk.expected index ba72c96..110c608 100644 --- a/tests/filter/main.mk.expected +++ b/tests/filter/main.mk.expected @@ -7,5 +7,6 @@ SUBDIRMK_MAKEFILES += Subdir.mk SUBDIRMK_MAKEFILES += sub/Subdir.mk SUBDIRMK_MAKEFILES += sub/dir/Subdir.mk MAKEFILE_TEMPLATES += ./Subdir.sd.mk +MAKEFILE_TEMPLATES += ./doctest.sd.mk MAKEFILE_TEMPLATES += ./sub/dir/Subdir.sd.mk include $(SUBDIRMK_MAKEFILES) diff --git a/tests/filter/update-expected b/tests/filter/update-expected index ff10542..18c53cf 100755 --- a/tests/filter/update-expected +++ b/tests/filter/update-expected @@ -6,5 +6,13 @@ # selectively git-add the things that are right, after inspecting them set -e -files=$(find tests/filter -name \*.tmp) -for f in $files; do cp $f ${f%.tmp}.expected; done +files=$(find tests/filter -name \*.expected.tmp) +for f in $files; do + perl -pe ' + (s/\n//, $stripnl=0) if $stripnl; + next unless /^# doctest starts/../^# doctest ends/; + $_=""; + $stripnl=1; + ' \ + <${f%.expected.tmp}.tmp >${f%.tmp} +done -- 2.30.2