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