1#!/bin/sh
2#
3#       aegis - project change supervisor
4#       Copyright (C) 1996-1998, 2000, 2002-2008, 2012 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}/$$
32PAGER=cat
33export PAGER
34AEGIS_FLAGS="delete_file_preference = no_keep; \
35        lock_wait_preference = always; \
36        diff_preference = automatic_merge; \
37        pager_preference = never; \
38        persevere_preference = all; \
39        log_file_preference = never;"
40export AEGIS_FLAGS
41AEGIS_THROTTLE=-1
42export AEGIS_THROTTLE
43
44here=`pwd`
45if test $? -ne 0 ; then exit 2; fi
46
47bin=$here/${1-.}/bin
48
49pass()
50{
51        set +x
52        echo PASSED 1>&2
53        cd $here
54        find $work -type d -user $USER -exec chmod u+w {} \;
55        rm -rf $work
56        exit 0
57}
58fail()
59{
60        set +x
61        echo "FAILED test of the aenfu functionality ($activity)" 1>&2
62        cd $here
63        find $work -type d -user $USER -exec chmod u+w {} \;
64        rm -rf $work
65        exit 1
66}
67no_result()
68{
69        set +x
70        echo "NO RESULT for test of the aenfu functionality ($activity)" 1>&2
71        cd $here
72        find $work -type d -user $USER -exec chmod u+w {} \;
73        rm -rf $work
74        exit 2
75}
76trap \"no_result\" 1 2 3 15
77
78check_it()
79{
80        sed     -e "s|$work|...|g" \
81                -e 's|= [0-9][0-9]*; /.*|= TIME;|' \
82                -e "s/\"$USER\"/\"USER\"/g" \
83                -e 's/19[0-9][0-9]/YYYY/' \
84                -e 's/20[0-9][0-9]/YYYY/' \
85                -e 's/node = ".*"/node = "NODE"/' \
86                -e 's/crypto = ".*"/crypto = "GUNK"/' \
87                -e 's/uuid = ".*"/uuid = "UUID"/' \
88                < $2 > $work/sed.out
89        if test $? -ne 0; then no_result; fi
90        diff -b $1 $work/sed.out
91        if test $? -ne 0; then fail; fi
92}
93
94activity="working directory 94"
95mkdir $work $work/lib
96if test $? -ne 0 ; then no_result; fi
97chmod 777 $work/lib
98if test $? -ne 0 ; then no_result; fi
99cd $work
100if test $? -ne 0 ; then no_result; fi
101
102workchan=$work/chan
103workproj=$work/proj
104worklib=$work/lib
105tmp=$work/tmp
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# make a new project
117#
118activity="new project 118"
119$bin/aegis -newpro foo -version "" -dir $workproj -lib $worklib
120if test $? -ne 0 ; then no_result; fi
121
122#
123# change project attributes
124#
125activity="project attributes 125"
126cat > $tmp << 'end'
127developer_may_review = true;
128developer_may_integrate = true;
129reviewer_may_integrate = true;
130end
131if test $? -ne 0 ; then no_result; fi
132$bin/aegis -proatt -f $tmp -proj foo -lib $worklib
133if test $? -ne 0 ; then no_result; fi
134
135#
136# create a new change
137#
138activity="new change 138"
139cat > $tmp << 'end'
140brief_description = "one";
141cause = internal_bug;
142end
143if test $? -ne 0 ; then no_result; fi
144$bin/aegis -new_change 1 -f $tmp -project foo -lib $worklib
145if test $? -ne 0 ; then no_result; fi
146
147#
148# add a new developer
149#
150activity="new developer 150"
151$bin/aegis -newdev $USER -p foo -lib $worklib
152if test $? -ne 0 ; then no_result; fi
153
154#
155# begin development of a change
156#
157activity="develop begin 157"
158$bin/aegis -devbeg 1 -p foo -dir $workchan -lib $worklib
159if test $? -ne 0 ; then no_result; fi
160
161#
162# add a new files to the change
163#
164activity="new file 164"
165$bin/aegis -new_file $workchan/aegis.conf $workchan/main.c -nl -lib $worklib -p foo
166if test $? -ne 0 ; then no_result; fi
167
168cat > $workchan/aegis.conf << 'end'
169build_command = "exit 0";
170history_get_command = "exit 0";
171history_create_command = "exit 0";
172history_put_command = "exit 0";
173history_query_command = "echo HAHA";
174diff_command =  "exit 0";
175diff3_command =  "exit 0";
176end
177if test $? -ne 0 ; then no_result; fi
178
179#
180# new file undo
181#
182activity="new file undo 182"
183$bin/aegis -nfu $workchan/main.c -lib $worklib -p foo
184if test $? -ne 0 ; then fail; fi
185
186#
187# check the change state
188#
189activity="check change state 189"
190cat > ok << 'fubar'
191brief_description = "one";
192description = "one";
193cause = internal_enhancement;
194test_exempt = false;
195test_baseline_exempt = true;
196regression_test_exempt = true;
197architecture =
198[
199        "unspecified",
200];
201copyright_years =
202[
203        YYYY,
204];
205state = being_developed;
206given_regression_test_exemption = true;
207development_directory = ".../chan";
208history =
209[
210        {
211                when = TIME;
212                what = new_change;
213                who = "USER";
214        },
215        {
216                when = TIME;
217                what = develop_begin;
218                who = "USER";
219        },
220];
221fubar
222if test $? -ne 0 ; then no_result; fi
223check_it ok $workproj/info/change/0/001
224
225activity="check change file state 225"
226cat > ok << 'fubar'
227src =
228[
229        {
230                file_name = "aegis.conf";
231                uuid = "UUID";
232                action = create;
233                usage = config;
234        },
235];
236fubar
237if test $? -ne 0 ; then no_result; fi
238check_it ok $workproj/info/change/0/001.fs
239
240#
241# Only definite negatives are possible.
242# The functionality exercised by this test appears to work,
243# no other guarantees are made.
244#
245pass
246# vim: set ts=8 sw=4 et :
247