1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 1993-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 manifested as 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 -ANticipate' variant ($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 -ANticipate' variant ($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 -vers "" -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
163$bin/aegis -proatt -f $tmp -proj foo -v -lib $worklib > log 2>&1
164if test $? -ne 0 ; then cat log; no_result; fi
165
166#
167# create a new change
168#	make sure it creates the files it should
169#
170activity="new change 157"
171cat > $tmp << 'end'
172brief_description = "This change is used to test the aegis functionality \
173with respect to change descriptions.";
174cause = internal_bug;
175end
176$bin/aegis -new_change 1 -f $tmp -project foo -v -lib $worklib > log 2>&1
177if test $? -ne 0 ; then cat log; no_result; fi
178
179#
180# create a second change
181#	make sure it creates the files it should
182#
183activity="new change 170"
184cat > $tmp << 'end'
185brief_description = "This change was added to make the various listings \
186much more interesting.";
187cause = internal_bug;
188end
189$bin/aegis -new_change 2 -f $tmp -project foo -v -lib $worklib > log 2>&1
190if test $? -ne 0 ; then cat log; no_result; fi
191
192#
193# create a third change
194#
195activity="new change 182"
196cat > $tmp << 'end'
197brief_description = "change three";
198cause = internal_bug;
199end
200$bin/aegis -new_change 3 -f $tmp -project foo -v -lib $worklib > log 2>&1
201if test $? -ne 0 ; then cat log; no_result; fi
202
203#
204# add a new developer
205#
206activity="new developer 193"
207$bin/aegis -newdev $USER -p foo -v -lib $worklib > log 2>&1
208if test $? -ne 0 ; then cat log; no_result; fi
209
210#
211# begin development of a change
212#	check it made the files it should
213#
214activity="develop begin 201"
215$bin/aegis -devbeg 1 -p foo -dir $workchan -v -lib $worklib > log 2>&1
216if test $? -ne 0 ; then cat log; no_result; fi
217
218#
219# add a new files to the change
220#
221activity="new file 208"
222$bin/aegis -new_file $workchan/main.cc -nl -v -lib $worklib -p foo > log 2>&1
223if test $? -ne 0 ; then cat log; no_result; fi
224$bin/aegis -new_file $workchan/aegis.conf -nl -v -lib $worklib -p foo > log 2>&1
225if test $? -ne 0 ; then cat log; no_result; fi
226cat > $workchan/main.cc << 'end'
227int
228main(int argc, char **argv)
229{
230	return 0;
231}
232end
233cat > $workchan/aegis.conf << 'end'
234build_command = "rm -f foo; c++ -o foo -D'VERSION=\"$version\"' main.cc";
235link_integration_directory = true;
236
237history_get_command = "aesvt -check-out -edit ${quote $edit} "
238    "-history ${quote $history} -f ${quote $output}";
239history_put_command = "aesvt -check-in -history ${quote $history} "
240    "-f ${quote $input}";
241history_query_command = "aesvt -query -history ${quote $history}";
242history_content_limitation = binary_capable;
243
244diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
245
246diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
247	echo '1,$$p' ) | ed - $mr > $out";
248end
249
250#
251# create a new test
252#
253activity="new test 242"
254$bin/aegis -nt -l -v -lib $worklib -p foo > log 2>&1
255if test $? -ne 0 ; then cat log; no_result; fi
256$bin/aegis -nt -v -lib $worklib -p foo > log 2>&1
257if test $? -ne 0 ; then cat log; no_result; fi
258cat > $workchan/test/00/t0001a.sh << 'end'
259#!/bin/sh
260
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./foo
278if test $? -ne 0; then fail; fi
279
280# it probably worked
281pass
282end
283
284#
285# build the change
286#
287activity="build 276"
288$bin/aegis -build -nl -v -lib $worklib -p foo > log 2>&1
289if test $? -ne 0 ; then cat log; no_result; fi
290
291#
292# difference the change
293#
294activity="diff 283"
295$bin/aegis -diff -nl -v -lib $worklib -p foo > log 2>&1
296if test $? -ne 0 ; then cat log; no_result; fi
297
298#
299# test the change
300#
301activity="test 290"
302$bin/aegis -test -nl -v -lib $worklib -p foo > log 2>&1
303if test $? -ne 0 ; then cat log; no_result; fi
304
305#
306# finish development of the change
307#
308activity="develop end 297"
309$bin/aegis -dev_end -v -lib $worklib -p foo > log 2>&1
310if test $? -ne 0 ; then cat log; no_result; fi
311
312#
313# add a new reviewer
314#
315activity="new reviewer 304"
316$bin/aegis -newrev $USER -p foo -v -lib $worklib > log 2>&1
317if test $? -ne 0 ; then cat log; no_result; fi
318
319#
320# pass the review
321#
322activity="review pass 311"
323$bin/aegis -review_pass -chan 1 -proj foo -v -lib $worklib > log 2>&1
324if test $? -ne 0 ; then cat log; no_result; fi
325
326#
327# add an integrator
328#
329activity="new integrator 318"
330$bin/aegis -newint $USER -p foo -v -lib $worklib > log 2>&1
331if test $? -ne 0 ; then cat log; no_result; fi
332
333#
334# start integrating
335#
336activity="integrate begin 325"
337$bin/aegis -intbeg 1 -p foo -v -lib $worklib > log 2>&1
338if test $? -ne 0 ; then cat log; no_result; fi
339
340#
341# integrate build
342#
343activity="build 332"
344$bin/aegis -build -nl -v -lib $worklib -p foo > log 2>&1
345if test $? -ne 0 ; then cat log; no_result; fi
346activity="test 335"
347$bin/aegis -test -nl -v -lib $worklib -p foo > log 2>&1
348if test $? -ne 0 ; then cat log; no_result; fi
349
350#
351# pass the integration
352#
353activity="integrate pass 342"
354$bin/aegis -intpass -nl -v -lib $worklib -p foo > log 2>&1
355if test $? -ne 0 ; then cat log; no_result; fi
356
357#
358# start work on change 2
359#
360workchan=$work/foo.chan2
361activity="develop begin 349"
362$bin/aegis -devbeg 2 -p foo -v -dir $workchan -lib $worklib > log 2>&1
363if test $? -ne 0 ; then cat log; no_result; fi
364
365#
366# start work on change 3
367#
368activity="develop begin 356"
369$bin/aegis -devbeg 3 -p foo -v -dir $workchan3 -lib $worklib > log 2>&1
370if test $? -ne 0 ; then cat log; no_result; fi
371
372#
373# copy a file into change 2
374#
375activity="copy file 363"
376$bin/aegis -cp $workchan/main.cc -nl -v -lib $worklib -c 2 -p foo > log 2>&1
377if test $? -ne 0 ; then cat log; no_result; fi
378
379#
380# copy a file into change 3
381#
382activity="copy file 370"
383$bin/aegis -cp $workchan3/main.cc -nl -v -lib $worklib -c 3 -p foo > log 2>&1
384if test $? -ne 0 ; then cat log; no_result; fi
385
386#
387# change the file
388#
389cat > $workchan/main.cc << 'end'
390
391#include <stdio.h>
392
393int
394main(int argc, char **argv)
395{
396	if (argc != 1)
397	{
398		fprintf(stderr, "usage: %s\n", argv[0]);
399		return 1;
400	}
401	printf("hello, world\n");
402	return 0;
403}
404end
405
406#
407# need another test
408#
409activity="new test 397"
410$bin/aegis -nt -v -lib $worklib -c 2 -p foo > log 2>&1
411if test $? -ne 0 ; then cat log; no_result; fi
412cat > $workchan/test/00/t0002a.sh << 'end'
413#!/bin/sh
414
415no_result()
416{
417	echo WHIMPER 1>&2
418	exit 2
419}
420fail()
421{
422	echo SHUZBUTT 1>&2
423	exit 1
424}
425pass()
426{
427	exit 0
428}
429trap "no_result" 1 2 3 15
430
431./foo > /dev/null 2>&1
432test $? -eq 0 || fail
433
434./foo ickky
435if test $? -ne 1; then fail; fi
436
437# it probably worked
438pass
439end
440
441#
442# build the change
443# diff the change
444# test the change
445#
446activity="build 434"
447$bin/aegis -b -nl -v -lib $worklib -c 2 -p foo > log 2>&1
448if test $? -ne 0 ; then cat log; no_result; fi
449activity="diff 437"
450$bin/aegis -diff -nl -v -lib $worklib -c 2 -p foo > log 2>&1
451if test $? -ne 0 ; then cat log; no_result; fi
452activity="test 440"
453$bin/aegis -test -nl -v -lib $worklib -c 2 -p foo > log 2>&1
454if test $? -ne 0 ; then cat log; no_result; fi
455activity="test baseline 443"
456$bin/aegis -test -bl -nl -v -lib $worklib -c 2 -p foo > log 2>&1
457if test $? -ne 0 ; then cat log; no_result; fi
458
459#
460# end development
461# review pass
462# start integrating
463#
464activity="develop end 452"
465$bin/aegis -devend -v -lib $worklib -c 2 -p foo > log 2>&1
466if test $? -ne 0 ; then cat log; no_result; fi
467activity="review pass 455"
468$bin/aegis -revpass -v -c 2 -p foo -lib $worklib > log 2>&1
469if test $? -ne 0 ; then cat log; no_result; fi
470activity="integrate bagin 458"
471$bin/aegis -intbeg -v -c 2 -p foo -lib $worklib > log 2>&1
472if test $? -ne 0 ; then cat log; no_result; fi
473
474#
475# difference change 3 anticipating 2
476#
477activity="diff anticipate 465"
478$bin/aegis -diff -nl -c 3 -lib $worklib -p foo -an 2 > log 2>&1
479if test $? -ne 0 ; then cat log; fail; fi
480
481#
482# the merged result (in change 3) should look like
483# the edited one from change 2
484#
485diff $workchan3/main.cc,D $workchan/main.cc
486if test $? -ne 0 ; then fail; fi
487
488#
489# the things tested in this test, worked
490#
491pass
492