1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 1999, 2002, 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
25umask 022
26
27LINES=24
28export LINES
29COLS=80
30export COLS
31
32USER=${USER:-${LOGNAME:-`whoami`}}
33
34work=${AEGIS_TMP:-/tmp}/$$
35PAGER=cat
36export PAGER
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
47here=`pwd`
48if test $? -ne 0 ; then exit 2; fi
49
50bin=$here/${1-.}/bin
51
52check_it()
53{
54	sed	-e "s|$work|...|g" \
55		-e 's|= [0-9][0-9]*; /.*|= TIME;|' \
56		-e "s/\"$USER\"/\"USER\"/g" \
57		-e 's/19[0-9][0-9]/YYYY/' \
58		-e 's/20[0-9][0-9]/YYYY/' \
59		-e 's/node = ".*"/node = "NODE"/' \
60		-e 's/crypto = ".*"/crypto = "GUNK"/' \
61		< $2 > $work/sed.out
62	if test $? -ne 0; then no_result; fi
63	diff $1 $work/sed.out
64	if test $? -ne 0; then fail; fi
65}
66
67pass()
68{
69	set +x
70	echo PASSED 1>&2
71	cd $here
72	find $work -type d -user $USER -exec chmod u+w {} \;
73	rm -rf $work
74	exit 0
75}
76fail()
77{
78	set +x
79	echo "FAILED test of the aenf body_command functionality ($activity)" 1>&2
80	cd $here
81	find $work -type d -user $USER -exec chmod u+w {} \;
82	rm -rf $work
83	exit 1
84}
85no_result()
86{
87	set +x
88	echo "NO RESULT when testing the aenf body_command functionality ($activity)" 1>&2
89	cd $here
90	find $work -type d -user $USER -exec chmod u+w {} \;
91	rm -rf $work
92	exit 2
93}
94trap \"no_result\" 1 2 3 15
95
96activity="working directory 99"
97mkdir $work $work/lib
98if test $? -ne 0 ; then no_result; fi
99chmod 777 $work/lib
100if test $? -ne 0 ; then no_result; fi
101cd $work
102if test $? -ne 0 ; then no_result; fi
103tmp="$work/temp-file"
104
105worklib=$work/lib
106workchan=$work/change-dir
107
108AEGIS_PATH=$worklib
109export AEGIS_PATH
110PATH=$bin:$PATH
111export PATH
112AEGIS_PROJECT=example
113export AEGIS_PROJECT
114
115#
116# use the built-in error messages
117#
118AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
119export AEGIS_MESSAGE_LIBRARY
120unset LANG
121unset LANGUAGE
122
123#
124# test the aenf body_command functionality
125#
126activity="new project 129"
127$bin/aegis -npr example -version '' -lib $worklib -dir $work/proj -v > log 2>&1
128if test $? -ne 0 ; then cat log; no_result; fi
129
130#
131# change project attributes
132#
133activity="project attributes 136"
134cat > $tmp << 'TheEnd'
135description = "bogosity";
136developer_may_review = true;
137developer_may_integrate = true;
138reviewer_may_integrate = true;
139default_test_exemption = true;
140TheEnd
141if test $? -ne 0 ; then no_result; fi
142
143$bin/aegis -proatt -f $tmp -proj example -v > log 2>&1
144if test $? -ne 0 ; then cat log; no_result; fi
145
146#
147# create a new change
148#
149activity="new change 152"
150cat > $tmp << 'TheEnd'
151brief_description = "c1";
152description = "c1";
153cause = internal_enhancement;
154TheEnd
155if test $? -ne 0 ; then no_result; fi
156
157$bin/aegis -nc 1 -f $tmp -project example -v > log 2>&1
158if test $? -ne 0 ; then cat log; no_result; fi
159
160#
161# add the staff
162#
163activity="new developer 166"
164$bin/aegis -newdev $USER -v > log 2>&1
165if test $? -ne 0 ; then cat log; no_result; fi
166activity="new reviewer 169"
167$bin/aegis -newrev $USER -v > log 2>&1
168if test $? -ne 0 ; then cat log; no_result; fi
169activity="new integrator 172"
170$bin/aegis -newint $USER -v > log 2>&1
171if test $? -ne 0 ; then cat log; no_result; fi
172
173#
174# begin development of the change
175#
176activity="develop begin 179"
177$bin/aegis -devbeg 1 -dir $workchan -v > log 2>&1
178if test $? -ne 0 ; then cat log; no_result; fi
179
180#
181# create a suitable aegis.conf file
182#
183activity="new files 186"
184$bin/aegis -nf $workchan/aegis.conf $workchan/template.sh -v > log 2>&1
185if test $? -ne 0 ; then cat log; no_result; fi
186
187cat > $workchan/aegis.conf << 'fubar'
188build_command = "exit 0";
189diff_command = "exit 1";
190merge_command = "exit 1";
191history_create_command = "exit 1";
192history_put_command = "exit 1";
193history_get_command = "exit 1";
194history_query_command = "exit 1";
195file_template =
196[
197	{
198		pattern = [ "*" ];
199		body_command = "sh ${source template.sh abs} $filename";
200	},
201];
202fubar
203if test $? -ne 0 ; then no_result; fi
204
205cat > $workchan/template.sh << 'fubar'
206#!/bin/sh
207echo Hello > $1
208echo $1 >> $1
209fubar
210if test $? -ne 0 ; then no_result; fi
211
212activity="new files 215"
213$bin/aegis -nf $workchan/fred -v > log 2>&1
214if test $? -ne 0 ; then cat log; fail; fi
215
216cat > ok << 'fubar'
217Hello
218fred
219fubar
220if test $? -ne 0 ; then no_result; fi
221
222diff ok $workchan/fred
223if test $? -ne 0 ; then fail; fi
224
225#
226# the things tested in this test, worked
227# the things not tested in this test, may or may not work
228#
229pass
230