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