]> git.ipfire.org Git - thirdparty/dhcp.git/blob - tests/unittest.sh.in
[master] Update auto files as part of moving docs systems
[thirdparty/dhcp.git] / tests / unittest.sh.in
1 #!/bin/sh
2 #
3 # Copyright (C) 2015 Internet Systems Consortium, Inc. ("ISC")
4 #
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
16 #
17 # Script used to execute unit tests described by the Atffile in the current
18 # directory. It exits with return value of atf-run, which will be 0 if all
19 # tests passed, non-zero otherwise.
20 #
21
22 # Add configured path to ATF tools, atf-run and atf-report
23 PATH="@ATF_BIN@:${PATH}"
24 export PATH
25
26 # colors if not outputting to a dumb terminal and stdout is a tty
27 if test "$TERM" != dumb && { test -t 1; } 2>/dev/null; then \
28 red='\033[0;31m'
29 green='\033[0;32m'
30 noclr='\033[0m'
31
32 # if echo supports -e, we must use it to set colors
33 # (output will be "" if its supported)
34 if [ -z "`echo -e`" ]
35 then
36 dash_e="-e"
37 fi
38 fi;
39
40 header="===================================================="
41
42 status=0
43 if [ -n "@ATF_BIN@" -a -f Atffile ]
44 then
45 # run the tests
46 echo "Running unit tests..."
47 atf-run > atf.out
48 status=$?
49
50 # set color based on success/failure
51 if [ $status -eq 0 ]
52 then
53 color=$green
54 else
55 color=$red
56 fi
57
58 # spit out the test report
59 # We print everything upto the summary in
60 # "no color". Print the summary in our
61 # result color.
62 cat atf.out | atf-report | while read line
63 do
64 cnt=`echo $line | grep -c "Summary"`
65 if [ $cnt -eq 1 ]
66 then
67 echo $dash_e $color$header
68 fi
69 echo $line;
70 done
71 echo $dash_e $header$noclr
72
73 # clean up unless there were test failures
74 if [ $status -eq 0 ]
75 then
76 rm -f atf.out
77 fi
78 fi
79 exit $status