1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 2004 Walter Franzini;
5#	All rights reserved.
6#       Copyright (C) 2007, 2008 Peter Miller
7#
8#	This program is free software; you can redistribute it and/or modify
9#	it under the terms of the GNU General Public License as published by
10#	the Free Software Foundation; either version 3 of the License, or
11#	(at your option) any later version.
12#
13#	This program is distributed in the hope that it will be useful,
14#	but WITHOUT ANY WARRANTY; without even the implied warranty of
15#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16#	GNU General Public License for more details.
17#
18#	You should have received a copy of the GNU General Public License
19#	along with this program. If not, see
20#	<http://www.gnu.org/licenses/>.
21#
22
23unset AEGIS_PROJECT
24unset AEGIS_CHANGE
25unset AEGIS_PATH
26unset AEGIS
27umask 022
28
29LINES=24
30export LINES
31COLS=80
32export COLS
33
34USER=${USER:-${LOGNAME:-`whoami`}}
35
36work=${AEGIS_TMP:-/tmp}/$$
37PAGER=cat
38export PAGER
39AEGIS_FLAGS="delete_file_preference = no_keep; \
40	lock_wait_preference = always; \
41	diff_preference = automatic_merge; \
42	pager_preference = never; \
43	persevere_preference = all; \
44	log_file_preference = never;"
45export AEGIS_FLAGS
46AEGIS_THROTTLE=-1
47export AEGIS_THROTTLE
48
49here=`pwd`
50if test $? -ne 0 ; then exit 2; fi
51
52bin=$here/${1-.}/bin
53
54if test "$EXEC_SEARCH_PATH" != ""
55then
56    tpath=
57    hold="$IFS"
58    IFS=":$IFS"
59    for tpath2 in $EXEC_SEARCH_PATH
60    do
61	tpath=${tpath}${tpath2}/${1-.}/bin:
62    done
63    IFS="$hold"
64    PATH=${tpath}${PATH}
65else
66    PATH=${bin}:${PATH}
67fi
68export PATH
69
70pass()
71{
72	set +x
73	echo PASSED 1>&2
74	cd $here
75	find $work -type d -user $USER -exec chmod u+w {} \;
76	rm -rf $work
77	exit 0
78}
79fail()
80{
81	set +x
82	echo "FAILED test of the aedist functionality (${activity})" 1>&2
83	cd $here
84	find $work -type d -user $USER -exec chmod u+w {} \;
85	rm -rf $work
86	exit 1
87}
88no_result()
89{
90	set +x
91	echo "NO RESULT when testing the aedist functionality (${activity})" 1>&2
92	cd $here
93	find $work -type d -user $USER -exec chmod u+w {} \;
94	rm -rf $work
95	exit 2
96}
97trap \"no_result\" 1 2 3 15
98
99mkdir $work $work/lib
100if test $? -ne 0 ; then no_result; fi
101chmod 777 $work/lib
102if test $? -ne 0 ; then no_result; fi
103cd $work
104if test $? -ne 0 ; then no_result; fi
105
106#
107# use the built-in error messages
108#
109AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
110export AEGIS_MESSAGE_LIBRARY
111unset LANG
112unset LANGUAGE
113
114#
115# test 'aedist -r' removing non existent files
116#
117#
118# make a new project
119#
120AEGIS_PROJECT=foo
121AEGIS_PATH=$work/lib
122workchan=$work/chan
123workproj=$work/proj
124tmp=$work/tmp
125export AEGIS_PROJECT AEGIS_PATH
126activity="new project 128"
127$bin/aegis -npr $AEGIS_PROJECT -vers "" -dir $workproj \
128    -lib $work/lib -verb > log 2>&1
129if test $? -ne 0 ; then cat log; no_result; fi
130
131cat > $tmp << 'end'
132description = "A bogus project created to test the aedis functionality.";
133developer_may_review = true;
134developer_may_integrate = true;
135reviewer_may_integrate = true;
136default_test_exemption = true;
137end
138if test $? -ne 0 ; then no_result; fi
139$bin/aegis -pa -p $AEGIS_PROJECT -f $tmp > log 2>&1
140if test $? -ne 0 ; then cat log; no_result; fi
141
142
143#
144# add the staff
145#
146activity="staff 148"
147$bin/aegis -nd $USER -p $AEGIS_PROJECT > log 2>&1
148if test $? -ne 0 ; then cat log; no_result; fi
149$bin/aegis -nrv $USER -p $AEGIS_PROJECT > log 2>&1
150if test $? -ne 0 ; then cat log; no_result; fi
151$bin/aegis -ni $USER -p $AEGIS_PROJECT > log 2>&1
152if test $? -ne 0 ; then cat log; no_result; fi
153
154#
155# create a new change
156#
157activity="new change 159"
158cat > $tmp << 'end'
159brief_description = "The first change";
160cause = internal_bug;
161test_exempt = true;
162test_baseline_exempt = true ;
163regression_test_exempt = true;
164end
165if test $? -ne 0 ; then no_result; fi
166
167$bin/aegis -nc 10 -f $tmp -p $AEGIS_PROJECT > log 2>&1
168if test $? -ne 0 ; then cat log; no_result; fi
169
170
171#
172# begin development of a change
173#
174$bin/aegis -db 10 -dir $workchan > log 2>&1
175if test $? -ne 0 ; then cat log; no_result; fi
176
177cat > $workchan/aegis.conf << 'end'
178build_command = "exit 0";
179link_integration_directory = true;
180
181history_get_command = "aesvt -check-out -edit ${quote $edit} "
182    "-history ${quote $history} -f ${quote $output}";
183history_put_command = "aesvt -check-in -history ${quote $history} "
184    "-f ${quote $input}";
185history_query_command = "aesvt -query -history ${quote $history}";
186history_content_limitation = binary_capable;
187
188diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
189diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
190	echo '1,$$p' ) | ed - $mr > $out";
191create_symlinks_before_build = true;
192remove_symlinks_after_integration_build = false;
193end
194if test $? -ne 0 ; then no_result; fi
195
196activity="New file 198"
197$bin/aegis -nf $workchan/aegis.conf > log 2>&1
198if test $? -ne 0 ; then cat log; no_result; fi
199
200activity="New file 202"
201$bin/aegis -nf $workchan/source-file0 > log 2>& 1
202if test $? -ne 0 ; then cat log; no_result; fi
203
204activity="New file 206"
205$bin/aegis -nf $workchan/source-file1 > log 2>& 1
206if test $? -ne 0 ; then cat log; no_result; fi
207
208activity="Build 210"
209$bin/aegis -b > log 2>&1
210if test $? -ne 0 ; then cat log; no_result; fi
211
212activity="Diff 214"
213$bin/aegis -diff > log 2>&1
214if test $? -ne 0 ; then cat log; no_result; fi
215
216activity="Develop end 218"
217$bin/aegis -de > log 2>&1
218if test $? -ne 0 ; then cat log; no_result; fi
219
220activity="Review Pass 222"
221$bin/aegis -rpass 10 > log 2>&1
222if test $? -ne 0 ; then cat log; no_result; fi
223
224activity="Integrate Begin 226"
225$bin/aegis -ib  10 > log 2>&1
226if test $? -ne 0 ; then cat log; no_result; fi
227
228activity="Integrate Build 230"
229$bin/aegis -b 10 > log 2>&1
230if test $? -ne 0 ; then cat log; no_result; fi
231
232activity="Integrate Pass 234"
233$bin/aegis -ipass 10 > log 2>&1
234if test $? -ne 0 ; then cat log; no_result; fi
235
236#
237# the second change
238#
239
240activity="New change 242"
241cat > $tmp << 'end'
242brief_description = "The second change";
243cause = internal_bug;
244test_exempt = true;
245test_baseline_exempt = true ;
246regression_test_exempt = true;
247end
248if test $? -ne 0 ; then no_result; fi
249
250$bin/aegis -nc 11 -f $tmp -p $AEGIS_PROJECT > log 2>&1
251if test $? -ne 0 ; then cat log; no_result; fi
252
253$bin/aegis -db 11 -p $AEGIS_PROJECT -dir $workchan > log 2>&1
254if test $? -ne 0 ; then cat log; no_result; fi
255
256activity="move file 258"
257$bin/aegis -mv -c 11 -p $AEGIS_PROJECT $workchan/source-file0 \
258    $workchan/source-file2 -nl > log 2>&1
259if test $? -ne 0 ; then cat log; no_result; fi
260
261activity="second change build 263"
262$bin/aegis -build -c 11 -nl > log 2>&1
263if test $? -ne 0 ; then cat log; no_result; fi
264
265activity="second change diff 267"
266$bin/aegis -diff -c 11 -nl > log 2>&1
267if test $? -ne 0 ; then cat log; no_result; fi
268
269activity="second change develop end 271"
270$bin/aegis -de -c 11 -verb > log 2>&1
271if test $? -ne 0 ; then cat log; no_result; fi
272
273activity="review pass 275"
274$bin/aegis -rpass -c 11 -verb > log 2>&1
275if test $? -ne 0 ; then cat log; no_result; fi
276
277activity="integrate begin 279"
278$bin/aegis -ib -c 11 -verb > log 2>&1
279if test $? -ne 0 ; then cat log; no_result; fi
280
281$bin/aegis -build -c 11 -nl > log 2>&1
282if test $? -ne 0 ; then cat log; no_result; fi
283
284$bin/aegis -diff -c 11 -nl > log 2>&1
285if test $? -ne 0 ; then cat log; no_result; fi
286
287$bin/aegis -ipass -c 11 -verb > log 2>&1
288if test $? -ne 0 ; then cat log; no_result; fi
289
290#
291# create the patch
292#
293activity="generate the patch 295"
294$bin/aedist -s -p $AEGIS_PROJECT -bl -es -o $work/$AEGIS_PROJECT.ae > log 2>&1
295if test $? -ne 0 ; then cat log; no_result; fi
296
297#
298# cleanup
299#
300activity="cleanup 302"
301rm -rf $workchan
302rm -rf $workproj
303rm -rf $work/lib
304
305#
306# create the destination project
307#
308
309activity="new project 311"
310$bin/aegis -npr $AEGIS_PROJECT -vers "" -dir $workproj \
311    -lib $work/lib -verb > log 2>&1
312if test $? -ne 0 ; then cat log; no_result; fi
313
314cat > $tmp << 'end'
315description = "A bogus project created to test the aedis functionality.";
316developer_may_review = true;
317developer_may_integrate = true;
318reviewer_may_integrate = true;
319default_test_exemption = true;
320end
321if test $? -ne 0 ; then no_result; fi
322
323$bin/aegis -pa -p $AEGIS_PROJECT -f $tmp > log 2>&1
324if test $? -ne 0 ; then cat log; no_result; fi
325
326
327#
328# add the staff
329#
330activity="staff 332"
331$bin/aegis -nd $USER -p $AEGIS_PROJECT > log 2>&1
332if test $? -ne 0 ; then cat log; no_result; fi
333$bin/aegis -nrv $USER -p $AEGIS_PROJECT > log 2>&1
334if test $? -ne 0 ; then cat log; no_result; fi
335$bin/aegis -ni $USER -p $AEGIS_PROJECT > log 2>&1
336if test $? -ne 0 ; then cat log; no_result; fi
337
338activity="receive the change 340"
339$bin/aedist -r -p $AEGIS_PROJECT -f $work/$AEGIS_PROJECT.ae \
340    -dir $workchan -verb > log 2>&1
341if test $? -ne 0 ; then cat log; fail; fi
342
343#
344# Only definite negatives are possible.
345# The functionality exercised by this test appears to work,
346# no other guarantees are made.
347#
348pass
349