1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 1996-1998, 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
25unset LINES
26unset COLS
27umask 022
28
29USER=${USER:-${LOGNAME:-`whoami`}}
30
31work=${AEGIS_TMP:-/tmp}/$$
32PAGER=cat
33export PAGER
34AEGIS_FLAGS="delete_file_preference = no_keep; \
35	lock_wait_preference = always; \
36	diff_preference = automatic_merge; \
37	pager_preference = never; \
38	persevere_preference = all; \
39	log_file_preference = never;"
40export AEGIS_FLAGS
41AEGIS_THROTTLE=-1
42export AEGIS_THROTTLE
43
44here=`pwd`
45if test $? -ne 0 ; then exit 2; fi
46
47bin=$here/${1-.}/bin
48
49no_result()
50{
51	set +x
52	echo 'NO RESULT for test of the throw/catch report functionality' 1>&2
53	cd $here
54	find $work -type d -user $USER -exec chmod u+w {} \;
55	rm -rf $work
56	exit 2
57}
58fail()
59{
60	set +x
61	echo 'FAILED test of the throw/catch report functionality' 1>&2
62	cd $here
63	find $work -type d -user $USER -exec chmod u+w {} \;
64	rm -rf $work
65	exit 1
66}
67pass()
68{
69	set +x
70	echo PASSED 1>&2
71	cd $here
72	find $work -type d -user $USER -exec chmod u+w {} \;
73	rm -rf $work
74	exit 0
75}
76trap \"no_result\" 1 2 3 15
77
78mkdir $work $work/lib
79if test $? -ne 0 ; then no_result; fi
80chmod 777 $work/lib
81if test $? -ne 0 ; then no_result; fi
82cd $work
83if test $? -ne 0 ; then no_result; fi
84
85#
86# use the built-in error messages
87#
88AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
89export AEGIS_MESSAGE_LIBRARY
90unset LANG
91unset LANGUAGE
92
93#
94# test the uncaught exception functionality
95#
96cat  > test.in << 'fubar'
97title("throw catch test");
98columns(80);
99auto a, b;
100a = 10;
101b = 0;
102print(a / b);
103fubar
104if test $? -ne 0 ; then no_result; fi
105
106cat > test.ok << 'fubar'
107aegis: test.in: 6: division by zero
108aegis: report aborted
109fubar
110if test $? -ne 0 ; then no_result; fi
111
112$bin/aegis -rpt -f test.in -ter > test.out 2>&1
113if test $? -ne 1 ; then fail; fi
114
115diff test.ok test.out
116if test $? -ne 0 ; then fail; fi
117
118#
119# test the try/catch statement
120#
121cat  > test.in << 'fubar'
122title("throw catch test");
123columns(8, 8, 8);
124auto a, b, c;
125for (a = -2.; a <= 2; ++a)
126{
127	for (b = -2.; b <= 2; ++b)
128	{
129		try
130			print(a, b, a/b);
131		catch (c)
132			print(a, b, "infinity");
133	}
134}
135fubar
136if test $? -ne 0 ; then no_result; fi
137
138cat > test.ok << 'fubar'
139-2 -2 1
140-2 -1 2
141-2 0 infinity
142-2 1 -2
143-2 2 -1
144-1 -2 0.5
145-1 -1 1
146-1 0 infinity
147-1 1 -1
148-1 2 -0.5
1490 -2 0
1500 -1 0
1510 0 infinity
1520 1 0
1530 2 0
1541 -2 -0.5
1551 -1 -1
1561 0 infinity
1571 1 1
1581 2 0.5
1592 -2 -1
1602 -1 -2
1612 0 infinity
1622 1 2
1632 2 1
164fubar
165if test $? -ne 0 ; then no_result; fi
166
167$bin/aegis -rpt -f test.in -ter -o test.out
168if test $? -ne 0 ; then fail; fi
169
170diff -b test.ok test.out
171if test $? -ne 0 ; then fail; fi
172
173#
174# test the throw statement
175#
176cat  > test.in << 'fubar'
177title("throw catch test");
178columns(80);
179auto a;
180try
181{
182	throw("boo boo");
183	print("this should never happen");
184}
185catch (a)
186	print(a);
187fubar
188if test $? -ne 0 ; then no_result; fi
189
190cat > test.ok << 'fubar'
191boo boo
192fubar
193if test $? -ne 0 ; then no_result; fi
194
195$bin/aegis -rpt -f test.in -ter -o test.out
196if test $? -ne 0 ; then fail; fi
197
198diff -b test.ok test.out
199if test $? -ne 0 ; then fail; fi
200
201#
202# Only definite negatives are possible.
203# The functionality exercised by this test appears to work,
204# no other guarantees are made.
205#
206pass
207