summaryrefslogtreecommitdiff
path: root/mnv/runtime/syntax/testdir/tools/regenerate_screendumps.sh
blob: 9dfdad306f2cd5bd154ed051c107dd91f1e8587d (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
#!/bin/sh -e
#
# The following steps are to be taken by this script:
# 1) Remove all files from the "dumps" directory.
# 2) Generate screendumps for each syntax test and each self-test.
# 3) Unconditionally move each batch of screendumps to "dumps"; if generated
#	files differ on repeated runs, always remove these files from "dumps".
# 4) Repeat steps 2) and 3) once or as many times as requested with the "$1"
#	argument.
# 5) Summarise any differences.
#
# Provided that "git difftool" is set up (see src/testdir/commondumps.mnv),
# run "git difftool HEAD -- '**/*.dump'" to collate tracked and generated
# screendumps.

case "$1" in
-h | --help)
	printf >&2 "Usage: [time MNV_SYNTAX_TEST_LOG=/tmp/log] $0 [1 | 2 | ...]\n"
	exit 0
	;;
esac

tries="${1:-1}"
shift $#

case "$tries" in
0* | *[!0-9]*)
	exit 80
	;;
esac

test -x "$(command -v make)"	|| exit 81
test -x "$(command -v git)"	|| exit 82

case "$(git status --porcelain=v1)" in
'')	;;
*)	printf >&2 'Resolve ALL changes before proceeding.\n'
	exit 83
	;;
esac

templet=$(printf "\t\t\t\t$(tput rev)%%s$(tput sgr0)") || exit 84
cd "$(dirname "$0")/../../../syntax" || exit 85
set +f
rm testdir/dumps/*.dump || exit 86
spuriosities=''

# Because the clean target of Make will be executed before each syntax test,
# this environment variable needs to be pointed to an existing file that is
# created in a directory not affectable by the target.
if test -w "$MNV_SYNTAX_TEST_LOG"
then
	log=-e MNV_SYNTAX_TEST_LOG="$MNV_SYNTAX_TEST_LOG"
else
	log=
fi

for f in testdir/input/*.*
do
	test ! -d "$f" || continue
	b=$(basename "$f")
	i=0
	printf "$templet\n\n" "$b"

	while test "$i" -le "$tries"
	do
		make $log clean "$b" test || :

		case "$i" in
		0)	mv testdir/failed/*.dump testdir/dumps/
			;;
		*)	case "$(printf '%s' testdir/failed/*.dump)" in
			testdir/failed/\*.dump)
				# (Repeatable) success.
				;;
			*)	spuriosities="${spuriosities}${b} "
				p=${b%.*}
				rm -f testdir/dumps/"$p"_[0-9][0-9].dump \
					testdir/dumps/"$p"_[0-9][0-9][0-9].dump \
					testdir/dumps/"$p"_[0-9][0-9][0-9][0-9].dump
				;;
			esac
			;;
		esac

		i=$(($i + 1))
		sleep 1
	done
done

# For a 20-file set, initially fail for a series of: 1-6, 7-12, 13-18, 19-20.
tries=$(($tries + 3))
i=0

while test "$i" -le "$tries"
do
	make $log clean self-testing test || :

	case "$i" in
	[0-3])	mv testdir/failed/dots_*.dump testdir/dumps/
		;;
	*)	case "$(printf '%s' testdir/failed/*.dump)" in
		testdir/failed/\*.dump)
			# (Repeatable) success.
			;;
		*)	spuriosities="${spuriosities}dots_xy "
			rm -f testdir/dumps/dots_*.dump
			;;
		esac
		;;
	esac

	sleep 1
	i=$(($i + 1))
done

make clean
git diff --compact-summary

if test -n "$spuriosities"
then
	printf '\n%s\n' "$spuriosities"
	exit 87
fi

# mnv:sw=8:ts=8:noet:nosta: