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>
Makefile
*.mk.tmp
+*.mk.expected.tmp
+doctest.sd.mk
+doctest.mk.part
# autogenerated - do not edit
# test cases for generate script
+# doctests:
all:: $(TOP_TARGETS) sub/all
.PHONY: all
# test cases for generate script
+# doctests:
+&:include doctest.sd.mk
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.
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)
# 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