Debian Codegraph @

test/basic

raw
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 test_description='the test framework itself'
7
8 . lib/test-lib.sh
9
10 ################################################################
11
12 test_expect_success 'success is reported like this' '
13 :
14 '
15 test_set_prereq HAVEIT
16 haveit=no
17 test_expect_success HAVEIT 'test runs if prerequisite is satisfied' '
18 test_have_prereq HAVEIT &&
19 haveit=yes
20 '
21
22 clean=no
23 test_expect_success 'tests clean up after themselves' '
24 test_when_finished clean=yes
25 '
26
27 cleaner=no
28 test_expect_code 1 'tests clean up even after a failure' '
29 test_when_finished cleaner=yes &&
30 (exit 1)
31 '
32
33 if test $clean$cleaner != yesyes
34 then
35 say "bug in test framework: cleanup commands do not work reliably"
36 exit 1
37 fi
38
39 test_expect_code 2 'failure to clean up causes the test to fail' '
40 test_when_finished "(exit 2)"
41 '
42
43 # Ensure that all tests are being run
44 test_begin_subtest 'Ensure that all available tests will be run'
45 eval $(sed -n -e '/^TESTS="$/,/^"$/p' $TEST_DIRECTORY/impass-test)
46 tests_in_suite=$(for i in $TESTS $TESTS_NET; do echo $i; done | sort)
47 available=$(find "$TEST_DIRECTORY" -maxdepth 1 -type f -perm /111 \
48 ! -name '*~' \
49 ! -name 'lib/*' \
50 ! -name test-verbose \
51 ! -name impass-test \
52 | sed 's,.*/,,' | sort)
53 test_expect_equal "$tests_in_suite" "$available"
54
55 EXPECTED=$TEST_DIRECTORY/lib/test.expected-output
56 suppress_diff_date() {
57 sed -e 's/\(.*\-\-\- test-verbose\.4\.\expected\).*/\1/' \
58 -e 's/\(.*\+\+\+ test-verbose\.4\.\output\).*/\1/'
59 }
60
61 test_begin_subtest "Ensure that test output is suppressed unless the test fails"
62 output=$(cd $TEST_DIRECTORY; ./test-verbose 2>&1 | suppress_diff_date)
63 expected=$(cat $EXPECTED/test-verbose-no | suppress_diff_date)
64 test_expect_equal "$output" "$expected"
65
66 test_begin_subtest "Ensure that -v does not suppress test output"
67 output=$(cd $TEST_DIRECTORY; ./test-verbose -v 2>&1 | suppress_diff_date)
68 expected=$(cat $EXPECTED/test-verbose-yes | suppress_diff_date)
69 # Do not include the results of test-verbose in totals
70 rm $TEST_DIRECTORY/test-results/test-verbose-*
71 rm -r $TEST_DIRECTORY/tmp.test-verbose
72 test_expect_equal "$output" "$expected"
73
74 test_begin_subtest "Ensure that we're looking at the correct library"
75 output=$(python3 -c 'import impass; print(impass.__file__)')
76 expected="${SRC_DIRECTORY}/impass/__init__.py"
77 test_expect_equal "$output" "$expected"
78
79 ################################################################
80
81 test_done