1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 1991-1998, 2000, 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# Make sure aede and aeipass can cope with symbolic links.
21# This test will always pass on systems without symbolic links.
22#
23
24unset AEGIS_PROJECT
25unset AEGIS_CHANGE
26unset AEGIS_PATH
27unset AEGIS
28unset LINES
29unset COLS
30umask 022
31
32USER=${USER:-${LOGNAME:-`whoami`}}
33
34PAGER=cat
35export PAGER
36
37AEGIS_FLAGS="delete_file_preference = no_keep; \
38	lock_wait_preference = always; \
39	diff_preference = automatic_merge; \
40	pager_preference = never; \
41	persevere_preference = all; \
42	log_file_preference = never;"
43export AEGIS_FLAGS
44AEGIS_THROTTLE=-1
45export AEGIS_THROTTLE
46
47work=${AEGIS_TMP:-/tmp}/$$
48
49here=`pwd`
50if test $? -ne 0 ; then exit 2; fi
51
52if test "$1" != "" ; then bin="$here/$1/bin"; else bin="$here/bin"; fi
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
70no_result()
71{
72	set +x
73	echo "NO RESULT for  test for correct behaviour around symbolic links ($activity)" 1>&2
74	cd $here
75	find $work -type d -user $USER -exec chmod u+w {} \;
76	rm -rf $work
77	exit 2
78}
79fail()
80{
81	set +x
82	echo "FAILED test for correct behaviour around symbolic links ($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}
88pass()
89{
90	set +x
91	echo PASSED 1>&2
92	cd $here
93	find $work -type d -user $USER -exec chmod u+w {} \;
94	rm -rf $work
95	exit 0
96}
97trap "no_result" 1 2 3 15
98
99activity="working directory 86"
100mkdir $work $work/lib
101if test $? -ne 0 ; then no_result; fi
102chmod 777 $work/lib
103if test $? -ne 0 ; then no_result; fi
104cd $work
105if test $? -ne 0 ; then no_result; fi
106
107#
108# use the built-in error messages
109#
110AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
111export AEGIS_MESSAGE_LIBRARY
112unset LANG
113unset LANGUAGE
114
115#
116# If the C++ compiler is called something other than "c++", as
117# discovered by the configure script, create a shell script called
118# "c++" which invokes the correct C++ compiler.  Make sure the current
119# directory is in the path, so that it will be invoked.
120#
121if test "$CXX" != "c++"
122then
123	cat >> c++ << fubar
124#!/bin/sh
125exec ${CXX-g++} \$*
126fubar
127	if test $? -ne 0 ; then no_result; fi
128	chmod a+rx c++
129	if test $? -ne 0 ; then no_result; fi
130	PATH=${work}:${PATH}
131	export PATH
132fi
133
134#
135# program to ask questions about symlinks
136#
137activity="symlink test program 124"
138cat > symlink.cc << 'fubar'
139#include <sys/types.h>
140#include <sys/stat.h>
141int
142main(int argc, char **argv)
143{
144#ifdef S_IFLNK
145	if (argc == 2)
146	{
147		struct stat st;
148		if (lstat(argv[1], &st))
149			return 0;
150		/* fails if file exists */
151		return 1;
152	}
153	return 0;
154#else
155	return 2;
156#endif
157}
158fubar
159if test $? -ne 0 ; then no_result; fi
160c++ -o symlink symlink.cc
161if test $? -ne 0 ; then no_result; fi
162
163#
164# if this system has no symlinks
165# automagically pass the test
166#
167./symlink
168if test $? -ge 2 ; then pass; fi
169
170#
171# some variable to make things earier to read
172#
173worklib=$work/lib
174workproj=$work/foo.proj
175workchan=$work/foo.chan
176tmp=$work/tmp
177symlinktestfile=$workchan/symlink
178symlinkdest=$workchan/symlinkdest
179
180#
181# make a new project
182#	and check files it should have made
183#
184activity="new project 171"
185$bin/aegis -newpro foo -version "" -dir $workproj -lib $worklib
186if test $? -ne 0 ; then no_result; fi
187
188#
189# change project attributes
190#
191activity="project attributes 178"
192cat > $tmp << 'end'
193description = "A bogus project created to test things.";
194developer_may_review = true;
195developer_may_integrate = true;
196reviewer_may_integrate = true;
197end
198if test $? -ne 0 ; then no_result; fi
199$bin/aegis -proatt -f $tmp -proj foo -lib $worklib
200if test $? -ne 0 ; then no_result; fi
201
202#
203# create a new change
204#	make sure it creates the files it should
205#
206activity="new change 193"
207cat > $tmp << 'end'
208brief_description = "This change is used to test the aegis functionality \
209with respect to change descriptions.";
210cause = internal_bug;
211end
212$bin/aegis -new_change 1 -f $tmp -project foo -lib $worklib
213if test $? -ne 0 ; then no_result; fi
214
215#
216# add a new developer
217#
218activity="new developer 205"
219$bin/aegis -newdev $USER -p foo -lib $worklib
220if test $? -ne 0 ; then no_result; fi
221
222#
223# begin development of a change
224#	check it made the files it should
225#
226activity="develop begin 213"
227$bin/aegis -devbeg 1 -p foo -dir $workchan -lib $worklib
228if test $? -ne 0 ; then no_result; fi
229
230#
231# create a symbolic link in the development directory
232#
233activity="create a symlink 220"
234mkdir $symlinkdest
235if test $? -ne 0 ; then no_result; fi
236ln -s $symlinkdest $symlinktestfile
237if test $? -ne 0 ; then no_result; fi
238
239#
240# add a new files to the change
241#
242activity="new file 229"
243$bin/aegis -new_file $workchan/main.cc -nl -lib $worklib -p foo
244if test $? -ne 0 ; then no_result; fi
245$bin/aegis -new_file $workchan/aegis.conf -nl -lib $worklib -p foo
246if test $? -ne 0 ; then no_result; fi
247cat > $workchan/main.cc << 'end'
248int
249main(int argc, char **argv)
250{
251	return 0;
252}
253end
254if test $? -ne 0 ; then no_result; fi
255cat > $workchan/aegis.conf << 'end'
256build_command = "rm -f foo; c++ -o foo -D'VERSION=\"$v\"' main.cc";
257link_integration_directory = true;
258
259history_get_command = "aesvt -check-out -edit ${quote $edit} "
260    "-history ${quote $history} -f ${quote $output}";
261history_put_command = "aesvt -check-in -history ${quote $history} "
262    "-f ${quote $input}";
263history_query_command = "aesvt -query -history ${quote $history}";
264history_content_limitation = binary_capable;
265
266diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
267
268diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
269	echo '1,$$p' ) | ed - $mr > $out";
270end
271if test $? -ne 0 ; then no_result; fi
272
273#
274# create a new test
275#
276activity="new test 265"
277$bin/aegis -nt -lib $worklib -p foo
278if test $? -ne 0 ; then fail; fi
279cat > $workchan/test/00/t0001a.sh << 'end'
280#!/bin/sh
281no_result()
282{
283	echo WHIMPER 1>&2
284	exit 2
285}
286fail()
287{
288	echo SHUZBUTT 1>&2
289	exit 1
290}
291pass()
292{
293	exit 0
294}
295trap "no_result" 1 2 3 15
296
297# should not complain
298./foo
299if test $? -ne 0; then fail; fi
300
301# it probably worked
302pass
303end
304if test $? -ne 0 ; then no_result; fi
305
306#
307# build the change
308#
309activity="build 298"
310$bin/aegis -build -nl -lib $worklib -p foo > /dev/null 2>&1
311if test $? -ne 0 ; then no_result; fi
312
313#
314# difference the change
315#
316activity="diff 305"
317$bin/aegis -diff -nl -lib $worklib -p foo > /dev/null 2>&1
318if test $? -ne 0 ; then no_result; fi
319
320#
321# test the change
322#
323activity="test 312"
324$bin/aegis -test -nl -lib $worklib -p foo > /dev/null 2>&1
325if test $? -ne 0 ; then no_result; fi
326
327#
328# finish development of the change
329#
330activity="develop end 319"
331$bin/aegis -dev_end -lib $worklib -p foo
332if test $? -ne 0 ; then fail; fi
333
334#
335# add a new reviewer
336#
337activity="new reviewer 326"
338$bin/aegis -newrev $USER -p foo -lib $worklib
339if test $? -ne 0 ; then no_result; fi
340
341#
342# pass the review
343#
344activity="review pass 333"
345$bin/aegis -review_pass -chan 1 -proj foo -lib $worklib
346if test $? -ne 0 ; then no_result; fi
347
348#
349# add an integrator
350#
351activity="new integrator 340"
352$bin/aegis -newint $USER -p foo -lib $worklib
353if test $? -ne 0 ; then no_result; fi
354
355#
356# start integrating
357#
358activity="integrate begin 347"
359$bin/aegis -intbeg 1 -p foo -lib $worklib
360if test $? -ne 0 ; then no_result; fi
361
362#
363# integrate build
364#
365activity="build 354"
366$bin/aegis -build -nl -lib $worklib -p foo > /dev/null 2>&1
367if test $? -ne 0 ; then no_result; fi
368activity="test 357"
369$bin/aegis -test -nl -lib $worklib -p foo > /dev/null 2>&1
370if test $? -ne 0 ; then no_result; fi
371
372#
373# pass the integration
374#
375activity="integrate pass 364"
376$bin/aegis -intpass -nl -lib $worklib -p foo > /dev/null 2>&1
377if test $? -ne 0 ; then fail; fi
378
379#
380# see if the symbolic link in the work area has been removed
381# or wether it is still there
382# It is meant to have been removed.
383#
384activity="symlink existence 379"
385./symlink $symlinktestfile
386if test $? -ne 0 ; then fail; fi
387
388# should be no automatic logging
389if test "`find $work -name 'aegis.log' -print`" != "" ; then no_result; fi
390
391#
392# the things tested in this test, worked
393#
394pass
395