1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 1994-1998, 2001, 2005-2008 Peter Miller
5#
6#	This program is free software; you can redistribute it and/or modify
7#	it under the terms of the GNU General Public License as published by
8#	the Free Software Foundation; either version 3 of the License, or
9#	(at your option) any later version.
10#
11#	This program is distributed in the hope that it will be useful,
12#	but WITHOUT ANY WARRANTY; without even the implied warranty of
13#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#	GNU General Public License for more details.
15#
16#	You should have received a copy of the GNU General Public License
17#	along with this program. If not, see
18#	<http://www.gnu.org/licenses/>.
19#
20
21unset AEGIS_PROJECT
22unset AEGIS_CHANGE
23unset AEGIS_PATH
24unset AEGIS
25umask 022
26
27USER=${USER:-${LOGNAME:-`whoami`}}
28
29work=${AEGIS_TMP:-/tmp}/$$
30PAGER=cat
31export PAGER
32
33AEGIS_FLAGS="delete_file_preference = no_keep; \
34	lock_wait_preference = always; \
35	diff_preference = automatic_merge; \
36	pager_preference = never; \
37	persevere_preference = all; \
38	log_file_preference = never;"
39export AEGIS_FLAGS
40AEGIS_THROTTLE=-1
41export AEGIS_THROTTLE
42
43LINES=66
44export LINES
45COLS=80
46export COLS
47
48here=`pwd`
49if test $? -ne 0 ; then exit 2; fi
50
51if test "$1" != "" ; then bin="$here/$1/bin"; else bin="$here/bin"; fi
52
53if test "$1" != "" ; then AEGIS_DATADIR=$here/$1/lib; else AEGIS_DATADIR="$here/lib"; fi
54export AEGIS_DATADIR
55
56no_result()
57{
58	set +x
59	echo 'NO RESULT for test of the report generator functionality' 1>&2
60	cd $here
61	find $work -type d -user $USER -exec chmod u+w {} \;
62	rm -rf $work
63	exit 2
64}
65fail()
66{
67	set +x
68	echo 'FAILED test of the report generator functionality' 1>&2
69	cd $here
70	find $work -type d -user $USER -exec chmod u+w {} \;
71	rm -rf $work
72	exit 1
73}
74pass()
75{
76	set +x
77	echo PASSED
78	cd $here
79	find $work -type d -user $USER -exec chmod u+w {} \;
80	rm -rf $work
81	exit 0
82}
83trap \"no_result\" 1 2 3 15
84
85mkdir $work $work/lib $work/lib/report
86if test $? -ne 0 ; then no_result; fi
87cd $work
88if test $? -ne 0 ; then no_result; fi
89
90AEGIS_PATH=$work/lib
91export AEGIS_PATH
92
93#
94# test do and while loops
95#
96cat > test.in << 'fubar'
97title("(Do)While Statement", "delete this line");
98columns("Results");
99auto j;
100j = 0;
101while (j < 10)
102	print(++j);
103do
104	print(--j);
105while
106	(j > 0);
107print("=====");
108while (j < 10)
109	print(j++);
110do
111	print(j--);
112while
113	(j > 0);
114fubar
115if test $? -ne 0 ; then no_result; fi
116cat > test.ok << 'fubar'
1171
1182
1193
1204
1215
1226
1237
1248
1259
12610
1279
1288
1297
1306
1315
1324
1333
1342
1351
1360
137=====
1380
1391
1402
1413
1424
1435
1446
1457
1468
1479
14810
1499
1508
1517
1526
1535
1544
1553
1562
1571
158fubar
159if test $? -ne 0 ; then no_result; fi
160$bin/aegis -rpt -f test.in -unf -o test.out
161if test $? -ne 0 ; then fail; fi
162diff -b test.ok test.out
163if test $? -ne 0 ; then fail; fi
164
165#
166# test bit and logical operators
167#
168cat > test.in << 'fubar'
169title("Bit and Logical operators", "delete this line");
170columns("a", "b", "~a", "a&b", "a^b", "a|b", "!a", "a&&b", "a||b");
171auto a, b;
172for (a = -3; a <= 3; ++a)
173	for (b = -3; b <= 3; ++b)
174		print(a, b, ~a, a&b, a^b, a|b, !a, a&&b, a||b);
175fubar
176if test $? -ne 0 ; then no_result; fi
177cat > test.ok << 'fubar'
178-3 -3 2 -3 0 -3 false true true
179-3 -2 2 -4 3 -1 false true true
180-3 -1 2 -3 2 -1 false true true
181-3 0 2 0 -3 -3 false false true
182-3 1 2 1 -4 -3 false true true
183-3 2 2 0 -1 -1 false true true
184-3 3 2 1 -2 -1 false true true
185-2 -3 1 -4 3 -1 false true true
186-2 -2 1 -2 0 -2 false true true
187-2 -1 1 -2 1 -1 false true true
188-2 0 1 0 -2 -2 false false true
189-2 1 1 0 -1 -1 false true true
190-2 2 1 2 -4 -2 false true true
191-2 3 1 2 -3 -1 false true true
192-1 -3 0 -3 2 -1 false true true
193-1 -2 0 -2 1 -1 false true true
194-1 -1 0 -1 0 -1 false true true
195-1 0 0 0 -1 -1 false false true
196-1 1 0 1 -2 -1 false true true
197-1 2 0 2 -3 -1 false true true
198-1 3 0 3 -4 -1 false true true
1990 -3 -1 0 -3 -3 true false true
2000 -2 -1 0 -2 -2 true false true
2010 -1 -1 0 -1 -1 true false true
2020 0 -1 0 0 0 true false false
2030 1 -1 0 1 1 true false true
2040 2 -1 0 2 2 true false true
2050 3 -1 0 3 3 true false true
2061 -3 -2 1 -4 -3 false true true
2071 -2 -2 0 -1 -1 false true true
2081 -1 -2 1 -2 -1 false true true
2091 0 -2 0 1 1 false false true
2101 1 -2 1 0 1 false true true
2111 2 -2 0 3 3 false true true
2121 3 -2 1 2 3 false true true
2132 -3 -3 0 -1 -1 false true true
2142 -2 -3 2 -4 -2 false true true
2152 -1 -3 2 -3 -1 false true true
2162 0 -3 0 2 2 false false true
2172 1 -3 0 3 3 false true true
2182 2 -3 2 0 2 false true true
2192 3 -3 2 1 3 false true true
2203 -3 -4 1 -2 -1 false true true
2213 -2 -4 2 -3 -1 false true true
2223 -1 -4 3 -4 -1 false true true
2233 0 -4 0 3 3 false false true
2243 1 -4 1 2 3 false true true
2253 2 -4 2 1 3 false true true
2263 3 -4 3 0 3 false true true
227fubar
228if test $? -ne 0 ; then no_result; fi
229$bin/aegis -rpt -f test.in -o test.out -unf
230if test $? -ne 0 ; then fail; fi
231diff -b test.ok test.out
232if test $? -ne 0 ; then fail; fi
233
234#
235# test shift operators
236#
237cat > test.in << 'fubar'
238title("shift operators", "delete this line");
239columns
240(
241	{ name = "Index";   width = 5; },
242	{ name = "    Left"; width = 8; },
243	{ name = "   Right"; width = 8; }
244);
245auto a;
246for (a = 0; a < 32; ++a)
247{
248	print
249	(
250		a,
251		sprintf("%X", 1 << a),
252		sprintf("%X", 0x80000000 >> a)
253	);
254}
255fubar
256if test $? -ne 0 ; then no_result; fi
257cat > test.ok << 'fubar'
2580 1 80000000
2591 2 40000000
2602 4 20000000
2613 8 10000000
2624 10 8000000
2635 20 4000000
2646 40 2000000
2657 80 1000000
2668 100 800000
2679 200 400000
26810 400 200000
26911 800 100000
27012 1000 80000
27113 2000 40000
27214 4000 20000
27315 8000 10000
27416 10000 8000
27517 20000 4000
27618 40000 2000
27719 80000 1000
27820 100000 800
27921 200000 400
28022 400000 200
28123 800000 100
28224 1000000 80
28325 2000000 40
28426 4000000 20
28527 8000000 10
28628 10000000 8
28729 20000000 4
28830 40000000 2
28931 80000000 1
290fubar
291if test $? -ne 0 ; then no_result; fi
292$bin/aegis -rpt -f test.in -o test.out -unf
293if test $? -ne 0 ; then fail; fi
294diff -b test.ok test.out
295if test $? -ne 0 ; then fail; fi
296
297#
298# test join operator
299#
300cat > test.in << 'fubar'
301title("join operator", "delete this line");
302columns("a", "b", "a ## b");
303auto a, b, ab;
304for (a in ["a", 42, 1.3, [1, 2, "3"]])
305{
306	auto ta, ca, tb, cb, tab, cab;
307	ta = typeof(a);
308	ca = ta == "list" ? ta : a;
309	for (b in ["a", 42, 1.3, [1, 2, "3"]])
310	{
311		tb = typeof(b);
312		cb = tb == "list" ? tb : b;
313		ab = a ## b;
314		tab = typeof(ab);
315		if (tab == "list")
316			cab = tab;
317		else
318			cab = ab;
319		print(ca, cb, cab);
320	}
321}
322fubar
323if test $? -ne 0 ; then no_result; fi
324cat > test.ok << 'fubar'
325a a aa
326a 42 a42
327a 1.3 a1.3
328a list list
32942 a 42a
33042 42 4242
33142 1.3 421.3
33242 list list
3331.3 a 1.3a
3341.3 42 1.342
3351.3 1.3 1.31.3
3361.3 list list
337list a list
338list 42 list
339list 1.3 list
340list list list
341fubar
342if test $? -ne 0 ; then no_result; fi
343$bin/aegis -rpt -f test.in -o test.out -unf
344if test $? -ne 0 ; then fail; fi
345diff -b test.ok test.out
346if test $? -ne 0 ; then fail; fi
347
348#
349# test assignment operators
350#
351cat > test.in << 'fubar'
352title("assignment operators", "delete this line");
353columns({ name = "Result"; width = 40; });
354auto a;
355a = 0;		print(a);
356a += 2;		print(a);
357a -= 6;		print(a);
358a *= -5.6;	print(a);
359a /= 4.2;	print(a);
360a %= 2;		print(a);
361a &= 1;		print(a);
362a ^= 9;		print(a);
363a |= 2;		print(a);
364a <<= 3;	print(a);
365a >>= 1;	print(a);
366a **= 2.1;	print(a);
367a ##= "boo!";	print(a);
368fubar
369if test $? -ne 0 ; then no_result; fi
370cat > test.ok << 'fubar'
3710
3722
373-4
37422.4
3755.33333
3761.33333
3771
3788
37910
38080
38140
3822313.8
3832313.8boo!
384fubar
385if test $? -ne 0 ; then no_result; fi
386$bin/aegis -rpt -f test.in -o test.out -unf
387if test $? -ne 0 ; then fail; fi
388diff -b test.ok test.out
389if test $? -ne 0 ; then fail; fi
390
391#
392# test report search path
393#
394cat > $work/lib/report.index << 'fubar'
395where =
396[
397	{
398		name = "Test";
399		description = "look for this line";
400		filename = "test.rpt";
401	}
402];
403fubar
404if test $? -ne 0 ; then no_result; fi
405cat > $work/lib/test.rpt << 'fubar'
406title("report searching", "delete this line");
407columns("x", "sqrt(x)", "sqr(x)");
408auto a;
409for (a = 0; a < 10; ++a)
410	print(a, a ** 0.5, a ** 2);
411fubar
412if test $? -ne 0 ; then no_result; fi
413cat > test.ok << 'fubar'
4140 0 0
4151 1 1
4162 1.41421 4
4173 1.73205 9
4184 2 16
4195 2.23607 25
4206 2.44949 36
4217 2.64575 49
4228 2.82843 64
4239 3 81
424fubar
425if test $? -ne 0 ; then no_result; fi
426$bin/aegis -rpt t -o test.out -unf
427if test $? -ne 0 ; then fail; fi
428diff -b test.ok test.out
429if test $? -ne 0 ; then fail; fi
430
431#
432# test report listing
433#
434cat > test.ok << fubar
435Test look for this line
436fubar
437if test $? -ne 0 ; then no_result; fi
438$bin/aegis -rpt -list -unf > test.out
439if test $? -ne 0 ; then fail; fi
440grep 'look for this line' test.out > test.out2
441if test $? -ne 0 ; then no_result; fi
442sed -e 's| /.*||' < test.out2 > test.out3
443if test $? -ne 0 ; then no_result; fi
444diff -b test.ok test.out3
445if test $? -ne 0 ; then fail; fi
446
447#
448# test getuid() function
449#
450cat > test.in << 'fubar'
451title("getuid function", "delete this line");
452columns({ width = 1000; });
453auto who_am_i;
454print(passwd[getuid()].pw_name);
455fubar
456if test $? -ne 0 ; then no_result; fi
457echo $USER > test.ok
458if test $? -ne 0 ; then no_result; fi
459$bin/aegis -rpt -f test.in -o test.out -unf
460if test $? -ne 0 ; then fail; fi
461diff -b test.ok test.out
462if test $? -ne 0 ; then fail; fi
463
464#
465# Only definite negatives are possible.
466# The functionality exercised by this test appears to work,
467# no other guarantees are made.
468#
469pass
470