chiark / gitweb /
doctests: Extract and use
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 24 Dec 2019 00:49:00 +0000 (00:49 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 28 Dec 2019 22:19:08 +0000 (22:19 +0000)
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 <ijackson@chiark.greenend.org.uk>
tests/filter/.gitignore
tests/filter/Subdir.mk.expected
tests/filter/Subdir.sd.mk
tests/filter/check
tests/filter/main.mk.expected
tests/filter/update-expected

index 08c232c..802a3e6 100644 (file)
@@ -1,2 +1,5 @@
 Makefile
 *.mk.tmp
+*.mk.expected.tmp
+doctest.sd.mk
+doctest.mk.part
index 84f7309..c0bc70f 100644 (file)
@@ -1,5 +1,6 @@
 # autogenerated - do not edit
 # test cases for generate script
+# doctests:
 
 all:: $(TOP_TARGETS) sub/all
 .PHONY: all
index f942367..9e51e23 100644 (file)
@@ -1 +1,3 @@
 # test cases for generate script
+# doctests:
+&:include doctest.sd.mk
index 2a5a8ee..18ead3e 100755 (executable)
@@ -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.
index ba72c96..110c608 100644 (file)
@@ -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)
index ff10542..18c53cf 100755 (executable)
@@ -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