1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 2003, 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 change_file_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 change_file_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 change_file_command functionality.";
138developer_may_review = true;
139developer_may_integrate = true;
140reviewer_may_integrate = true;
141default_test_exemption = 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# add the staff
149#
150activity="staff 144"
151$bin/aegis -nd $USER > log 2>&1
152if test $? -ne 0 ; then cat log; no_result; fi
153$bin/aegis -nrv $USER > log 2>&1
154if test $? -ne 0 ; then cat log; no_result; fi
155$bin/aegis -ni $USER > log 2>&1
156if test $? -ne 0 ; then cat log; no_result; fi
157
158# --------------------------------------------------------------------------
159
160#
161# create a new change
162#
163activity="new change 157"
164cat > $tmp << 'end'
165brief_description = "The first change";
166cause = internal_bug;
167end
168if test $? -ne 0 ; then no_result; fi
169$bin/aegis -nc 1 -f $tmp -p foo > log 2>&1
170if test $? -ne 0 ; then cat log; no_result; fi
171
172#
173# begin development of a change
174#
175$bin/aegis -db 1 -dir $workchan > log 2>&1
176if test $? -ne 0 ; then cat log; no_result; fi
177
178#
179# add a new files to the change
180#
181activity="new file 175"
182$bin/aegis -nf  $workchan/aegis.conf -nl > log 2>&1
183if test $? -ne 0 ; then cat log; no_result; fi
184
185cat > $workchan/aegis.conf << 'end'
186build_command = "exit 0";
187link_integration_directory = true;
188
189history_get_command = "aesvt -check-out -edit ${quote $edit} "
190    "-history ${quote $history} -f ${quote $output}";
191history_put_command = "aesvt -check-in -history ${quote $history} "
192    "-f ${quote $input}";
193history_query_command = "aesvt -query -history ${quote $history}";
194history_content_limitation = binary_capable;
195
196diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
197merge_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
198	echo '1,$$p' ) | ed - $mr > $out";
199patch_diff_command = "set +e; diff -C0 -L $index -L $index $orig $i > $out; \
200test $$? -le 1";
201change_file_command = "echo $fl > change_file_command";
202end
203if test $? -ne 0 ; then no_result; fi
204
205activity="change_file_command (nf) 199"
206$bin/aegis -nf $workchan/bogus -nl > log 2>&1
207if test $? -ne 0 ; then cat log; fail; fi
208
209test -f $workchan/change_file_command || fail
210
211cat > $workchan/bogus << 'end'
212the trunk version
213end
214if test $? -ne 0 ; then no_result; fi
215
216cat > $workchan/aegis.conf << 'end'
217build_command = "exit 0";
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";
228merge_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
229	echo '1,$$p' ) | ed - $mr > $out";
230patch_diff_command = "set +e; diff -C0 -L $index -L $index $orig $i > $out; \
231test $$? -le 1";
232change_file_command = "echo $fl > change_file_command";
233new_file_command = "echo $fl > new_file_command";
234end
235if test $? -ne 0 ; then no_result; fi
236
237activity="new_file_command 231"
238$bin/aegis -nf $workchan/bogus2 -nl > log 2>&1
239if test $? -ne 0 ; then cat log; fail; fi
240
241test -f $workchan/new_file_command || fail
242
243cat > $workchan/bogus2 << 'end'
244the trunk version 2
245end
246if test $? -ne 0 ; then no_result; fi
247
248#
249# build the change
250#
251activity="build 245"
252$bin/aegis -build -nl -v > log 2>&1
253if test $? -ne 0 ; then cat log; fail; fi
254
255#
256# difference the change
257#
258activity="diff 252"
259$bin/aegis -diff > log 2>&1
260if test $? -ne 0 ; then cat log; no_result; fi
261
262#
263# finish development of the change
264#
265activity="develop end 259"
266$bin/aegis -de > log 2>&1
267if test $? -ne 0 ; then cat log; fail; fi
268
269#
270# pass the review
271#
272activity="review pass 266"
273$bin/aegis -rpass -c 1 > log 2>&1
274if test $? -ne 0 ; then cat log; no_result; fi
275
276#
277# start integrating
278#
279activity="integrate begin 273"
280$bin/aegis -ib 1 > log 2>&1
281if test $? -ne 0 ; then cat log; no_result; fi
282
283#
284# integrate build
285#
286activity="build 280"
287$bin/aegis -b -nl -v > log 2>&1
288if test $? -ne 0 ; then cat log; no_result; fi
289
290#
291# pass the integration
292#
293activity="integrate pass 287"
294$bin/aegis -intpass -nl > log 2>&1
295if test $? -ne 0 ; then cat log; no_result; fi
296
297# --------------------------------------------------------------------------
298
299#
300# create a new change
301#
302activity="new change 296"
303cat > $tmp << 'end'
304brief_description = "The second change";
305cause = internal_bug;
306end
307if test $? -ne 0 ; then no_result; fi
308$bin/aegis -nc 2 -f $tmp -p foo > log 2>&1
309if test $? -ne 0 ; then cat log; no_result; fi
310
311#
312# begin development of a change
313#
314$bin/aegis -db 2 -dir $workchan > log 2>&1
315if test $? -ne 0 ; then cat log; no_result; fi
316
317#
318# copy a file into the change
319#
320activity="change_file_command (cp) 314"
321$bin/aegis -cp  $workchan/aegis.conf $workchan/bogus2 -nl > log 2>&1
322if test $? -ne 0 ; then cat log; no_result; fi
323
324test $workchan/change_file_command || fail
325
326rm $workchan/change_file_command || no_result
327activity="change_file_command (cpu) 321"
328$bin/aegis -cpu  $workchan/bogus2 -nl > log 2>&1
329if test $? -ne 0 ; then cat log; no_result; fi
330
331test $workchan/change_file_command || fail
332
333cat > $workchan/aegis.conf << 'end'
334build_command = "exit 0";
335link_integration_directory = true;
336
337history_get_command = "aesvt -check-out -edit ${quote $edit} "
338    "-history ${quote $history} -f ${quote $output}";
339history_put_command = "aesvt -check-in -history ${quote $history} "
340    "-f ${quote $input}";
341history_query_command = "aesvt -query -history ${quote $history}";
342history_content_limitation = binary_capable;
343
344diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
345merge_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
346	echo '1,$$p' ) | ed - $mr > $out";
347patch_diff_command = "set +e; diff -C0 -L $index -L $index $orig $i > $out; \
348test $$? -le 1";
349change_file_command = "echo $fl > change_file_command";
350new_file_command = "echo $fl > new_file_command";
351copy_file_command = "echo $fl > copy_file_command";
352copy_file_undo_command = "echo $fl > copy_file_undo_command";
353end
354if test $? -ne 0 ; then no_result; fi
355
356activity="copy_file_command 350"
357$bin/aegis -cp $workchan/bogus -nl > log 2>&1
358if test $? -ne 0 ; then cat log; fail; fi
359
360test -f $workchan/copy_file_command || fail
361
362activity="copy_file_undo_command 356"
363$bin/aegis -cpu $workchan/bogus -nl > log 2>&1
364if test $? -ne 0 ; then cat log; fail; fi
365
366test -f $workchan/copy_file_undo_command || fail
367
368#
369# build the change
370#
371activity="build 365"
372$bin/aegis -build -nl -v > log 2>&1
373if test $? -ne 0 ; then cat log; fail; fi
374
375#
376# difference the change
377#
378activity="diff 372"
379$bin/aegis -diff > log 2>&1
380if test $? -ne 0 ; then cat log; no_result; fi
381
382#
383# finish development of the change
384#
385activity="develop end 379"
386$bin/aegis -de > log 2>&1
387if test $? -ne 0 ; then cat log; fail; fi
388
389#
390# pass the review
391#
392activity="review pass 386"
393$bin/aegis -rpass -c 2 > log 2>&1
394if test $? -ne 0 ; then cat log; no_result; fi
395
396#
397# start integrating
398#
399activity="integrate begin 393"
400$bin/aegis -ib 2 > log 2>&1
401if test $? -ne 0 ; then cat log; no_result; fi
402
403#
404# integrate build
405#
406activity="build 400"
407$bin/aegis -b -nl -v > log 2>&1
408if test $? -ne 0 ; then cat log; no_result; fi
409
410#
411# pass the integration
412#
413activity="integrate pass 407"
414$bin/aegis -intpass -nl > log 2>&1
415if test $? -ne 0 ; then cat log; no_result; fi
416
417# --------------------------------------------------------------------------
418
419#
420# create a new change
421#
422activity="new change 416"
423cat > $tmp << 'end'
424brief_description = "The third change";
425cause = internal_bug;
426end
427if test $? -ne 0 ; then no_result; fi
428$bin/aegis -nc 3 -f $tmp -p foo > log 2>&1
429if test $? -ne 0 ; then cat log; no_result; fi
430
431#
432# begin development of a change
433#
434$bin/aegis -db 3 -dir $workchan > log 2>&1
435if test $? -ne 0 ; then cat log; no_result; fi
436
437#
438# remove a file
439#
440activity="change_file_command (rm) 434"
441$bin/aegis -rm  $workchan/bogus -nl > log 2>&1
442if test $? -ne 0 ; then cat log; fail; fi
443
444test -f $workchan/change_file_command || fail
445rm $workchan/change_file_command || no_result
446
447#
448# remove_undo a file
449#
450activity="change_file_command (rmu) 444"
451$bin/aegis -rmu  $workchan/bogus -nl > log 2>&1
452if test $? -ne 0 ; then cat log; fail; fi
453
454test -f $workchan/change_file_command || fail
455rm $workchan/change_file_command || no_result
456
457#
458# update the project aegis.conf file
459#
460activity="copy file 454"
461$bin/aegis -cp  $workchan/aegis.conf -nl > log 2>&1
462if test $? -ne 0 ; then cat log; no_result; fi
463
464cat > $workchan/aegis.conf << 'end'
465build_command = "exit 0";
466link_integration_directory = true;
467
468history_get_command = "aesvt -check-out -edit ${quote $edit} "
469    "-history ${quote $history} -f ${quote $output}";
470history_put_command = "aesvt -check-in -history ${quote $history} "
471    "-f ${quote $input}";
472history_query_command = "aesvt -query -history ${quote $history}";
473history_content_limitation = binary_capable;
474
475diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
476merge_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
477	echo '1,$$p' ) | ed - $mr > $out";
478patch_diff_command = "set +e; diff -C0 -L $index -L $index $orig $i > $out; \
479test $$? -le 1";
480change_file_command = "echo $fl > change_file_command";
481new_file_command = "echo $fl > new_file_command";
482copy_file_command = "echo $fl > copy_file_command";
483copy_file_undo_command = "echo $fl > copy_file_undo_command";
484remove_file_command = "echo $fl > remove_file_command";
485remove_file_undo_command = "echo $fl > remove_file_undo_command";
486end
487if test $? -ne 0 ; then no_result; fi
488
489activity="remove_file_command 483"
490$bin/aegis -rm $workchan/bogus2 -nl > log 2>&1
491if test $? -ne 0 ; then cat log; fail; fi
492
493test -f $workchan/remove_file_command || fail
494
495activity="remove_file_undo_command 489"
496$bin/aegis -rmu $workchan/bogus2 -nl > log 2>&1
497if test $? -ne 0 ; then cat log; fail; fi
498
499test -f $workchan/remove_file_undo_command || fail
500
501#
502# build the change
503#
504activity="build 498"
505$bin/aegis -build -nl -v > log 2>&1
506if test $? -ne 0 ; then cat log; fail; fi
507
508#
509# difference the change
510#
511activity="diff 505"
512$bin/aegis -diff > log 2>&1
513if test $? -ne 0 ; then cat log; no_result; fi
514
515#
516# finish development of the change
517#
518activity="develop end 512"
519$bin/aegis -de > log 2>&1
520if test $? -ne 0 ; then cat log; fail; fi
521
522#
523# pass the review
524#
525activity="review pass 519"
526$bin/aegis -rpass -c 3 > log 2>&1
527if test $? -ne 0 ; then cat log; no_result; fi
528
529#
530# start integrating
531#
532activity="integrate begin 526"
533$bin/aegis -ib 3 > log 2>&1
534if test $? -ne 0 ; then cat log; no_result; fi
535
536#
537# integrate build
538#
539activity="build 533"
540$bin/aegis -b -nl -v > log 2>&1
541if test $? -ne 0 ; then cat log; no_result; fi
542
543#
544# pass the integration
545#
546activity="integrate pass 540"
547$bin/aegis -intpass -nl > log 2>&1
548if test $? -ne 0 ; then cat log; no_result; fi
549
550#
551# the things tested in this test, worked
552# can't speak for the rest of the code
553#
554pass
555