Skip to content

Commit d35cbf7

Browse files
committed
feat: feature flag enable parallel only macos and ubuntu
1 parent 61dc052 commit d35cbf7

File tree

6 files changed

+27
-19
lines changed

6 files changed

+27
-19
lines changed

.github/workflows/tests.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
jobs:
1010

1111
simple-output:
12-
name: "On ${{ matrix.os }} - simple & sync"
12+
name: "${{ matrix.os }} - simple & sync"
1313
timeout-minutes: 10
1414
runs-on: ${{ matrix.os }}
1515
strategy:
@@ -28,7 +28,7 @@ jobs:
2828
./bashunit --simple --no-parallel tests/
2929
3030
simple-output-parallel:
31-
name: "On ${{ matrix.os }} - simple & parallel"
31+
name: "${{ matrix.os }} - simple & parallel"
3232
timeout-minutes: 10
3333
runs-on: ${{ matrix.os }}
3434
strategy:
@@ -47,7 +47,7 @@ jobs:
4747
./bashunit --simple --parallel tests/
4848
4949
detailed-output-parallel:
50-
name: "On ${{ matrix.os }} - detailed & parallel"
50+
name: "${{ matrix.os }} - detailed & parallel"
5151
timeout-minutes: 10
5252
runs-on: ${{ matrix.os }}
5353
strategy:
@@ -66,7 +66,7 @@ jobs:
6666
./bashunit --detailed --parallel tests/
6767
6868
windows:
69-
name: "On windows (${{ matrix.test_chunk }})"
69+
name: "windows (${{ matrix.test_chunk }})"
7070
timeout-minutes: 10
7171
runs-on: windows-latest
7272
strategy:
@@ -85,7 +85,7 @@ jobs:
8585
./bashunit tests/${{ matrix.test_chunk }}/*_test.sh
8686
8787
alpine:
88-
name: "On alpine-latest"
88+
name: "alpine-latest"
8989
runs-on: ubuntu-latest
9090
steps:
9191
- name: Checkout

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased](https://github.com/TypedDevs/bashunit/compare/0.17.0...main)
44

55
- Added `-p|--parallel` to enable running tests in parallel
6+
- Enabled only in macOS and Ubuntu
67
- Added `assert_file_contains` and `assert_file_not_contains`
78
- Added `assert_true` and `assert_false`
89
- Added `BASHUNIT_DEV_LOG`

src/main.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,25 @@ function main::exec_tests() {
1919
trap 'main::cleanup' SIGINT
2020
trap '[[ $? -eq $EXIT_CODE_STOP_ON_FAILURE ]] && main::handle_stop_on_failure_sync' EXIT
2121

22-
if env::is_parallel_run_enabled && check_os::is_alpine; then
23-
printf "%sWarning: Parallel test execution on Alpine Linux is currently" "${_COLOR_INCOMPLETE}"
24-
printf "in a beta stage.\nThis means there may be unresolved issues, "
25-
printf "particularly involving race conditions.%s\n" "${_COLOR_DEFAULT}"
22+
if env::is_parallel_run_enabled && ! parallel::is_enabled; then
23+
printf "%sWarning: Parallel tests are working only for macOS and Ubuntu.\n" "${_COLOR_INCOMPLETE}"
24+
printf "For other OS (Linux/Alpine, Windows), --parallel is not enabled due to inconsistent results,\n"
25+
printf "particularly involving race conditions.%s " "${_COLOR_DEFAULT}"
26+
printf "%sFallback using --no-parallel%s\n" "${_COLOR_SKIPPED}" "${_COLOR_DEFAULT}"
2627
fi
2728

28-
if env::is_parallel_run_enabled; then
29+
if parallel::is_enabled; then
2930
parallel::reset
3031
fi
3132

3233
console_header::print_version_with_env "$filter" "${test_files[@]}"
3334
runner::load_test_files "$filter" "${test_files[@]}"
34-
if env::is_parallel_run_enabled; then
35+
36+
if parallel::is_enabled; then
3537
wait
3638
fi
3739

38-
if env::is_parallel_run_enabled && parallel::must_stop_on_failure; then
40+
if parallel::is_enabled && parallel::must_stop_on_failure; then
3941
printf "\r%sStop on failure enabled...%s\n" "${_COLOR_SKIPPED}" "${_COLOR_DEFAULT}"
4042
fi
4143

src/parallel.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,8 @@ function parallel::reset() {
8383
rm -rf "$TEMP_DIR_PARALLEL_TEST_SUITE"
8484
[ -f "$TEMP_FILE_PARALLEL_STOP_ON_FAILURE" ] && rm "$TEMP_FILE_PARALLEL_STOP_ON_FAILURE"
8585
}
86+
87+
function parallel::is_enabled() {
88+
[[ $(env::is_parallel_run_enabled) \
89+
&& ($(check_os::is_macos) || $(check_os::is_ubuntu)) ]]
90+
}

src/runner.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function runner::load_test_files() {
1313
# shellcheck source=/dev/null
1414
source "$test_file"
1515
runner::run_set_up_before_script
16-
if env::is_parallel_run_enabled; then
16+
if parallel::is_enabled; then
1717
runner::call_test_functions "$test_file" "$filter" 2>/dev/null &
1818
else
1919
runner::call_test_functions "$test_file" "$filter"
@@ -22,7 +22,7 @@ function runner::load_test_files() {
2222
runner::clean_set_up_and_tear_down_after_script
2323
done
2424

25-
if env::is_parallel_run_enabled; then
25+
if parallel::is_enabled; then
2626
wait
2727
runner::spinner &
2828
local spinner_pid=$!
@@ -74,14 +74,14 @@ function runner::call_test_functions() {
7474
return
7575
fi
7676

77-
if ! env::is_simple_output_enabled && ! env::is_parallel_run_enabled; then
77+
if ! env::is_simple_output_enabled && ! parallel::is_enabled; then
7878
echo "Running $script"
7979
fi
8080

8181
helper::check_duplicate_functions "$script" || true
8282

8383
for function_name in "${functions_to_run[@]}"; do
84-
if env::is_parallel_run_enabled && parallel::must_stop_on_failure; then
84+
if parallel::is_enabled && parallel::must_stop_on_failure; then
8585
break
8686
fi
8787

@@ -193,7 +193,7 @@ function runner::run_test() {
193193
runner::write_failure_result_output "$test_file" "$subshell_output"
194194

195195
if env::is_stop_on_failure_enabled; then
196-
if env::is_parallel_run_enabled; then
196+
if parallel::is_enabled; then
197197
parallel::mark_stop_on_failure
198198
else
199199
exit "$EXIT_CODE_STOP_ON_FAILURE"
@@ -249,7 +249,7 @@ function runner::parse_result() {
249249
shift
250250
local args=("$@")
251251

252-
if env::is_parallel_run_enabled; then
252+
if parallel::is_enabled; then
253253
runner::parse_result_parallel "$function_name" "$execution_result" "${args[@]}"
254254
else
255255
runner::parse_result_sync "$function_name" "$execution_result"

src/state.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function state::print_line() {
205205
*) char="?" && log "warning" "unknown test type '$type'" ;;
206206
esac
207207

208-
if env::is_parallel_run_enabled; then
208+
if parallel::is_enabled; then
209209
printf "%s" "$char"
210210
else
211211
if (( _TOTAL_TESTS_COUNT % 50 == 0 )); then

0 commit comments

Comments
 (0)