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 08c232ca8386baf52690c435fabf49c72738e384..802a3e6344bb85619c94477b00ba2dde8fef9fe3 100644 (file)
@@ -1,2 +1,5 @@
 Makefile
 *.mk.tmp
+*.mk.expected.tmp
+doctest.sd.mk
+doctest.mk.part
index 84f73093d02ce6ee1d53fbc911255539b1674ef8..c0bc70f593b540fd3e391793c391525d78e4140c 100644 (file)
@@ -1,5 +1,6 @@
 # autogenerated - do not edit
 # test cases for generate script
+# doctests:
 
 all:: $(TOP_TARGETS) sub/all
 .PHONY: all
index f9423674c6a55f695a8401644f92fc6e3aef817c..9e51e2363b6d1ca15cf49289c8953f9ae66bb298 100644 (file)
@@ -1 +1,3 @@
 # test cases for generate script
+# doctests:
+&:include doctest.sd.mk
index 2a5a8ee1d9be97df9dafe0531c6e7af7786e50d8..18ead3eb444a0823a706cd1ef99910238e402b26 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 ba72c96dcb7937c13ecf1b37f6a9a91d4c8cf175..110c60880a2815c2c2bc6ec2179058c4a5452488 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 ff105423fa427ffe1d68836c36fe76735f4fb9f9..18c53cff4cfdf15d6f925f0b6cf55d4151e6c970 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