[build-path-prefix-map-spec] 41/50: Generate an rst report of the test cases and include this in the spec

Ximin Luo infinity0 at debian.org
Fri Mar 10 15:17:22 UTC 2017


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch master
in repository build-path-prefix-map-spec.

commit 0611a8244b0b80369a33e43cded27b7955aa6dd6
Author: Ximin Luo <infinity0 at debian.org>
Date:   Fri Feb 24 18:16:17 2017 +0100

    Generate an rst report of the test cases and include this in the spec
---
 .gitignore                             |  3 ++
 Makefile                               | 22 ++++++++++++++
 consume/Makefile                       | 26 ++++++++++++-----
 consume/{check-generic.sh => check.sh} |  0
 consume/make_printable.py              | 17 +++++++++++
 consume/testcases-rst.css              |  8 ++++++
 consume/testcases-rst.sh               | 52 ++++++++++++++++++++++++++++++++++
 spec-draft.rst => spec-main.rst        | 25 ++++++++++------
 8 files changed, 138 insertions(+), 15 deletions(-)

diff --git a/.gitignore b/.gitignore
index 054f20e..3f99414 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,7 @@
 /consume/*.out
+/consume/*.rst
+/consume/*.html
 /consume/afl-in-*
 /consume/afl-out-*
 /produce/*.html
+/*.html
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a1dce40
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,22 @@
+all: spec.html
+
+%.html: %.rst %.css
+	pandoc -s --css "$*.css" "$<" > "$@"
+
+spec.rst: spec-main.rst spec-testcases.rst
+	cat $^ > "$@"
+
+T = testcases-rst-pecsplit.rst
+.PHONY: consume/$(T)
+consume/$(T):
+	$(MAKE) -C consume $(T)
+
+spec-testcases.rst: consume/testcases-rst-pecsplit.rst
+	cp "$<" "$@"
+
+spec.css: consume/testcases-rst.css
+	cp "$<" "$@"
+
+.PHONY: clean
+clean:
+	rm -f *.html spec.css spec-testcases.rst spec.rst
diff --git a/consume/Makefile b/consume/Makefile
index bc1c96d..54523cf 100644
--- a/consume/Makefile
+++ b/consume/Makefile
@@ -20,7 +20,7 @@ RUSTC ?= rustc
 # 1 key, e.g. "0" or "pecsplit.0"
 # 2 suffix that indicates a test, e.g. "in" or "env"
 find_testcases = \
-	TESTCASES_$(1) = $(patsubst $(T)$(1).%.$(2),$(1).%,$(wildcard $(T)$(1).*.$(2)))
+	TESTCASES_$(1) = $(sort $(patsubst $(T)$(1).%.$(2),$(1).%,$(wildcard $(T)$(1).*.$(2))))
 $(eval $(call find_testcases,0,in))
 $(eval $(call find_testcases,1,in))
 $(foreach format,$(ALL_FORMATS),$(eval $(call find_testcases,$(format).0,env)))
@@ -35,17 +35,28 @@ all: $(ALL_SOURCE:%=%.out)
 %.rs.out: %.rs
 	$(RUSTC) -W warnings -o "$@" "$<"
 
-.PHONY: check
+.PHONY: check testcases-rst
 check: $(ALL_FORMATS:%=check-%)
+testcases-rst: $(ALL_FORMATS:%=testcases-rst-%.html)
 
 export TESTDIR = $(T)
-.PHONY: check-%
 check-%:
 	$(MAKE) $(ALLCHECK_$*)
-	set -e; for case in $(TESTCASES_0); do ./check-generic.sh "$(ALLCHECK_$*)" $* 0 $$case $$case.$* $$case; done
-	set -e; for case in $(TESTCASES_1); do ./check-generic.sh "$(ALLCHECK_$*)" $* 1 $$case $$case.$* $$case; done
-	set -e; for case in $(TESTCASES_$*.0); do ./check-generic.sh "$(ALLCHECK_$*)" $* 0 $$case $$case $*.0; done
-	set -e; for case in $(TESTCASES_$*.1); do ./check-generic.sh "$(ALLCHECK_$*)" $* 1 $$case $$case $*.1; done
+	set -e; for case in $(TESTCASES_0); do ./check.sh "$(ALLCHECK_$*)" $* 0 $$case $$case.$* $$case; done
+	set -e; for case in $(TESTCASES_1); do ./check.sh "$(ALLCHECK_$*)" $* 1 $$case $$case.$* $$case; done
+	set -e; for case in $(TESTCASES_$*.0); do ./check.sh "$(ALLCHECK_$*)" $* 0 $$case $$case $*.0; done
+	set -e; for case in $(TESTCASES_$*.1); do ./check.sh "$(ALLCHECK_$*)" $* 1 $$case $$case $*.1; done
+
+testcases-rst-%.html: testcases-rst-%.rst
+	pandoc -s --css testcases-rst.css "$<" > "$@"
+
+testcases-rst-%.rst: $(wildcard $(T)/*) Makefile
+	rm -f "$@" "$@.tmp" && touch "$@.tmp"
+	set -e; for case in $(TESTCASES_0); do ./testcases-rst.sh $* $$case $$case.$* $$case valid; done >> "$@.tmp"
+	set -e; for case in $(TESTCASES_1); do ./testcases-rst.sh $* $$case $$case.$* $$case invalid; done >> "$@.tmp"
+	set -e; for case in $(TESTCASES_$*.0); do ./testcases-rst.sh $* $$case $$case $*.0 valid; done >> "$@.tmp"
+	set -e; for case in $(TESTCASES_$*.1); do ./testcases-rst.sh $* $$case $$case $*.1 invalid; done >> "$@.tmp"
+	mv "$@.tmp" "$@"
 
 make-afl-test-case = \
 	cat testcases/$(3).$(1).env testcases/$(3).in > afl-in-$(1)/$(3).in;
@@ -77,6 +88,7 @@ reset-fuzz-%:
 clean:
 	rm -f $(ALL_SOURCE:%=%.out)
 	rm -rf $(ALL_FORMATS:%=afl-in-%)
+	rm -f *.rst *.html
 
 .PHONY: clean-all
 clean-all: clean $(ALL_SOURCE:%=reset-fuzz-%)
diff --git a/consume/check-generic.sh b/consume/check.sh
similarity index 100%
rename from consume/check-generic.sh
rename to consume/check.sh
diff --git a/consume/make_printable.py b/consume/make_printable.py
new file mode 100755
index 0000000..b93a514
--- /dev/null
+++ b/consume/make_printable.py
@@ -0,0 +1,17 @@
+#!/usr/bin/python3
+
+import string
+import sys
+import textwrap
+
+sanitized = [x for x in string.printable if x not in string.whitespace or x in " \n"]
+
+contents = open(sys.argv[1], 'rb').read().rstrip(b'\n')
+try:
+    contents = contents.decode("utf-8")
+    if all(x in sanitized for x in contents):
+        print(contents)
+    else:
+        print("\u200b".join(repr(contents)))
+except UnicodeDecodeError:
+    print("".join(repr(contents)))
diff --git a/consume/testcases-rst.css b/consume/testcases-rst.css
new file mode 100644
index 0000000..acffe57
--- /dev/null
+++ b/consume/testcases-rst.css
@@ -0,0 +1,8 @@
+p code {
+    white-space: normal;
+    word-break: break-all;
+}
+
+pre, blockquote {
+    margin-left: 40px;
+}
diff --git a/consume/testcases-rst.sh b/consume/testcases-rst.sh
new file mode 100755
index 0000000..3a7f70f
--- /dev/null
+++ b/consume/testcases-rst.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# Args:
+# 1 format name
+# 2 prefix for .in, .out
+# 3 prefix for .env
+# 4 prefix for .in, .out if $4 doesn't exist
+# 5 cases
+# 6 parse result e.g. "valid" or "invalid"
+
+T="$TESTDIR"
+
+print_section() {
+	local header="$1"
+	shift
+	echo "$header"
+	echo
+	"$@" | sed -e 's/^/\t/g'
+	echo
+}
+
+dump_or_ref() {
+	if [ -h "$2" ]; then
+		local dst="$(readlink "$2")"
+		if [ "${dst%.out}" != "$dst" ]; then
+			print_section "${1}:" echo "(same as the output for Case '${dst%.out}')"
+		elif [ "${dst%.in}" != "$dst" ]; then
+			print_section "${1}:" echo "(same as the input for Case '${dst%.in}')"
+		else
+			echo >&2 "ERROR: unknown symlink"
+			exit 1
+		fi
+	else
+		print_section "${1}::" ./make_printable.py "$2"
+	fi
+}
+
+case="$2"
+
+	if [ -f "${T}${2}.in" ]; then input="${T}${2}.in"; else input="${T}${4}.in"; fi
+	if [ -f "${T}${2}.out" ]; then output="${T}${2}.out"; else output="${T}${4}.out"; fi
+	envfile="${T}${3}.env"
+
+	if [ -s "$output" ]; then
+		dump_or_ref "Case '$2', **${5}**"': ``'"$(./make_printable.py "$envfile")"'`` maps' "$input"
+		dump_or_ref 'to' "$output"
+
+	else
+		echo "Case '$2', **${5}**"': ``'"$(./make_printable.py "$envfile")"'``'
+		echo
+
+	fi
+#done
diff --git a/spec-draft.rst b/spec-main.rst
similarity index 94%
rename from spec-draft.rst
rename to spec-main.rst
index d5604a5..fcf1e9a 100644
--- a/spec-draft.rst
+++ b/spec-main.rst
@@ -99,7 +99,7 @@ The encoding is as follows:
 
   B. encoding:
 
-     we don't anticipate this to be a major use-case
+     - We don't anticipate this to be a major use-case
 
 
 Setting the encoded value
@@ -150,12 +150,6 @@ Consumers SHOULD implement one of the following algorithms:
    This has more robust semantics but is slightly more complex to implement.
 
 
-Test vectors
-============
-
-TODO
-
-
 Notes and links
 ===============
 
@@ -188,7 +182,7 @@ POSIX system strings
 
 - `Definitions (no HTTPS)
   <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html>`_
-  - see "Pathname", "String" and "Byte".
+  -- see "Pathname", "String" and "Byte".
 
 - `Environment Variables (no HTTPS)
   <http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html>`_
@@ -227,3 +221,18 @@ to do this, is to treat them as opaque 16-bit sequences with no encoding.
   This often-cited page is not actually relevant to filesystem paths or
   environment variable values, and rather instead refers to how Windows
   applications deal with userland, not system, character data.
+
+
+Appendix
+============
+
+Test vectors
+------------
+
+In the below, statements of the form "E maps I to O" means that when E is set
+as the value of ``BUILD_PATH_PREFIX_MAP``, then a compliant consumer, when
+implementing either algorithm 1 or 2 in "Applying the decoded structure",
+should map line-separated input paths I to line-separated output paths O.
+
+Where E is wrapped by ``b'`` and ``'``, it is to be interpreted as a sequence
+of bytes, represented in the same way as Python byte literals.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/build-path-prefix-map-spec.git



More information about the Reproducible-commits mailing list