]> git.ipfire.org Git - thirdparty/dracut.git/blob - test/test-functions
remove all vim and emacs code format comments
[thirdparty/dracut.git] / test / test-functions
1 #!/bin/bash
2 PATH=/sbin:/bin:/usr/sbin:/usr/bin
3 export PATH
4
5 [[ -e .testdir ]] && . .testdir
6 if [[ -z "$TESTDIR" ]] || [[ ! -d "$TESTDIR" ]]; then
7 TESTDIR=$(mktemp -d --tmpdir="/var/tmp" -t dracut-test.XXXXXX)
8 fi
9 echo "TESTDIR=\"$TESTDIR\"" > .testdir
10 export TESTDIR
11
12 command -v test_check &>/dev/null || test_check() {
13 :
14 }
15
16 # terminal sequence to set color to a 'success' color (currently: green)
17 function SETCOLOR_SUCCESS() { echo -en '\033[0;32m'; }
18 # terminal sequence to set color to a 'failure' color (currently: red)
19 function SETCOLOR_FAILURE() { echo -en '\033[0;31m'; }
20 # terminal sequence to set color to a 'warning' color (currently: yellow)
21 function SETCOLOR_WARNING() { echo -en '\033[0;33m'; }
22 # terminal sequence to reset to the default color.
23 function SETCOLOR_NORMAL() { echo -en '\033[0;39m'; }
24
25 check_root() {
26 if (( $EUID != 0 )); then
27 SETCOLOR_FAILURE; echo "Tests must be run as root! Please use 'sudo'."; SETCOLOR_NORMAL
28 exit 1
29 fi
30 }
31
32 while (($# > 0)); do
33 case $1 in
34 --run)
35 check_root
36 echo "TEST RUN: $TEST_DESCRIPTION"
37 test_check && test_run
38 exit $?;;
39 --setup)
40 check_root
41 echo "TEST SETUP: $TEST_DESCRIPTION"
42 test_check && test_setup
43 exit $?;;
44 --clean)
45 echo "TEST CLEANUP: $TEST_DESCRIPTION"
46 test_cleanup
47 rm -fr -- "$TESTDIR"
48 rm -f -- .testdir
49 exit $?;;
50 --all)
51 check_root
52 echo -n "TEST: $TEST_DESCRIPTION ";
53 if ! test_check 2&>test.log ; then
54 SETCOLOR_WARNING
55 echo "[SKIPPED]"
56 SETCOLOR_NORMAL
57 exit 0;
58 fi
59 if [ "$V" != "1" ]; then
60 (
61 test_setup && test_run
62 ret=$?
63 test_cleanup
64 rm -fr -- "$TESTDIR"
65 rm -f -- .testdir
66 exit $ret
67 ) </dev/null >test.log 2>&1
68 else
69 set -o pipefail
70 (
71 test_setup && test_run
72 ret=$?
73 test_cleanup
74 rm -fr -- "$TESTDIR"
75 rm -f -- .testdir
76 exit $ret
77 ) </dev/null 2>&1 | tee test.log
78 fi
79 ret=$?
80 set +o pipefail
81 if [ $ret -eq 0 ]; then
82 rm -- test.log
83 SETCOLOR_SUCCESS
84 echo "[OK]"
85 SETCOLOR_NORMAL
86 else
87 SETCOLOR_FAILURE
88 echo "[FAILED]"
89 SETCOLOR_NORMAL
90 echo "see $(pwd)/test.log"
91 fi
92 exit $ret;;
93 *) break ;;
94 esac
95 shift
96 done