Skip to content

Commit 0139090

Browse files
committed
refactor: replace compgen with a safer globbing approach
1 parent fd4feaf commit 0139090

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Unreleased
44

5-
- Fix build issue with bashunit on NixOS
5+
- Fix parallel and `compgen` issue on NixOS
66

77
## [0.22.2](https://github.com/TypedDevs/bashunit/compare/0.22.1...0.22.2) - 2025-07-26
88

src/math.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#!/usr/bin/env bash
22

3-
if dependencies::has_bc; then
4-
# bc is better than awk because bc has no integer limits.
5-
function math::calculate() {
3+
function math::calculate() {
4+
if dependencies::has_bc; then
65
echo "$*" | bc
7-
}
8-
elif dependencies::has_awk; then
9-
function math::calculate() {
10-
awk "BEGIN { print ""$*"" }"
11-
}
12-
fi
6+
elif dependencies::has_awk; then
7+
awk "BEGIN { print ($*) }"
8+
else
9+
local result=$(( $* ))
10+
echo "$result"
11+
fi
12+
}

src/parallel.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ function parallel::aggregate_test_results() {
1212
local total_snapshot=0
1313

1414
for script_dir in "$temp_dir_parallel_test_suite"/*; do
15-
if ! compgen -G "$script_dir"/*.result > /dev/null; then
15+
shopt -s nullglob
16+
local result_files=("$script_dir"/*.result)
17+
shopt -u nullglob
18+
19+
if [ ${#result_files[@]} -eq 0 ]; then
1620
printf "%sNo tests found%s" "$_COLOR_SKIPPED" "$_COLOR_DEFAULT"
1721
continue
1822
fi
1923

20-
for result_file in "$script_dir"/*.result; do
24+
for result_file in "${result_files[@]}"; do
2125
local result_line
2226
result_line=$(tail -n 1 "$result_file")
2327

0 commit comments

Comments
 (0)