aboutsummaryrefslogtreecommitdiffstats
path: root/test/Gentests
diff options
context:
space:
mode:
Diffstat (limited to 'test/Gentests')
-rwxr-xr-xtest/Gentests92
1 files changed, 92 insertions, 0 deletions
diff --git a/test/Gentests b/test/Gentests
new file mode 100755
index 00000000..10401ddf
--- /dev/null
+++ b/test/Gentests
@@ -0,0 +1,92 @@
+#!/usr/bin/gawk -f
+
+# This program should generate Maketests
+
+BEGIN {
+ # read the list of files
+ for (i = 2; i < ARGC; i++)
+ files[ARGV[i]]
+
+ # throw it away
+ ARGC = 2
+
+ ntests = 0
+}
+
+# process the file Makefile.am:
+
+/^[A-Z_]*_TESTS *=/,/[^\\]$/ {
+ gsub(/(^[A-Z_]*_TESTS *=|\\$)/,"")
+ for (i = 1; i <= NF; i++)
+ tests[++ntests] = $i
+ next
+}
+
+/^NEED_LINT *=/,/[^\\]$/ {
+ gsub(/(^NEED_LINT *=|\\$)/,"")
+ for (i = 1; i <= NF; i++)
+ lint[$i]
+ next
+}
+
+/^GENTESTS_UNUSED *=/,/[^\\]$/ {
+ gsub(/(^GENTESTS_UNUSED *=|\\$)/,"")
+ for (i = 1; i <= NF; i++)
+ unused[$i]
+ next
+}
+
+/^[a-zA-Z][a-zA-Z0-9]*:/ {
+ # remember all targets from Makefile.am
+ sub(/:.*/,"")
+ targets[$0]
+}
+
+# Now write the output file:
+END {
+ # this line tells automake to keep the comment with the rules:
+ print "Gt-dummy:"
+ print "# file Maketests, generated from Makefile.am by the Gentests program"
+
+ for (i = 1; i <= ntests; i++) {
+ x = tests[i]
+ if (!(x in targets))
+ generate(x)
+ }
+
+ print "# end of file Maketests"
+}
+
+function generate(x, s)
+{
+ if (!(x".awk" in files))
+ printf "WARNING: file `%s.awk' not found.\n", x > "/dev/stderr"
+ else
+ delete files[x".awk"]
+
+ print x ":"
+
+ s = ""
+ if (x in lint) {
+ s = s " --lint"
+ delete lint[x]
+ }
+ if (x".in" in files) {
+ s = s " < $(srcdir)/$@.in"
+ delete files[x".in"]
+ }
+
+ printf "\t@echo %s\n", x
+ printf "\t@AWKPATH=$(srcdir) $(AWK) -f $@.awk %s >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@\n", s
+ printf "\t@-$(CMP) $(srcdir)/$@.ok _$@ && rm -f _$@\n\n"
+}
+
+END {
+ for (x in lint)
+ if (!(x in targets))
+ printf "WARNING: --lint target `%s' is missing.\n", x > "/dev/stderr"
+ for (x in files)
+ if (!(x in unused) && \
+ !(gensub(/\.(awk|in)$/,"","",x) in targets))
+ printf "WARNING: unused file `%s'.\n", x > "/dev/stderr"
+}