Skip to content

Commit 155e694

Browse files
committed
feat: add logs on dev_mode
1 parent 0f452a8 commit 155e694

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

bashunit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ declare -r BASHUNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
99
export BASHUNIT_ROOT_DIR
1010

1111
source "$BASHUNIT_ROOT_DIR/src/dev/debug.sh"
12+
source "$BASHUNIT_ROOT_DIR/src/check_os.sh"
1213
source "$BASHUNIT_ROOT_DIR/src/str.sh"
1314
source "$BASHUNIT_ROOT_DIR/src/globals.sh"
1415
source "$BASHUNIT_ROOT_DIR/src/dependencies.sh"
1516
source "$BASHUNIT_ROOT_DIR/src/io.sh"
1617
source "$BASHUNIT_ROOT_DIR/src/math.sh"
1718
source "$BASHUNIT_ROOT_DIR/src/parallel.sh"
1819
source "$BASHUNIT_ROOT_DIR/src/env.sh"
19-
source "$BASHUNIT_ROOT_DIR/src/check_os.sh"
2020
source "$BASHUNIT_ROOT_DIR/src/clock.sh"
2121
source "$BASHUNIT_ROOT_DIR/src/state.sh"
2222
source "$BASHUNIT_ROOT_DIR/src/colors.sh"

src/env.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ function env::find_terminal_width() {
7979
echo "${cols:-$_DEFAULT_TERMINAL_WIDTH}"
8080
}
8181

82-
TEMP_DIR_PARALLEL_TEST_SUITE="/tmp/bashunit/parallel"
82+
TEMP_DIR_PARALLEL_TEST_SUITE="/tmp/bashunit/parallel/${_OS:-Unknown}"
8383
TERMINAL_WIDTH="$(env::find_terminal_width)"
8484
FAILURES_OUTPUT_PATH=$(mktemp)
8585
CAT="$(which cat)"

src/runner.sh

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,6 @@ function runner::run_test() {
158158
# Closes FD 3, which was used temporarily to hold the original stdout.
159159
exec 3>&-
160160

161-
runner::parse_result "$function_name" "$test_execution_result" "$@"
162-
163161
local subshell_output=$(\
164162
echo "$test_execution_result" |\
165163
tail -n 1 |\
@@ -185,13 +183,15 @@ function runner::run_test() {
185183
"division by 0" "cannot allocate memory" "bad file descriptor" \
186184
"segmentation fault" "illegal option" "argument list too long" \
187185
"readonly variable" "missing keyword" "killed" \
188-
"cannot execute binary file"; do
186+
"cannot execute binary file" "invalid arithmetic operator"; do
189187
if [[ "$runtime_output" == *"$error"* ]]; then
190188
runtime_error=$(echo "${runtime_output#*: }" | tr -d '\n')
191189
break
192190
fi
193191
done
194192

193+
runner::parse_result "$function_name" "$test_execution_result" "$@"
194+
195195
local total_assertions="$(state::calculate_total_assertions "$test_execution_result")"
196196

197197
local end_time=$(clock::now)
@@ -282,6 +282,15 @@ function runner::parse_result_parallel() {
282282
count=$((count + 1))
283283
done
284284

285+
if env::is_dev_mode_enabled; then
286+
local test_id=$(\
287+
echo "$execution_result" |\
288+
tail -n 1 |\
289+
sed -E -e 's/.*##TEST_ID=([a-zA-Z0-9]*)##.*/\1/g'\
290+
)
291+
log "debug" "[PARA] test_id:$test_id" "function_name:$function_name" "execution_result:$execution_result"
292+
fi
293+
285294
echo "$execution_result" > "$unique_test_result_file"
286295
}
287296

@@ -324,9 +333,9 @@ function runner::parse_result_sync() {
324333
local test_id=$(\
325334
echo "$execution_result" |\
326335
tail -n 1 |\
327-
sed -E -e 's/.*##TEST_ID=([0-9]*)##.*/\1/g'\
336+
sed -E -e 's/.*##TEST_ID=([a-zA-Z0-9]*)##.*/\1/g'\
328337
)
329-
log "$test_id" "$function_name" "$execution_result"
338+
log "debug" "[SYNC] test_id:$test_id" "function_name:$function_name" "execution_result:$execution_result"
330339
fi
331340

332341
((_ASSERTIONS_PASSED += assertions_passed)) || true

src/state.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function state::export_subshell_context() {
148148
encoded_test_output=$(echo -n "$_TEST_OUTPUT" | base64)
149149
fi
150150

151-
echo "##TEST_ID=$(random_str)\
151+
echo "##TEST_ID=$(LC_ALL=C tr -dc A-Za-z0-9 </dev/urandom | head -c 8)\
152152
##ASSERTIONS_FAILED=$_ASSERTIONS_FAILED\
153153
##ASSERTIONS_PASSED=$_ASSERTIONS_PASSED\
154154
##ASSERTIONS_SKIPPED=$_ASSERTIONS_SKIPPED\
@@ -196,7 +196,7 @@ function state::print_line() {
196196
incomplete) char="${_COLOR_INCOMPLETE}I${_COLOR_DEFAULT}" ;;
197197
snapshot) char="${_COLOR_SNAPSHOT}N${_COLOR_DEFAULT}" ;;
198198
error) char="${_COLOR_FAILED}E${_COLOR_DEFAULT}" ;;
199-
*) char="?" ;;
199+
*) char="?" && log "warning" "unknown test type '$type'" ;;
200200
esac
201201

202202
if env::is_parallel_run_enabled; then

tests/unit/state_test.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ function test_set_duplicated_functions_merged() {
234234
}
235235

236236
function test_initialize_assertions_count() {
237-
mock random_str echo "abc123"
237+
mock tr echo "abc123"
238238

239239
local export_assertions_count
240240
export_assertions_count=$(
@@ -261,7 +261,7 @@ function test_initialize_assertions_count() {
261261
}
262262

263263
function test_export_assertions_count() {
264-
mock random_str echo "abc123"
264+
mock tr echo "abc123"
265265

266266
local export_assertions_count
267267
export_assertions_count=$(

0 commit comments

Comments
 (0)