|
2 | 2 | set -euo pipefail |
3 | 3 |
|
4 | 4 | function set_up_before_script() { |
5 | | - TEST_ENV_FILE="tests/acceptance/fixtures/.env.default" |
| 5 | + TEST_ENV_FILE="tests/acceptance/fixtures/.env.default" |
6 | 6 | } |
7 | 7 |
|
8 | 8 | function strip_ansi() { |
9 | | - sed -E 's/\x1B\[[0-9;]*[A-Za-z]//g' |
| 9 | + sed -E 's/\x1B\[[0-9;]*[A-Za-z]//g' |
10 | 10 | } |
11 | 11 |
|
12 | 12 | function test_bashunit_when_set_up_errors() { |
13 | | - local test_file=./tests/acceptance/fixtures/test_bashunit_when_setup_errors.sh |
14 | | - local fixture=$test_file |
15 | | - |
16 | | - local header_line="Running $fixture" |
17 | | - local error_line="✗ Error: Set up" |
18 | | - local message_line=" $fixture: line 4: invalid_function_name: command not found" |
19 | | - local tests_summary="Tests: 1 failed, 1 total" |
20 | | - local assertions_summary="Assertions: 0 failed, 0 total" |
21 | | - |
22 | | - local actual_raw |
23 | | - set +e |
24 | | - actual_raw="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")" |
25 | | - set -e |
26 | | - |
27 | | - local actual |
28 | | - actual="$(printf "%s" "$actual_raw" | strip_ansi)" |
29 | | - |
30 | | - assert_contains "$header_line" "$actual" |
31 | | - assert_contains "$error_line" "$actual" |
32 | | - assert_contains "$message_line" "$actual" |
33 | | - assert_contains "$tests_summary" "$actual" |
34 | | - assert_contains "$assertions_summary" "$actual" |
35 | | - assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")" |
| 13 | + local test_file=./tests/acceptance/fixtures/test_bashunit_when_setup_errors.sh |
| 14 | + local fixture=$test_file |
| 15 | + |
| 16 | + local header_line="Running $fixture" |
| 17 | + local error_line="✗ Error: Set up" |
| 18 | + local message_line=" $fixture: line 4: invalid_function_name: command not found" |
| 19 | + local tests_summary="Tests: 1 failed, 1 total" |
| 20 | + local assertions_summary="Assertions: 0 failed, 0 total" |
| 21 | + |
| 22 | + local actual_raw |
| 23 | + set +e |
| 24 | + actual_raw="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")" |
| 25 | + set -e |
| 26 | + |
| 27 | + local actual |
| 28 | + actual="$(printf "%s" "$actual_raw" | strip_ansi)" |
| 29 | + |
| 30 | + assert_contains "$header_line" "$actual" |
| 31 | + assert_contains "$error_line" "$actual" |
| 32 | + assert_contains "$message_line" "$actual" |
| 33 | + assert_contains "$tests_summary" "$actual" |
| 34 | + assert_contains "$assertions_summary" "$actual" |
| 35 | + assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")" |
36 | 36 | } |
37 | 37 |
|
38 | 38 | function test_bashunit_when_set_up_with_failing_command() { |
39 | | - local test_file=./tests/acceptance/fixtures/test_bashunit_when_setup_with_failing_command.sh |
40 | | - local fixture=$test_file |
41 | | - |
42 | | - local header_line="Running $fixture" |
43 | | - local error_line="✗ Error: Set up" |
44 | | - local message_line=" Hook 'set_up' failed with exit code 1" |
45 | | - local tests_summary="Tests: 1 failed, 1 total" |
46 | | - local assertions_summary="Assertions: 0 failed, 0 total" |
47 | | - |
48 | | - local actual_raw |
49 | | - set +e |
50 | | - actual_raw="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")" |
51 | | - set -e |
52 | | - |
53 | | - local actual |
54 | | - actual="$(printf "%s" "$actual_raw" | strip_ansi)" |
55 | | - |
56 | | - assert_contains "$header_line" "$actual" |
57 | | - assert_contains "$error_line" "$actual" |
58 | | - assert_contains "$message_line" "$actual" |
59 | | - assert_contains "$tests_summary" "$actual" |
60 | | - assert_contains "$assertions_summary" "$actual" |
61 | | - assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")" |
| 39 | + local test_file=./tests/acceptance/fixtures/test_bashunit_when_setup_with_failing_command.sh |
| 40 | + local fixture=$test_file |
| 41 | + |
| 42 | + local header_line="Running $fixture" |
| 43 | + local error_line="✗ Error: Set up" |
| 44 | + local message_line=" Hook 'set_up' failed with exit code 1" |
| 45 | + local tests_summary="Tests: 1 failed, 1 total" |
| 46 | + local assertions_summary="Assertions: 0 failed, 0 total" |
| 47 | + |
| 48 | + local actual_raw |
| 49 | + set +e |
| 50 | + actual_raw="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")" |
| 51 | + set -e |
| 52 | + |
| 53 | + local actual |
| 54 | + actual="$(printf "%s" "$actual_raw" | strip_ansi)" |
| 55 | + |
| 56 | + assert_contains "$header_line" "$actual" |
| 57 | + assert_contains "$error_line" "$actual" |
| 58 | + assert_contains "$message_line" "$actual" |
| 59 | + assert_contains "$tests_summary" "$actual" |
| 60 | + assert_contains "$assertions_summary" "$actual" |
| 61 | + assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")" |
62 | 62 | } |
63 | 63 |
|
64 | 64 | function test_bashunit_when_set_up_with_intermediate_failing_command() { |
65 | | - local test_file=./tests/acceptance/fixtures/test_bashunit_when_setup_with_intermediate_failing_command.sh |
66 | | - local fixture=$test_file |
67 | | - |
68 | | - local header_line="Running $fixture" |
69 | | - local error_line="✗ Error: Set up" |
70 | | - local message_line=" Hook 'set_up' failed with exit code 1" |
71 | | - local tests_summary="Tests: 1 failed, 1 total" |
72 | | - local assertions_summary="Assertions: 0 failed, 0 total" |
73 | | - |
74 | | - local actual_raw |
75 | | - set +e |
76 | | - actual_raw="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")" |
77 | | - set -e |
78 | | - |
79 | | - local actual |
80 | | - actual="$(printf "%s" "$actual_raw" | strip_ansi)" |
81 | | - |
82 | | - assert_contains "$header_line" "$actual" |
83 | | - assert_contains "$error_line" "$actual" |
84 | | - assert_contains "$message_line" "$actual" |
85 | | - assert_contains "$tests_summary" "$actual" |
86 | | - assert_contains "$assertions_summary" "$actual" |
87 | | - assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")" |
| 65 | + local test_file=./tests/acceptance/fixtures/test_bashunit_when_setup_with_intermediate_failing_command.sh |
| 66 | + local fixture=$test_file |
| 67 | + |
| 68 | + local header_line="Running $fixture" |
| 69 | + local error_line="✗ Error: Set up" |
| 70 | + local message_line=" Hook 'set_up' failed with exit code 1" |
| 71 | + local tests_summary="Tests: 1 failed, 1 total" |
| 72 | + local assertions_summary="Assertions: 0 failed, 0 total" |
| 73 | + |
| 74 | + local actual_raw |
| 75 | + set +e |
| 76 | + actual_raw="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")" |
| 77 | + set -e |
| 78 | + |
| 79 | + local actual |
| 80 | + actual="$(printf "%s" "$actual_raw" | strip_ansi)" |
| 81 | + |
| 82 | + assert_contains "$header_line" "$actual" |
| 83 | + assert_contains "$error_line" "$actual" |
| 84 | + assert_contains "$message_line" "$actual" |
| 85 | + assert_contains "$tests_summary" "$actual" |
| 86 | + assert_contains "$assertions_summary" "$actual" |
| 87 | + assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")" |
88 | 88 | } |
89 | 89 |
|
90 | 90 | # Issue #517: When set_up fails, remaining commands should not execute |
91 | 91 | function test_bashunit_set_up_stops_on_first_failure() { |
92 | | - local test_file=./tests/acceptance/fixtures/test_bashunit_setup_stops_on_failure.sh |
93 | | - local marker_file="/tmp/bashunit_setup_marker_test" |
| 92 | + local test_file=./tests/acceptance/fixtures/test_bashunit_setup_stops_on_failure.sh |
| 93 | + local marker_file="/tmp/bashunit_setup_marker_test" |
94 | 94 |
|
95 | | - # Clean up any existing marker file |
96 | | - rm -f "$marker_file" |
| 95 | + # Clean up any existing marker file |
| 96 | + rm -f "$marker_file" |
97 | 97 |
|
98 | | - set +e |
99 | | - ./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" >/dev/null 2>&1 |
100 | | - set -e |
| 98 | + set +e |
| 99 | + ./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file" >/dev/null 2>&1 |
| 100 | + set -e |
101 | 101 |
|
102 | | - # The marker file should NOT exist because the touch command |
103 | | - # should not have executed after the failing command |
104 | | - assert_file_not_exists "$marker_file" |
| 102 | + # The marker file should NOT exist because the touch command |
| 103 | + # should not have executed after the failing command |
| 104 | + assert_file_not_exists "$marker_file" |
105 | 105 |
|
106 | | - # Clean up |
107 | | - rm -f "$marker_file" |
| 106 | + # Clean up |
| 107 | + rm -f "$marker_file" |
| 108 | +} |
| 109 | + |
| 110 | +# Issue #611: Sourcing a non-existent file in set_up should fail the test |
| 111 | +function test_bashunit_when_set_up_sources_nonexistent_file() { |
| 112 | + local test_file=./tests/acceptance/fixtures/test_bashunit_when_setup_sources_nonexistent_file.sh |
| 113 | + local fixture=$test_file |
| 114 | + |
| 115 | + local error_line="✗ Error: Set up" |
| 116 | + local tests_summary="Tests: 1 failed, 1 total" |
| 117 | + local assertions_summary="Assertions: 0 failed, 0 total" |
| 118 | + |
| 119 | + local actual_raw |
| 120 | + set +e |
| 121 | + actual_raw="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")" |
| 122 | + set -e |
| 123 | + |
| 124 | + local actual |
| 125 | + actual="$(printf "%s" "$actual_raw" | strip_ansi)" |
| 126 | + |
| 127 | + assert_contains "$error_line" "$actual" |
| 128 | + assert_contains "$tests_summary" "$actual" |
| 129 | + assert_contains "$assertions_summary" "$actual" |
| 130 | + assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE" "$test_file")" |
108 | 131 | } |
0 commit comments