Skip to content

Commit 14ace95

Browse files
authored
Merge branch 'main' into revert-458-test/skip-init-for-nixos
2 parents fd8b27f + 1355b59 commit 14ace95

15 files changed

+89
-17
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Add support for `.bash` test files
6+
37
## [0.22.3](https://github.com/TypedDevs/bashunit/compare/0.22.2...0.22.3) - 2025-07-27
48

59
- Fix NixOS support

docs/command-line.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
99
Specifies the `directory` or `file` containing the tests to be run.
1010

11-
If a directory is specified, it will execute tests within files ending in `test.sh`.
11+
If a directory is specified, it will execute tests within files ending in `test.sh` or `test.bash`.
1212

1313
If you use wildcards, **bashunit** will run any tests it finds.
1414

docs/test-files.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ In this section, you'll find information about these features along with some he
77

88
**bashunit** is flexible about how you name your test files.
99

10-
You can use a directory name, and bashunit will look for all files (ending with `test.sh`) recursively inside that directory, and execute them.
10+
You can use a directory name, and bashunit will look for all files (ending with `test.sh` or `test.bash`) recursively inside that directory, and execute them.
1111

1212
If you're using wildcards for scanning your tests, keep in mind that the initial search can slow down if you don't filter the test files in the wildcard.
1313

14-
To optimize this, we recommend adding a `test` prefix or suffix to your test file names, and include this identifier in your wildcard pattern too (e.g., `**/*test.sh`).
14+
To optimize this, we recommend adding a `test` prefix or suffix to your test file names, and include this identifier in your wildcard pattern too (e.g., `**/*test.sh` or `**/*test.bash`).
1515
This naming convention not only speeds up the scanning process but also helps you keep your test files organized.
1616

1717
This is useful regardless of whether your test files are located near your production code or share directories with your mocks, stubs, or fixtures.

src/console_header.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Usage:
6161
6262
Arguments:
6363
PATH File or directory containing tests.
64-
- Directories: runs all '*test.sh' files.
64+
- Directories: runs all '*test.sh' or '*test.bash' files.
6565
- Wildcards: supported to match multiple test files.
6666
- Default search path is 'tests'
6767

src/helpers.sh

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,23 @@ function helper::find_files_recursive() {
127127
local path="${1%%/}"
128128
local pattern="${2:-*[tT]est.sh}"
129129

130+
local alt_pattern=""
131+
if [[ $pattern == *test.sh ]] || [[ $pattern =~ \[tT\]est\.sh$ ]]; then
132+
alt_pattern="${pattern%.sh}.bash"
133+
fi
134+
130135
if [[ "$path" == *"*"* ]]; then
131-
eval find "$path" -type f -name "$pattern" | sort -u
136+
if [[ -n $alt_pattern ]]; then
137+
eval "find $path -type f \( -name \"$pattern\" -o -name \"$alt_pattern\" \)" | sort -u
138+
else
139+
eval "find $path -type f -name \"$pattern\"" | sort -u
140+
fi
132141
elif [[ -d "$path" ]]; then
133-
find "$path" -type f -name "$pattern" | sort -u
142+
if [[ -n $alt_pattern ]]; then
143+
find "$path" -type f \( -name "$pattern" -o -name "$alt_pattern" \) | sort -u
144+
else
145+
find "$path" -type f -name "$pattern" | sort -u
146+
fi
134147
else
135148
echo "$path"
136149
fi
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
3+
function test_assert_same() {
4+
assert_same 1 1
5+
}
6+
7+
function test_assert_contains() {
8+
assert_contains "foo" "foobar"
9+
assert_contains "bar" "foobar"
10+
}

tests/acceptance/snapshots/bashunit_find_tests_command_line_test_sh.test_all_tests_files_with_wildcard.snapshot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
✓ Passed: Assert greater and less than
33
✓ Passed: Assert empty
44

5+
Running ./tests/acceptance/fixtures/tests_path/bash_test.bash
6+
✓ Passed: Assert same
7+
✓ Passed: Assert contains
8+
59
Running ./tests/acceptance/fixtures/tests_path/other_test.sh
610
✓ Passed: Assert same
711
✓ Passed: Assert contains
812

9-
Tests:  4 passed, 4 total
10-
Assertions: 6 passed, 6 total
13+
Tests:  6 passed, 6 total
14+
Assertions: 9 passed, 9 total
1115

1216
 All tests passed 

tests/acceptance/snapshots/bashunit_find_tests_command_line_test_sh.test_all_tests_files_within_a_directory.snapshot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
✓ Passed: Assert greater and less than
33
✓ Passed: Assert empty
44

5+
Running ./tests/acceptance/fixtures/tests_path/bash_test.bash
6+
✓ Passed: Assert same
7+
✓ Passed: Assert contains
8+
59
Running ./tests/acceptance/fixtures/tests_path/other_test.sh
610
✓ Passed: Assert same
711
✓ Passed: Assert contains
812

9-
Tests:  4 passed, 4 total
10-
Assertions: 6 passed, 6 total
13+
Tests:  6 passed, 6 total
14+
Assertions: 9 passed, 9 total
1115

1216
 All tests passed 

tests/acceptance/snapshots/bashunit_path_test_sh.test_bashunit_with_argument_path.snapshot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
✓ Passed: Assert greater and less than
33
✓ Passed: Assert empty
44

5+
Running tests/acceptance/fixtures/tests_path/bash_test.bash
6+
✓ Passed: Assert same
7+
✓ Passed: Assert contains
8+
59
Running tests/acceptance/fixtures/tests_path/other_test.sh
610
✓ Passed: Assert same
711
✓ Passed: Assert contains
812

9-
Tests:  4 passed, 4 total
10-
Assertions: 6 passed, 6 total
13+
Tests:  6 passed, 6 total
14+
Assertions: 9 passed, 9 total
1115

1216
 All tests passed 

tests/acceptance/snapshots/bashunit_path_test_sh.test_bashunit_with_env_default_path.snapshot

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
✓ Passed: Assert greater and less than
33
✓ Passed: Assert empty
44

5+
Running tests/acceptance/fixtures/tests_path/bash_test.bash
6+
✓ Passed: Assert same
7+
✓ Passed: Assert contains
8+
59
Running tests/acceptance/fixtures/tests_path/other_test.sh
610
✓ Passed: Assert same
711
✓ Passed: Assert contains
812

9-
Tests:  4 passed, 4 total
10-
Assertions: 6 passed, 6 total
13+
Tests:  6 passed, 6 total
14+
Assertions: 9 passed, 9 total
1115

1216
 All tests passed 

0 commit comments

Comments
 (0)