1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 2002, 2004-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
27LINES=24
28export LINES
29COLS=80
30export COLS
31
32USER=${USER:-${LOGNAME:-`whoami`}}
33
34work=${AEGIS_TMP:-/tmp}/$$
35PAGER=cat
36export PAGER
37AEGIS_FLAGS="delete_file_preference = no_keep; \
38	lock_wait_preference = always; \
39	diff_preference = automatic_merge; \
40	pager_preference = never; \
41	persevere_preference = all; \
42	log_file_preference = never;"
43export AEGIS_FLAGS
44AEGIS_THROTTLE=-1
45export AEGIS_THROTTLE
46
47here=`pwd`
48if test $? -ne 0 ; then exit 2; fi
49
50if test "$1" != "" ; then bin="$here/$1/bin"; else bin="$here/bin"; fi
51
52if test "$EXEC_SEARCH_PATH" != ""
53then
54    tpath=
55    hold="$IFS"
56    IFS=":$IFS"
57    for tpath2 in $EXEC_SEARCH_PATH
58    do
59	tpath=${tpath}${tpath2}/${1-.}/bin:
60    done
61    IFS="$hold"
62    PATH=${tpath}${PATH}
63else
64    PATH=${bin}:${PATH}
65fi
66export PATH
67
68pass()
69{
70	set +x
71	echo PASSED 1>&2
72	cd $here
73	find $work -type d -user $USER -exec chmod u+w {} \;
74	rm -rf $work
75	exit 0
76}
77fail()
78{
79	set +x
80	echo 'FAILED test of the progress messages functionality' 1>&2
81	cd $here
82	find $work -type d -user $USER -exec chmod u+w {} \;
83	rm -rf $work
84	exit 1
85}
86no_result()
87{
88	set +x
89	echo 'NO RESULT when testing the progress messages functionality' 1>&2
90	cd $here
91	find $work -type d -user $USER -exec chmod u+w {} \;
92	rm -rf $work
93	exit 2
94}
95trap "\"no_result\"" 1 2 3 15
96
97mkdir $work $work/lib
98if test $? -ne 0 ; then no_result; fi
99chmod 777 $work/lib
100if test $? -ne 0 ; then no_result; fi
101cd $work
102if test $? -ne 0 ; then no_result; fi
103
104#
105# use the built-in error messages
106#
107AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
108export AEGIS_MESSAGE_LIBRARY
109unset LANG
110unset LANGUAGE
111
112#
113# If the C++ compiler is called something other than "c++", as
114# discovered by the configure script, create a shell script called
115# "c++" which invokes the correct C++ compiler.  Make sure the current
116# directory is in the path, so that it will be invoked.
117#
118if test "$CXX" != "c++"
119then
120	cat >> $work/c++ << fubar
121#!/bin/sh
122exec ${CXX-g++} \$*
123fubar
124	if test $? -ne 0 ; then no_result; fi
125	chmod a+rx $work/c++
126	if test $? -ne 0 ; then no_result; fi
127	PATH=${work}:${PATH}
128	export PATH
129fi
130
131worklib=$work/lib
132workproj=$work/foo.proj
133workchan=$work/foo.chan
134tmp=$work/tmp
135
136#
137# make sure progress messages are printed if -PROGress option is specified
138# and not printed if -Not-PROGress is specified.
139#
140
141#
142# make a new project
143#
144activity="new project 137"
145$bin/aegis -newpro foo -version "" -dir $workproj -v -lib $worklib > log 2>&1
146if test $? -ne 0 ; then cat log; no_result; fi
147
148#
149# change project attributes
150#
151activity="project attributes 144"
152cat > $tmp << 'end'
153description = "A bogus project created to test things.";
154developer_may_review = true;
155developer_may_integrate = true;
156reviewer_may_integrate = true;
157end
158$bin/aegis -proatt -f $tmp -proj foo -v -lib $worklib > log 2>&1
159if test $? -ne 0 ; then cat log; no_result; fi
160
161#
162# create a new change
163#	make sure it creates the files it should
164#
165activity="new change 158"
166cat > $tmp << 'end'
167brief_description = "This change is used to test the aegis functionality \
168with respect to change descriptions.";
169cause = internal_bug;
170end
171$bin/aegis -new_change -f $tmp -project foo -v -lib $worklib > log 2>&1
172if test $? -ne 0 ; then cat log; no_result; fi
173
174#
175# create a second change
176#	make sure it creates the files it should
177#
178activity="new change 171"
179cat > $tmp << 'end'
180brief_description = "This change was added to make the various listings \
181much more interesting.";
182cause = internal_bug;
183end
184$bin/aegis -new_change -f $tmp -project foo -v -lib $worklib > log 2>&1
185if test $? -ne 0 ; then cat log; no_result; fi
186
187#
188# add a new developer
189#
190activity="new developer 183"
191$bin/aegis -newdev $USER -p foo -v -lib $worklib > log 2>&1
192if test $? -ne 0 ; then cat log; no_result; fi
193
194#
195# begin development of a change
196#
197activity="develop begin 190"
198$bin/aegis -devbeg 10 -p foo -dir $workchan -v -lib $worklib > log 2>&1
199if test $? -ne 0 ; then cat log; no_result; fi
200
201#
202# add a new files to the change
203#
204activity="new file 197"
205$bin/aegis -new_file $workchan/main.cc -nl -v -lib $worklib -p foo > log 2>&1
206if test $? -ne 0 ; then cat log; no_result; fi
207$bin/aegis -new_file $workchan/fubar -nl -v -lib $worklib -p foo > log 2>&1
208if test $? -ne 0 ; then cat log; no_result; fi
209$bin/aegis -new_file $workchan/aegis.conf -nl -v -lib $worklib -p foo > log 2>&1
210if test $? -ne 0 ; then cat log; no_result; fi
211
212#
213# put something in 'main.cc'
214#
215cat > $workchan/main.cc << 'end'
216int
217main(int argc, char **argv)
218{
219	return 0;
220}
221end
222
223#
224# put something in 'config'
225#
226cat > $workchan/aegis.conf << 'end'
227build_command = "rm -f foo; c++ -o foo -D'VERSION=\"$vers\"' main.cc";
228link_integration_directory = true;
229
230history_get_command = "aesvt -check-out -edit ${quote $edit} "
231    "-history ${quote $history} -f ${quote $output}";
232history_put_command = "aesvt -check-in -history ${quote $history} "
233    "-f ${quote $input}";
234history_query_command = "aesvt -query -history ${quote $history}";
235history_content_limitation = binary_capable;
236
237diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
238
239diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
240	echo '1,$$p' ) | ed - $mr > $out";
241batch_test_command = "echo \"-- ${current} of ${total}\"; \
242echo \"test_result = [\" >> ${output}; \
243for f in ${file_names}; do echo \"{file_name = \\\"$$f\\\"; exit_status=0;},\">> ${output}; done; \
244echo \"];\" >> ${output};";
245end
246if test $? -ne 0 ; then no_result; fi
247
248#
249# create a new test
250#
251activity="new test 246"
252$bin/aegis -nt -v -lib $worklib -p foo > log 2>&1
253if test $? -ne 0 ; then cat log; no_result; fi
254
255#
256# put something in 'test/00/t0001a.sh'
257#
258cat > $workchan/test/00/t0001a.sh << 'end'
259#!/bin/sh
260no_result()
261{
262	echo WHIMPER 1>&2
263	exit 2
264}
265fail()
266{
267	echo SHUZBUTT 1>&2
268	exit 1
269}
270pass()
271{
272	exit 0
273}
274trap "no_result" 1 2 3 15
275
276# should not complain
277./foo
278if test $? -ne 0; then fail; fi
279
280# it probably worked
281pass
282end
283if test $? -ne 0 ; then no_result; fi
284
285#
286# create 199 more tests (batches is split by 100 tests)
287#
288activity="new test 283"
289
290i=1
291while test $i -le 199; do
292	$bin/aegis -nt -v -lib $worklib -p foo > log 2>&1
293	if test $? -ne 0 ; then cat log; no_result; fi
294
295	cp $workchan/test/00/t0001a.sh $workchan/`cat log | grep 'new test' | sed -e's/^.*new test \(.*\) complete$/\1/'`
296	if test $? -ne 0 ; then no_result; fi
297	i=`expr $i + 1`
298done
299
300
301#
302# build the change
303#
304activity="build 299"
305$bin/aegis -build -nl -v -lib $worklib -p foo > log 2>&1
306if test $? -ne 0 ; then cat log; no_result; fi
307
308#
309# difference the change
310#
311activity="diff 306"
312$bin/aegis -diff -nl -v -lib $worklib -p foo > log 2>&1
313if test $? -ne 0 ; then cat log; no_result; fi
314
315#
316# test the change with progress messages
317#
318activity="test 313"
319$bin/aegis -test -prog -nl -v -lib $worklib -p foo > log 2>&1
320if test $? -ne 0 ; then cat log; fail; fi
321
322#
323# make sure progress messages is in the log
324#
325grep 'batch test' log > $tmp.log
326cat > $tmp.log.ideal << 'end'
327aegis: project "foo": change 10: batch test from 1 to 100 of 200
328aegis: project "foo": change 10: batch test from 101 to 200 of 200
329end
330diff $tmp.log $tmp.log.ideal > log 2>&1
331if test $? -ne 0; then cat log; fail; fi
332
333#
334# build the change again to reset test results
335#
336activity="build 331"
337$bin/aegis -build -nl -v -lib $worklib -p foo > log 2>&1
338if test $? -ne 0 ; then cat log; no_result; fi
339
340#
341# test the change without progress messages
342#
343activity="test 338"
344$bin/aegis -test -trace libaegis/change/test/batch_fake.c -nprog -nl -v -lib $worklib -p foo > log 2>&1
345if test $? -ne 0 ; then cat log; fail; fi
346
347#
348# make sure progress messages is not in the log
349#
350cp log $tmp.log
351if grep 'batch test' $tmp.log > log 2>&1; then cat log; fail; fi
352
353#
354# Only definite negatives are possible.
355# The functionality exercised by this test appears to work,
356# no other guarantees are made.
357#
358pass
359