1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 2001, 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}/$$
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 build_time_adjust_notify_command functionality ($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 build_time_adjust_notify_command functionality ($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
103AEGIS_PATH=$worklib ; export AEGIS_PATH
104AEGIS_PROJECT=foo ; export AEGIS_PROJECT
105
106#
107# make the directories
108#
109activity="working directory 103"
110mkdir $work $work/lib
111if test $? -ne 0 ; then no_result; fi
112chmod 777 $work/lib
113if test $? -ne 0 ; then no_result; fi
114cd $work
115if test $? -ne 0 ; then no_result; fi
116
117#
118# use the built-in error messages
119#
120AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
121export AEGIS_MESSAGE_LIBRARY
122unset LANG
123unset LANGUAGE
124
125#
126# make a new project
127#
128activity="new project 122"
129$bin/aegis -npr foo -vers "" -dir $workproj > log 2>&1
130if test $? -ne 0 ; then cat log; no_result; fi
131
132#
133# change project attributes
134#
135activity="project attributes 129"
136cat > $tmp << 'end'
137description = "A bogus project created to test the \
138build_time_adjust_notify_command functionality.";
139developer_may_review = true;
140developer_may_integrate = true;
141reviewer_may_integrate = true;
142end
143if test $? -ne 0 ; then no_result; fi
144$bin/aegis -pa -f $tmp > log 2>&1
145if test $? -ne 0 ; then cat log; no_result; fi
146
147#
148# create a new change
149#
150activity="new change 144"
151cat > $tmp << 'end'
152brief_description = "The first change";
153cause = internal_bug;
154end
155if test $? -ne 0 ; then no_result; fi
156$bin/aegis -nc 1 -f $tmp -p foo > log 2>&1
157if test $? -ne 0 ; then cat log; no_result; fi
158
159#
160# add the staff
161#
162activity="staff 156"
163$bin/aegis -nd $USER > log 2>&1
164if test $? -ne 0 ; then cat log; no_result; fi
165$bin/aegis -nrv $USER > log 2>&1
166if test $? -ne 0 ; then cat log; no_result; fi
167$bin/aegis -ni $USER > log 2>&1
168if test $? -ne 0 ; then cat log; no_result; fi
169
170#
171# begin development of a change
172#
173$bin/aegis -db 1 -dir $workchan > log 2>&1
174if test $? -ne 0 ; then cat log; no_result; fi
175
176#
177# add a new files to the change
178#
179activity="new file 173"
180$bin/aegis -nf $workchan/main.c $workchan/test.c $workchan/Makefile \
181	$workchan/aegis.conf $workchan/cmd/time_adj.sh -nl > log 2>&1
182if test $? -ne 0 ; then cat log; no_result; fi
183cat > $workchan/main.c << 'end'
184int
185main(argc, argv)
186	int	argc;
187	char	**argv;
188{
189	test();
190	exit(0);
191	return 0;
192}
193end
194if test $? -ne 0 ; then no_result; fi
195cat > $workchan/test.c << 'end'
196void test() { }
197end
198if test $? -ne 0 ; then no_result; fi
199cat > $workchan/Makefile << 'end'
200.c.o:
201	date > $@
202
203foo: main.o test.o
204	date > $@
205end
206if test $? -ne 0 ; then no_result; fi
207
208cat > $workchan/aegis.conf << 'end'
209build_command = "exit 0";
210link_integration_directory = true;
211
212history_get_command = "aesvt -check-out -edit ${quote $edit} "
213    "-history ${quote $history} -f ${quote $output}";
214history_put_command = "aesvt -check-in -history ${quote $history} "
215    "-f ${quote $input}";
216history_query_command = "aesvt -query -history ${quote $history}";
217history_content_limitation = binary_capable;
218
219diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
220diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
221	echo '1,$$p' ) | ed - $mr > $out";
222build_time_adjust_notify_command = "sh ${source cmd/time_adj.sh}";
223end
224if test $? -ne 0 ; then no_result; fi
225
226cat > $workchan/cmd/time_adj.sh << 'end'
227#!/bin/sh
228echo "time ajdust notification received"
229exit 0
230end
231if test $? -ne 0 ; then no_result; fi
232
233#
234# create a new test
235#
236activity="new test 230"
237$bin/aegis -nt > log 2>&1
238if test $? -ne 0 ; then cat log; no_result; fi
239cat > $workchan/test/00/t0001a.sh << 'end'
240#!/bin/sh
241exit 0
242end
243if test $? -ne 0 ; then no_result; fi
244
245#
246# build the change
247#
248activity="build 242"
249$bin/aegis -build -nl -v > log 2>&1
250if test $? -ne 0 ; then cat log; fail; fi
251
252#
253# difference the change
254#
255activity="diff 249"
256$bin/aegis -diff > log 2>&1
257if test $? -ne 0 ; then cat log; no_result; fi
258
259#
260# test the change
261#
262activity="test 256"
263$bin/aegis -t -v > log 2>&1
264if test $? -ne 0 ; then cat log; no_result; fi
265
266#
267# finish development of the change
268#
269activity="develop end 263"
270$bin/aegis -de > log 2>&1
271if test $? -ne 0 ; then cat log; fail; fi
272
273#
274# pass the review
275#
276activity="review pass 270"
277$bin/aegis -rpass -c 1 > log 2>&1
278if test $? -ne 0 ; then cat log; no_result; fi
279
280#
281# start integrating
282#
283activity="integrate begin 277"
284$bin/aegis -ib 1 > log 2>&1
285if test $? -ne 0 ; then cat log; no_result; fi
286
287#
288# integrate build
289#
290activity="build 284"
291$bin/aegis -b -nl -v > log 2>&1
292if test $? -ne 0 ; then cat log; no_result; fi
293
294#
295# integrate test
296#
297activity="test 291"
298$bin/aegis -t -nl -v > log 2>&1
299if test $? -ne 0 ; then cat log; no_result; fi
300
301#
302# pass the integration
303#
304# This is the point it used to fail.
305#
306activity="integrate pass 300"
307$bin/aegis -intpass -nl > log 2>&1
308if test $? -ne 0 ; then cat log; fail; fi
309
310#
311# the things tested in this test, worked
312#
313pass
314