aboutsummaryrefslogtreecommitdiffstats
path: root/test/Gentests
blob: 5a7aaa09d377d2381c110aa073bf39093cc1375e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/gawk -f

# This program should generate Maketests

BEGIN {
	if (VMSTESTS) vmsargvfixup()

	# 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:

/^[[:upper:]_]*_TESTS *=/,/[^\\]$/ {
	gsub(/(^[[:upper:]_]*_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
}

/^NEED_LINT_OLD *=/,/[^\\]$/ {
	gsub(/(^NEED_LINT_OLD *=|\\$)/,"")
	for (i = 1; i <= NF; i++)
		lint_old[$i]
	next
}

/^GENTESTS_UNUSED *=/,/[^\\]$/ {
	gsub(/(^GENTESTS_UNUSED *=|\\$)/,"")
	for (i = 1; i <= NF; i++)
		unused[$i]
	next
}

/^CHECK_MPFR *=/,/[^\\]$/ {
	gsub(/(^CHECK_MPFR *=|\\$)/,"")
	for (i = 1; i <= NF; i++)
	{
		mpfr[$i]
	}
	next
}

/^[[:alpha:]_][[:alnum:]_]*:/ {
	# 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"]

	if (VMSTESTS) return vmsgenerate(x)

	print x ":"

	s = ""
	if (x in lint) {
		s = s " --lint"
		delete lint[x]
	}
	if (x in lint_old) {
		s = s " --lint-old"
		delete lint_old[x]
	}
	if (x".in" in files) {
		s = s " < \"$(srcdir)\"/$@.in"
		delete files[x".in"]
	}

	printf "\t@echo $@\n"

	if (x in mpfr) {
		delete mpfr[x]
		printf "\t@AWKPATH=\"$(srcdir)\" $(AWK) $(AWKFLAGS) -f $@.awk %s >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@\n", s
		printf "\t@-if test -z \"$$AWKFLAGS\" ; then $(CMP) \"$(srcdir)\"/$@.ok _$@ && rm -f _$@ ; else \\\n"
		printf "\t$(CMP) \"$(srcdir)\"/$@-mpfr.ok _$@ && rm -f _$@ ; \\\n"
		printf "\tfi\n\n"
	} else {
		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 lint_old)
		if (!(x in targets))
			printf "WARNING: --lint-old target `%s' is missing.\n", x > "/dev/stderr"
	for (x in files)
		if (!(x in unused) && \
		    !(gensub(/\.(awk|in)$/,"",1,x) in targets))
			printf "WARNING: unused file `%s'.\n", x > "/dev/stderr"
}

# VMSTESTS: generate test template in vms format
# gawk -v "VMSTESTS=1" -f Gentests -f Gentests.vms Makefile.am *.awk *.in >Maketests.vms