1#!/bin/sh
2#
3#       aegis - project change supervisor
4#       Copyright (C) 2003-2008, 2012 Peter Miller
5#       Copyright (C) 2008 Walter Franzini
6#
7#       This program is free software; you can redistribute it and/or modify
8#       it under the terms of the GNU General Public License as published by
9#       the Free Software Foundation; either version 3 of the License, or
10#       (at your option) any later version.
11#
12#       This program is distributed in the hope that it will be useful,
13#       but WITHOUT ANY WARRANTY; without even the implied warranty of
14#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#       GNU General Public License for more details.
16#
17#       You should have received a copy of the GNU General Public License
18#       along with this program. If not, see
19#       <http://www.gnu.org/licenses/>.
20#
21
22unset AEGIS_PROJECT
23unset AEGIS_CHANGE
24unset AEGIS_PATH
25unset AEGIS
26unset LINES
27unset COLS
28umask 022
29
30USER=${USER:-${LOGNAME:-`whoami`}}
31
32work=${AEGIS_TMP:-/tmp}/$$
33
34here=`pwd`
35if test $? -ne 0 ; then exit 2; fi
36
37if test "$1" != "" ; then bin="$here/$1/bin"; else bin="$here/bin"; fi
38
39if test "$EXEC_SEARCH_PATH" != ""
40then
41    tpath=
42    hold="$IFS"
43    IFS=":$IFS"
44    for tpath2 in $EXEC_SEARCH_PATH
45    do
46        tpath=${tpath}${tpath2}/${1-.}/bin:
47    done
48    IFS="$hold"
49    PATH=${tpath}${PATH}
50else
51    PATH=${bin}:${PATH}
52fi
53export PATH
54
55check_it()
56{
57        sed     -e "s|$work|...|g" \
58                -e 's|= [0-9][0-9]*; /.*|= TIME;|' \
59                -e "s/\"$USER\"/\"USER\"/g" \
60                -e 's/19[0-9][0-9]/YYYY/' \
61                -e 's/20[0-9][0-9]/YYYY/' \
62                -e 's/node = ".*"/node = "NODE"/' \
63                -e 's/crypto = ".*"/crypto = "GUNK"/' \
64                -e 's/uuid = ".*"/uuid = "UUID"/' \
65                < $2 > $work/sed.out
66        if test $? -ne 0; then no_result; fi
67        diff -b $1 $work/sed.out
68        if test $? -ne 0; then fail; fi
69}
70
71no_result()
72{
73        set +x
74        echo "NO RESULT for test of aemt -unch functionality ($activity)" 1>&2
75        cd $here
76        find $work -type d -user $USER -exec chmod u+w {} \;
77        rm -rf $work
78        exit 2
79}
80fail()
81{
82        set +x
83        echo "FAILED test of aemt -unch functionality ($activity)" 1>&2
84        cd $here
85        find $work -type d -user $USER -exec chmod u+w {} \;
86        rm -rf $work
87        exit 1
88}
89pass()
90{
91        set +x
92        echo PASSED 1>&2
93        cd $here
94        find $work -type d -user $USER -exec chmod u+w {} \;
95        rm -rf $work
96        exit 0
97}
98trap "no_result" 1 2 3 15
99
100#
101# some variable to make things earier to read
102#
103PAGER=cat
104export PAGER
105
106AEGIS_FLAGS="delete_file_preference = no_keep; \
107        lock_wait_preference = always; \
108        diff_preference = automatic_merge; \
109        pager_preference = never; \
110        persevere_preference = all; \
111        log_file_preference = never;"
112export AEGIS_FLAGS
113AEGIS_THROTTLE=-1
114export AEGIS_THROTTLE
115
116worklib=$work/lib
117workproj=$work/foo.proj
118workchan=$work/foo.chan
119tmp=$work/tmp
120AEGIS_PATH=$worklib ; export AEGIS_PATH
121AEGIS_PROJECT=foo ; export AEGIS_PROJECT
122
123#
124# make the directories
125#
126activity="working directory 119"
127mkdir $work $work/lib
128if test $? -ne 0 ; then no_result; fi
129chmod 777 $work/lib
130if test $? -ne 0 ; then no_result; fi
131cd $work
132if test $? -ne 0 ; then no_result; fi
133
134#
135# use the built-in error messages
136#
137AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
138export AEGIS_MESSAGE_LIBRARY
139unset LANG
140unset LANGUAGE
141
142#
143# make a new project
144#
145activity="new project 138"
146$bin/aegis -npr foo -vers "" -dir $workproj > log 2>&1
147if test $? -ne 0 ; then cat log; no_result; fi
148
149#
150# change project attributes
151#
152activity="project attributes 145"
153cat > $tmp << 'end'
154description = "A bogus project created to test the aemt -unch functionality.";
155developer_may_review = true;
156developer_may_integrate = true;
157reviewer_may_integrate = true;
158default_test_exemption = true;
159end
160if test $? -ne 0 ; then no_result; fi
161$bin/aegis -pa -f $tmp > log 2>&1
162if test $? -ne 0 ; then cat log; no_result; fi
163
164#
165# add the staff
166#
167activity="staff 160"
168$bin/aegis -nd $USER > log 2>&1
169if test $? -ne 0 ; then cat log; no_result; fi
170$bin/aegis -nrv $USER > log 2>&1
171if test $? -ne 0 ; then cat log; no_result; fi
172$bin/aegis -ni $USER > log 2>&1
173if test $? -ne 0 ; then cat log; no_result; fi
174
175# --------------------------------------------------------------------------
176
177#
178# create a new change
179#
180activity="new change 173"
181cat > $tmp << 'end'
182brief_description = "The first change";
183cause = internal_bug;
184end
185if test $? -ne 0 ; then no_result; fi
186$bin/aegis -nc 1 -f $tmp -p foo > log 2>&1
187if test $? -ne 0 ; then cat log; no_result; fi
188
189#
190# begin development of a change
191#
192$bin/aegis -db 1 -dir $workchan > log 2>&1
193if test $? -ne 0 ; then cat log; no_result; fi
194
195#
196# add a new files to the change
197#
198activity="new file 191"
199$bin/aegis -nf  $workchan/aegis.conf $workchan/bogus $workchan/bogus2 -nl > log 2>&1
200if test $? -ne 0 ; then cat log; no_result; fi
201
202cat > $workchan/bogus << 'end'
203the trunk version
204end
205if test $? -ne 0 ; then no_result; fi
206
207cat > $workchan/bogus2 << 'end'
208the trunk version 2
209end
210if test $? -ne 0 ; then no_result; fi
211
212cat > $workchan/aegis.conf << 'end'
213build_command = "exit 0";
214link_integration_directory = true;
215
216history_get_command = "aesvt -check-out -edit ${quote $edit} "
217    "-history ${quote $history} -f ${quote $output}";
218history_put_command = "aesvt -check-in -history ${quote $history} "
219    "-f ${quote $input}";
220history_query_command = "aesvt -query -history ${quote $history}";
221history_content_limitation = binary_capable;
222
223diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
224diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
225        echo '1,$$p' ) | ed - $mr > $out";
226patch_diff_command = "set +e; diff -C0 -L $index -L $index $orig $i > $out; \
227test $$? -le 1";
228end
229if test $? -ne 0 ; then no_result; fi
230
231#
232# build the change
233#
234activity="build 227"
235$bin/aegis -build -nl -v > log 2>&1
236if test $? -ne 0 ; then cat log; fail; fi
237
238#
239# difference the change
240#
241activity="diff 234"
242$bin/aegis -diff > log 2>&1
243if test $? -ne 0 ; then cat log; no_result; fi
244
245#
246# finish development of the change
247#
248activity="develop end 241"
249$bin/aegis -de > log 2>&1
250if test $? -ne 0 ; then cat log; fail; fi
251
252#
253# pass the review
254#
255activity="review pass 248"
256$bin/aegis -rpass -c 1 > log 2>&1
257if test $? -ne 0 ; then cat log; no_result; fi
258
259#
260# start integrating
261#
262activity="integrate begin 255"
263$bin/aegis -ib 1 > log 2>&1
264if test $? -ne 0 ; then cat log; no_result; fi
265
266#
267# integrate build
268#
269activity="build 262"
270$bin/aegis -b -nl -v > log 2>&1
271if test $? -ne 0 ; then cat log; no_result; fi
272
273#
274# pass the integration
275#
276activity="integrate pass 269"
277$bin/aegis -intpass -nl > log 2>&1
278if test $? -ne 0 ; then cat log; no_result; fi
279
280# --------------------------------------------------------------------------
281
282#
283# create a branch
284#
285activity="new branch 278"
286$bin/aegis -nbr -p foo 2 > log 2>&1
287if test $? -ne 0 ; then cat log; no_result; fi
288
289AEGIS_PROJECT=foo.2
290export AEGIS_PROJECT
291
292# --------------------------------------------------------------------------
293
294#
295# create a new change
296#
297activity="new change 290"
298cat > $tmp << 'end'
299brief_description = "The second change";
300cause = internal_bug;
301end
302if test $? -ne 0 ; then no_result; fi
303$bin/aegis -nc 3 -f $tmp -p foo.2 > log 2>&1
304if test $? -ne 0 ; then cat log; no_result; fi
305
306#
307# begin development of a change
308#
309$bin/aegis -db 3 -dir $workchan > log 2>&1
310if test $? -ne 0 ; then cat log; no_result; fi
311
312#
313# add files to the change
314#
315activity="copy file 308"
316$bin/aegis -cp  $workchan/bogus $workchan/bogus2 -nl > log 2>&1
317if test $? -ne 0 ; then cat log; no_result; fi
318
319cat > $workchan/bogus2 << 'end'
320the branch version 2
321end
322if test $? -ne 0 ; then no_result; fi
323
324activity="new file 317"
325$bin/aegis -nf  $workchan/bogus3 -nl > log 2>&1
326if test $? -ne 0 ; then cat log; no_result; fi
327
328cat > $workchan/bogus3 << 'end'
329the branch version 3
330end
331if test $? -ne 0 ; then no_result; fi
332
333#
334# build the change
335#
336activity="build 329"
337$bin/aegis -build -nl -v > log 2>&1
338if test $? -ne 0 ; then cat log; fail; fi
339
340#
341# difference the change
342#
343activity="diff 336"
344$bin/aegis -diff > log 2>&1
345if test $? -ne 0 ; then cat log; no_result; fi
346
347#
348# finish development of the change
349#
350activity="develop end 343"
351$bin/aegis -de > log 2>&1
352if test $? -ne 0 ; then cat log; fail; fi
353
354#
355# pass the review
356#
357activity="review pass 350"
358$bin/aegis -rpass -c 3 > log 2>&1
359if test $? -ne 0 ; then cat log; no_result; fi
360
361#
362# start integrating
363#
364activity="integrate begin 357"
365$bin/aegis -ib 3 > log 2>&1
366if test $? -ne 0 ; then cat log; no_result; fi
367
368#
369# integrate build
370#
371activity="build 364"
372$bin/aegis -b -nl -v > log 2>&1
373if test $? -ne 0 ; then cat log; no_result; fi
374
375#
376# integrate diff
377#
378activity="diff 371"
379$bin/aegis -diff -nl -v > log 2>&1
380if test $? -ne 0 ; then cat log; no_result; fi
381
382#
383# pass the integration
384#
385activity="integrate pass 378"
386$bin/aegis -intpass -nl > log 2>&1
387if test $? -ne 0 ; then cat log; no_result; fi
388
389activity="check branch file state 382"
390cat > ok << 'end'
391src =
392[
393        {
394                file_name = "bogus";
395                uuid = "UUID";
396                action = modify;
397                edit =
398                {
399                        revision = "2";
400                        encoding = none;
401                        uuid = "UUID";
402                };
403                edit_origin =
404                {
405                        revision = "1";
406                        encoding = none;
407                        uuid = "UUID";
408                };
409                usage = source;
410                file_fp =
411                {
412                        youngest = TIME;
413                        oldest = TIME;
414                        crypto = "GUNK";
415                };
416                diff_file_fp =
417                {
418                        youngest = TIME;
419                        oldest = TIME;
420                        crypto = "GUNK";
421                };
422        },
423        {
424                file_name = "bogus2";
425                uuid = "UUID";
426                action = modify;
427                edit =
428                {
429                        revision = "2";
430                        encoding = none;
431                        uuid = "UUID";
432                };
433                edit_origin =
434                {
435                        revision = "1";
436                        encoding = none;
437                        uuid = "UUID";
438                };
439                usage = source;
440                file_fp =
441                {
442                        youngest = TIME;
443                        oldest = TIME;
444                        crypto = "GUNK";
445                };
446                diff_file_fp =
447                {
448                        youngest = TIME;
449                        oldest = TIME;
450                        crypto = "GUNK";
451                };
452        },
453        {
454                file_name = "bogus3";
455                uuid = "UUID";
456                action = create;
457                edit =
458                {
459                        revision = "1";
460                        encoding = none;
461                        uuid = "UUID";
462                };
463                edit_origin =
464                {
465                        revision = "1";
466                        encoding = none;
467                        uuid = "UUID";
468                };
469                usage = source;
470                file_fp =
471                {
472                        youngest = TIME;
473                        oldest = TIME;
474                        crypto = "GUNK";
475                };
476                diff_file_fp =
477                {
478                        youngest = TIME;
479                        oldest = TIME;
480                        crypto = "GUNK";
481                };
482        },
483];
484end
485if test $? -ne 0 ; then no_result; fi
486
487check_it ok $workproj/info/change/0/002.fs
488
489# --------------------------------------------------------------------------
490
491#
492# create a new change
493#
494activity="new change 481"
495cat > $tmp << 'end'
496brief_description = "The third change";
497cause = internal_bug;
498end
499if test $? -ne 0 ; then no_result; fi
500$bin/aegis -nc 4 -f $tmp -p foo.2 > log 2>&1
501if test $? -ne 0 ; then cat log; no_result; fi
502
503#
504# begin development of a change
505#
506$bin/aegis -db 4 -dir $workchan > log 2>&1
507if test $? -ne 0 ; then cat log; no_result; fi
508
509#
510# add files to the change
511#
512activity="make transparent 499"
513$bin/aegis -mt -unch -nl -c 4 -trace nth aemt find > log 2>&1
514if test $? -ne 0 ; then cat log; fail; fi
515
516activity="check change file state 503"
517cat > ok << 'end'
518src =
519[
520        {
521                file_name = "bogus";
522                uuid = "UUID";
523                action = transparent;
524                edit_origin =
525                {
526                        revision = "2";
527                        encoding = none;
528                        uuid = "UUID";
529                };
530                usage = source;
531        },
532];
533end
534if test $? -ne 0 ; then no_result; fi
535
536check_it ok $workproj/info/change/0/002.branch/0/004.fs
537
538#
539# the things tested in this test, worked
540# can't speak for the rest of the code
541#
542pass
543# vim: set ts=8 sw=4 et :
544