Skip to content

Commit 91e523b

Browse files
committed
ref(test): split large acceptance test files for better parallel distribution
Split bashunit_assert_subcommand_test.sh (20 tests) into 3 files: - bashunit_assert_basic_test.sh (8 tests): basic assertions and help - bashunit_assert_errors_test.sh (6 tests): error cases and deprecation - bashunit_assert_multi_test.sh (6 tests): multi-assertion mode Split bashunit_direct_fn_call_test.sh (19 tests) into 2 files: - bashunit_direct_fn_call_basic_test.sh (11 tests): basic assertions - bashunit_direct_fn_call_advanced_test.sh (8 tests): exit codes and failures Split bashunit_lifecycle_output_test.sh (12 tests) into 2 files: - bashunit_lifecycle_verbose_test.sh (2 tests): verbose output behavior - bashunit_lifecycle_visibility_test.sh (4 tests): hook visibility modes Improves parallel execution by distributing 51 acceptance tests across more workers.
1 parent ad4c66d commit 91e523b

10 files changed

Lines changed: 334 additions & 299 deletions
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
function set_up() {
5+
export BASHUNIT_SIMPLE_OUTPUT=false
6+
}
7+
8+
# Test basic assert subcommand functionality
9+
function test_bashunit_assert_subcommand_equals() {
10+
./bashunit assert equals "foo" "foo"
11+
assert_successful_code
12+
}
13+
14+
function test_bashunit_assert_subcommand_same() {
15+
./bashunit assert same "1" "1"
16+
assert_successful_code
17+
}
18+
19+
function test_bashunit_assert_subcommand_contains() {
20+
./bashunit assert contains "world" "hello world"
21+
assert_successful_code
22+
}
23+
24+
function test_bashunit_assert_subcommand_without_prefix() {
25+
./bashunit assert equals "bar" "bar"
26+
assert_successful_code
27+
}
28+
29+
# Test help functionality
30+
function test_bashunit_assert_subcommand_help_short() {
31+
local output
32+
output=$(./bashunit assert -h 2>&1)
33+
34+
assert_contains "Usage: bashunit assert" "$output"
35+
assert_contains "Run standalone assertion" "$output"
36+
assert_successful_code "$(./bashunit assert -h)"
37+
}
38+
39+
function test_bashunit_assert_subcommand_help_long() {
40+
local output
41+
output=$(./bashunit assert --help 2>&1)
42+
43+
assert_contains "Usage: bashunit assert" "$output"
44+
assert_contains "Single assertion:" "$output"
45+
assert_successful_code "$(./bashunit assert --help)"
46+
}
47+
48+
# Test assert subcommand is in main help
49+
function test_bashunit_main_help_includes_assert() {
50+
local output
51+
output=$(./bashunit --help 2>&1)
52+
53+
assert_contains "assert <fn> <args>" "$output"
54+
}
55+
56+
function test_multi_assert_help_shows_multi_syntax() {
57+
local output
58+
output=$(./bashunit assert --help 2>&1)
59+
assert_contains "Multiple assertions on command output" "$output"
60+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
function set_up() {
5+
export BASHUNIT_SIMPLE_OUTPUT=false
6+
}
7+
8+
# Test error cases
9+
function test_bashunit_assert_subcommand_no_function() {
10+
local output
11+
local exit_code
12+
output=$(./bashunit assert 2>&1) && exit_code=$? || exit_code=$?
13+
14+
assert_contains "Error: Assert function name or command is required" "$output"
15+
assert_general_error "" "" "$exit_code"
16+
}
17+
18+
function test_bashunit_assert_subcommand_non_existing_function() {
19+
local exit_code
20+
./bashunit assert non_existing_function 2>&1 && exit_code=$? || exit_code=$?
21+
assert_command_not_found "" "" "$exit_code"
22+
}
23+
24+
function test_bashunit_assert_subcommand_failure() {
25+
local exit_code
26+
./bashunit --no-parallel assert equals "foo" "bar" 2>&1 && exit_code=$? || exit_code=$?
27+
assert_general_error "" "" "$exit_code"
28+
}
29+
30+
# Test backward compatibility with --assert option
31+
function test_bashunit_old_assert_option_still_works() {
32+
local output
33+
output=$(./bashunit -a equals "foo" "foo" 2>&1)
34+
assert_successful_code "$output"
35+
}
36+
37+
function test_bashunit_old_assert_option_long_form() {
38+
local output
39+
output=$(./bashunit --assert equals "foo" "foo" 2>&1)
40+
assert_successful_code "$output"
41+
}
42+
43+
# Test deprecation notice in help
44+
function test_bashunit_test_help_shows_deprecation() {
45+
local output
46+
output=$(./bashunit test --help 2>&1)
47+
48+
assert_contains "deprecated" "$output"
49+
assert_contains "bashunit assert" "$output"
50+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
function set_up() {
5+
export BASHUNIT_SIMPLE_OUTPUT=false
6+
}
7+
8+
# Test multi-assertion mode
9+
function test_multi_assert_exit_code_and_contains() {
10+
./bashunit assert "echo 'some error' && exit 1" exit_code "1" contains "some error" 2>&1
11+
assert_successful_code
12+
}
13+
14+
function test_multi_assert_exit_code_zero_and_output() {
15+
./bashunit assert "echo 'success message'" exit_code "0" contains "success" 2>&1
16+
assert_successful_code
17+
}
18+
19+
function test_multi_assert_multiple_output_assertions() {
20+
./bashunit assert "echo 'hello world'" exit_code "0" contains "hello" contains "world" 2>&1
21+
assert_successful_code
22+
}
23+
24+
function test_multi_assert_fails_on_exit_code_mismatch() {
25+
local exit_code
26+
./bashunit assert "echo 'output' && exit 1" exit_code "0" 2>&1 && exit_code=$? || exit_code=$?
27+
assert_general_error "" "" "$exit_code"
28+
}
29+
30+
function test_multi_assert_fails_on_contains_mismatch() {
31+
local exit_code
32+
./bashunit assert "echo 'actual output'" exit_code "0" contains "expected" 2>&1 && exit_code=$? || exit_code=$?
33+
assert_general_error "" "" "$exit_code"
34+
}
35+
36+
function test_multi_assert_missing_assertion_arg() {
37+
local exit_code
38+
local output
39+
output=$(./bashunit assert "echo test" exit_code 2>&1) && exit_code=$? || exit_code=$?
40+
assert_contains "Missing argument for assertion" "$output"
41+
assert_general_error "" "" "$exit_code"
42+
}

tests/acceptance/bashunit_assert_subcommand_test.sh

Lines changed: 0 additions & 140 deletions
This file was deleted.

tests/acceptance/bashunit_direct_fn_call_test.sh renamed to tests/acceptance/bashunit_direct_fn_call_advanced_test.sh

Lines changed: 0 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,77 +3,12 @@ set -euo pipefail
33

44
function set_up_before_script() {
55
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
6-
TEST_MULTILINE_STR="first line
7-
\n
8-
four line
9-
find me with \n a regular expression"
106
}
117

128
function set_up() {
139
export BASHUNIT_SIMPLE_OUTPUT=false
1410
}
1511

16-
function test_bashunit_direct_fn_call_passes() {
17-
local expected="foo"
18-
local actual="foo"
19-
20-
./bashunit -a assert_same --env "$TEST_ENV_FILE" "$expected" $actual
21-
assert_successful_code
22-
}
23-
24-
function test_bashunit_direct_fn_call_without_assert_prefix_passes() {
25-
local expected="foo"
26-
local actual="foo"
27-
28-
./bashunit -a equals --env "$TEST_ENV_FILE" "$expected" $actual
29-
assert_successful_code
30-
}
31-
32-
function test_bashunit_assert_line_count() {
33-
./bashunit -a line_count 6 "$TEST_MULTILINE_STR"
34-
assert_successful_code
35-
}
36-
37-
function test_bashunit_assert_contains() {
38-
./bashunit -a contains "four" "$TEST_MULTILINE_STR"
39-
assert_successful_code
40-
}
41-
42-
function test_bashunit_assert_not_contains() {
43-
./bashunit -a not_contains "unknown" "$TEST_MULTILINE_STR"
44-
assert_successful_code
45-
}
46-
47-
function test_bashunit_assert_matches() {
48-
./bashunit -a matches "with.+regular expr" "$TEST_MULTILINE_STR"
49-
assert_successful_code
50-
}
51-
52-
function test_bashunit_assert_not_matches() {
53-
./bashunit -a not_matches "unknown" "$TEST_MULTILINE_STR"
54-
assert_successful_code
55-
}
56-
57-
function test_bashunit_assert_string_starts_with() {
58-
./bashunit -a string_starts_with "first" "$TEST_MULTILINE_STR"
59-
assert_successful_code
60-
}
61-
62-
function test_bashunit_assert_string_not_starts_with() {
63-
./bashunit -a string_not_starts_with "unknown" "$TEST_MULTILINE_STR"
64-
assert_successful_code
65-
}
66-
67-
function test_bashunit_assert_string_ends_with() {
68-
./bashunit -a string_ends_with "expression" "$TEST_MULTILINE_STR"
69-
assert_successful_code
70-
}
71-
72-
function test_bashunit_assert_string_not_ends_with() {
73-
./bashunit -a string_not_ends_with "unknown" "$TEST_MULTILINE_STR"
74-
assert_successful_code
75-
}
76-
7712
function test_bashunit_direct_fn_call_failure() {
7813
local expected="foo"
7914
local actual="bar"

0 commit comments

Comments
 (0)