1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 1993-1998, 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
25unset LINES
26unset COLS
27umask 022
28
29USER=${USER:-${LOGNAME:-`whoami`}}
30
31work=${AEGIS_TMP:-/tmp}/$$
32
33here=`pwd`
34if test $? -ne 0; then exit 2; fi
35
36if test "$1" != "" ; then bin="$here/$1/bin"; else bin="$here/bin"; fi
37
38if test "$EXEC_SEARCH_PATH" != ""
39then
40    tpath=
41    hold="$IFS"
42    IFS=":$IFS"
43    for tpath2 in $EXEC_SEARCH_PATH
44    do
45	tpath=${tpath}${tpath2}/${1-.}/bin:
46    done
47    IFS="$hold"
48    PATH=${tpath}${PATH}
49else
50    PATH=${bin}:${PATH}
51fi
52export PATH
53
54no_result()
55{
56	set +x
57	echo "NO RESULT for test of 'aegis -NewFile -Build' command ($activity)" 1>&2
58	cd $here
59	find $work -type d -user $USER -exec chmod u+w {} \;
60	rm -rf $work
61	exit 2
62}
63fail()
64{
65	set +x
66	echo "FAILED test of 'aegis -NewFile -Build' command ($activity)" 1>&2
67	cd $here
68	find $work -type d -user $USER -exec chmod u+w {} \;
69	rm -rf $work
70	exit 1
71}
72pass()
73{
74	set +x
75	echo PASSED 1>&2
76	cd $here
77	find $work -type d -user $USER -exec chmod u+w {} \;
78	rm -rf $work
79	exit 0
80}
81trap "no_result" 1 2 3 15
82
83#
84# some variable to make things earier to read
85#
86PAGER=cat
87export PAGER
88
89AEGIS_FLAGS="delete_file_preference = no_keep; \
90	lock_wait_preference = always; \
91	diff_preference = automatic_merge; \
92	pager_preference = never; \
93	persevere_preference = all; \
94	log_file_preference = never;"
95export AEGIS_FLAGS
96AEGIS_THROTTLE=-1
97export AEGIS_THROTTLE
98
99worklib=$work/lib
100workproj=$work/foo.proj
101workchan=$work/foo.chan
102tmp=$work/tmp
103
104#
105# make the directories
106#
107activity="create working directory 94"
108mkdir $work $work/lib
109if test $? -ne 0 ; then no_result; fi
110chmod 777 $work/lib
111if test $? -ne 0 ; then no_result; fi
112cd $work
113if test $? -ne 0 ; then no_result; fi
114
115#
116# use the built-in error messages
117#
118AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
119export AEGIS_MESSAGE_LIBRARY
120unset LANG
121unset LANGUAGE
122
123#
124# If the C++ compiler is called something other than "c++", as
125# discovered by the configure script, create a shell script called
126# "c++" which invokes the correct C++ compiler.  Make sure the current
127# directory is in the path, so that it will be invoked.
128#
129if test "$CXX" != "c++"
130then
131	cat >> c++ << fubar
132#!/bin/sh
133exec ${CXX-g++} \$*
134fubar
135	if test $? -ne 0 ; then no_result; fi
136	chmod a+rx c++
137	if test $? -ne 0 ; then no_result; fi
138	PATH=${work}:${PATH}
139	export PATH
140fi
141
142#
143# make a new project
144#
145activity="new project 132"
146$bin/aegis -newpro foo -vers "" -dir $workproj -v -lib $worklib > test.out 2>&1
147if test $? -ne 0 ; then cat test.out; no_result; fi
148
149#
150# change project attributes
151#
152activity="project attributes 139"
153cat > $tmp << 'end'
154description = "A bogus project created to test things.";
155developer_may_review = true;
156developer_may_integrate = true;
157reviewer_may_integrate = true;
158end
159$bin/aegis -proatt -f $tmp -proj foo -v -lib $worklib > test.out 2>&1
160if test $? -ne 0 ; then cat test.out; no_result; fi
161
162#
163# create a new change
164#	make sure it creates the files it should
165#
166activity="new change 153"
167cat > $tmp << 'end'
168brief_description = "This change is used to test the aegis functionality \
169with respect to change descriptions.";
170cause = internal_bug;
171end
172$bin/aegis -new_change 1 -f $tmp -project foo -v -lib $worklib > test.out 2>&1
173if test $? -ne 0 ; then cat test.out; no_result; fi
174
175#
176# add a new developer
177#
178activity="new developer 165"
179$bin/aegis -newdev $USER -p foo -v -lib $worklib > test.out 2>&1
180if test $? -ne 0 ; then cat test.out; no_result; fi
181
182#
183# begin development of a change
184#
185activity="begin development 172"
186$bin/aegis -devbeg 1 -p foo -dir $workchan -v -lib $worklib > test.out 2>&1
187if test $? -ne 0 ; then cat test.out; no_result; fi
188
189#
190# add a new files to the change
191#
192activity="new file 179"
193$bin/aegis -new_file $workchan/main.cc -nl -v -lib $worklib -p foo > test.out 2>&1
194if test $? -ne 0 ; then cat test.out; no_result; fi
195$bin/aegis -new_file $workchan/fubar -nl -v -lib $worklib -p foo > test.out 2>&1
196if test $? -ne 0 ; then cat test.out; no_result; fi
197$bin/aegis -new_file $workchan/version -b -nl -v -lib $worklib -p foo > test.out 2>&1
198if test $? -ne 0 ; then cat test.out; fail; fi
199$bin/aegis -new_file $workchan/aegis.conf -nl -v -lib $worklib -p foo > test.out 2>&1
200if test $? -ne 0 ; then cat test.out; no_result; fi
201
202#
203# put something in 'main.cc'
204#
205cat > $workchan/main.cc << 'end'
206int
207main(int argc, char **argv)
208{
209	return 0;
210}
211end
212
213#
214# put something in 'config'
215#
216cat > $workchan/aegis.conf << 'end'
217build_command = "rm -f foo version; c++ -o foo main.cc; echo '$v' > version";
218link_integration_directory = true;
219
220history_get_command = "aesvt -check-out -edit ${quote $edit} "
221    "-history ${quote $history} -f ${quote $output}";
222history_put_command = "aesvt -check-in -history ${quote $history} "
223    "-f ${quote $input}";
224history_query_command = "aesvt -query -history ${quote $history}";
225history_content_limitation = binary_capable;
226
227diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
228
229diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
230	echo '1,$$p' ) | ed - $mr > $out";
231end
232
233#
234# create a new test
235#
236activity="new test 225"
237$bin/aegis -nt -v -lib $worklib -p foo > test.out 2>&1
238if test $? -ne 0 ; then cat test.out; no_result; fi
239
240#
241# put something in 'test/00/t0001a.sh'
242#
243cat > $workchan/test/00/t0001a.sh << 'end'
244#!/bin/sh
245#
246# Project: "foo"
247# Change: 1
248#
249
250no_result()
251{
252	echo WHIMPER 1>&2
253	exit 2
254}
255fail()
256{
257	echo SHUZBUTT 1>&2
258	exit 1
259}
260pass()
261{
262	exit 0
263}
264trap "no_result" 1 2 3 15
265
266./foo
267q=$?
268
269# check for signals
270if test $q -ge 128
271then
272	fail
273fi
274
275# should not complain
276if test $q -ne 0
277then
278	fail
279fi
280
281# it probably worked
282pass
283end
284
285#
286# build the change
287#
288activity="development build 282"
289$bin/aegis -build -nl -v -lib $worklib -p foo > test.out 2>&1
290if test $? -ne 0 ; then cat test.out; fail; fi
291
292#
293# difference the change
294#
295activity="development diff 289"
296$bin/aegis -diff -nl -v -lib $worklib -p foo > test.out 2>&1
297if test $? -ne 0 ; then cat test.out; fail; fi
298
299#
300# test the change
301#
302activity="development test 296"
303$bin/aegis -test -nl -v -lib $worklib -p foo > test.out 2>&1
304if test $? -ne 0 ; then cat test.out; no_result; fi
305
306#
307# finish development of the change
308#
309activity="develop end 303"
310$bin/aegis -dev_end -v -lib $worklib -p foo > test.out 2>&1
311if test $? -ne 0 ; then cat test.out; fail; fi
312
313#
314# add a new reviewer
315#
316activity="new reviewer 310"
317$bin/aegis -newrev $USER -p foo -v -lib $worklib > test.out 2>&1
318if test $? -ne 0 ; then cat test.out; no_result; fi
319
320#
321# pass the review
322#
323activity="review pass 317"
324$bin/aegis -review_pass -chan 1 -proj foo -v -lib $worklib > test.out 2>&1
325if test $? -ne 0 ; then cat test.out; no_result; fi
326
327#
328# add an integrator
329#
330activity="new inegrator 324"
331$bin/aegis -newint $USER -p foo -v -lib $worklib > test.out 2>&1
332if test $? -ne 0 ; then cat test.out; no_result; fi
333
334#
335# start integrating
336#
337activity="integrate begin 331"
338$bin/aegis -intbeg 1 -p foo -v -lib $worklib > test.out 2>&1
339if test $? -ne 0 ; then cat test.out; fail; fi
340
341#
342# integrate build
343#
344activity="integration build 338"
345$bin/aegis -build -nl -v -lib $worklib -p foo > test.out 2>&1
346if test $? -ne 0 ; then cat test.out; fail; fi
347
348#
349# integrate test
350#
351activity="integration test 345"
352$bin/aegis -test -nl -v -lib $worklib -p foo > test.out 2>&1
353if test $? -ne 0 ; then cat test.out; no_result; fi
354
355#
356# integration pass
357#
358activity="integrate pass 352"
359$bin/aegis -intpass -nl -v -lib $worklib -p foo > test.out 2>&1
360if test $? -ne 0 ; then cat test.out; fail; fi
361
362#
363# create a new change
364#	make sure it creates the files it should
365#
366activity="new change 360"
367cat > $tmp << 'end'
368brief_description = "A second Change";
369cause = internal_bug;
370end
371$bin/aegis -new_change 2 -f $tmp -project foo -v -lib $worklib > test.out 2>&1
372if test $? -ne 0 ; then cat test.out; no_result; fi
373
374#
375# begin development of a change
376#
377activity="develop begin 371"
378$bin/aegis -devbeg 2 -p foo -dir $workchan -v -lib $worklib > test.out 2>&1
379if test $? -ne 0 ; then cat test.out; no_result; fi
380
381#
382# set change attributes
383#
384activity="change attributes 378"
385cat > $workchan/xx  << 'fubar'
386test_exempt = true;
387test_baseline_exempt = true;
388fubar
389if test $? -ne 0 ; then no_result; fi
390$bin/aegis -ca -f $workchan/xx -p foo -v -lib $worklib > test.out 2>&1
391if test $? -ne 0 ; then cat test.out; no_result; fi
392
393#
394# add a new files to the change
395#
396activity="copy file 390"
397$bin/aegis -cp $workchan/main.cc -nl -v -lib $worklib -p foo > test.out 2>&1
398if test $? -ne 0 ; then cat test.out; no_result; fi
399
400#
401# make it re-compile
402#
403cat >> $workchan/main.cc << 'end'
404/* almost nothing */
405end
406
407#
408# build the change
409#
410activity="development build 409"
411$bin/aegis -build -nl -v -lib $worklib -p foo > test.out 2>&1
412if test $? -ne 0 ; then cat test.out; no_result; fi
413
414#
415# difference the change
416#
417activity="development diff 416"
418$bin/aegis -diff -nl -v -lib $worklib -p foo > test.out 2>&1
419if test $? -ne 0 ; then cat test.out; no_result; fi
420
421#
422# finish development of the change
423#
424activity="develop end 423"
425$bin/aegis -dev_end -v -lib $worklib -p foo > test.out 2>&1
426if test $? -ne 0 ; then cat test.out; no_result; fi
427
428#
429# pass the review
430#
431activity="review pass 430"
432$bin/aegis -review_pass -chan 2 -proj foo -v -lib $worklib > test.out 2>&1
433if test $? -ne 0 ; then cat test.out; no_result; fi
434
435#
436# start integrating
437#
438activity="integrate begin 437"
439$bin/aegis -intbeg 2 -p foo -v -lib $worklib > test.out 2>&1
440if test $? -ne 0 ; then cat test.out; fail; fi
441
442#
443# integrate build
444#
445activity="integration build 444"
446$bin/aegis -build -nl -v -lib $worklib -p foo > test.out 2>&1
447if test $? -ne 0 ; then cat test.out; no_result; fi
448
449#
450# integration pass
451#
452activity="integrate pass 451"
453$bin/aegis -intpass -nl -v -lib $worklib -p foo > test.out 2>&1
454if test $? -ne 0 ; then cat test.out; fail; fi
455
456#
457# the build file should now be a change file
458#	even though user did not put it there
459#
460activity="check change file state 459"
461$bin/aegis -l cf -c 2 -unf -lib $worklib -p foo > test.out 2>&1
462if test $? -ne 0 ; then cat test.out; fail; fi
463cat > test.ok << 'fubar'
464source modify 1 -> 2 main.cc
465build modify 1 -> 2 version
466fubar
467if test $? -ne 0 ; then no_result; fi
468diff test.ok test.out
469if test $? -ne 0 ; then fail; fi
470
471#
472# the things tested in this test, worked
473#
474pass
475