From 1e9fb838481eb5f380ae7c92e71a09712505c9fe Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Sat, 6 Dec 2025 15:29:30 +0100 Subject: [PATCH 1/3] feat!: namespace helper functions to prevent user code conflicts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: All helper functions now require bashunit:: prefix. Renamed functions: - skip → bashunit::skip - todo → bashunit::todo - fail → bashunit::fail - mock → bashunit::mock - unmock → bashunit::unmock - spy → bashunit::spy - temp_file → bashunit::temp_file - temp_dir → bashunit::temp_dir - data_set → bashunit::data_set - current_dir → bashunit::current_dir - current_filename → bashunit::current_filename - random_str → bashunit::random_str - log → bashunit::log - set_test_title → bashunit::set_test_title All assert_* functions remain unchanged. --- CHANGELOG.md | 16 +++ docs/assertions.md | 8 +- docs/common-patterns.md | 10 +- docs/custom-asserts.md | 6 +- docs/data-providers.md | 30 ++--- docs/globals.md | 28 ++--- docs/skipping-incomplete.md | 16 +-- docs/test-doubles.md | 40 +++---- src/assert.sh | 18 +-- src/benchmark.sh | 2 +- src/env.sh | 8 +- src/globals.sh | 38 +++---- src/helpers.sh | 2 +- src/main.sh | 12 +- src/parallel.sh | 6 +- src/runner.sh | 56 +++++----- src/skip_todo.sh | 4 +- src/state.sh | 2 +- src/test_doubles.sh | 10 +- src/test_title.sh | 2 +- .../bashunit_execution_error_test.sh | 4 +- tests/acceptance/bashunit_fail_test.sh | 4 +- tests/acceptance/bashunit_init_test.sh | 2 +- tests/acceptance/bashunit_pass_test.sh | 4 +- .../bashunit_stop_on_failure_test.sh | 2 +- tests/acceptance/bashunit_test.sh | 6 +- tests/acceptance/bashunit_upgrade_test.sh | 16 +-- .../fixtures/script_with_setup_temp_file.sh | 4 +- .../test_bashunit_when_report_html.sh | 4 +- ...st_bashunit_with_multiple_failing_tests.sh | 8 +- .../test_cd_in_setup_before_script_first.sh | 2 +- .../acceptance/fixtures/test_custom_title.sh | 2 +- .../fixtures/test_parallel_spy_file1.sh | 2 +- .../fixtures/test_parallel_spy_file2.sh | 2 +- tests/acceptance/install_test.sh | 26 ++--- tests/acceptance/mock_test.sh | 4 +- .../acceptance/parallel_spy_parallel_test.sh | 4 +- ...it_should_display_all_assert_docs.snapshot | 2 +- tests/bootstrap.sh | 60 +++++----- tests/functional/custom_asserts_test.sh | 2 +- tests/functional/doubles_test.sh | 28 ++--- tests/functional/logic_test.sh | 2 +- tests/functional/provider_test.sh | 20 ++-- tests/functional/provider_with_cd_test.sh | 2 +- tests/unit/assert_snapshot_test.sh | 12 +- tests/unit/assert_test.sh | 16 +-- tests/unit/check_os_test.sh | 46 ++++---- tests/unit/clock_test.sh | 104 +++++++++--------- tests/unit/console_results_test.sh | 18 +-- tests/unit/custom_assertions_test.sh | 2 +- tests/unit/dependencies_test.sh | 14 +-- tests/unit/directory_test.sh | 30 ++--- tests/unit/file_test.sh | 12 +- .../find_total_tests/provider_test.sh | 6 +- tests/unit/globals_test.sh | 48 ++++---- tests/unit/helpers_test.sh | 42 +++---- tests/unit/parallel_test.sh | 6 +- tests/unit/skip_todo_test.sh | 8 +- tests/unit/state_test.sh | 4 +- tests/unit/test_doubles_test.sh | 30 ++--- 60 files changed, 470 insertions(+), 454 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 081e8716..82da1c68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,22 @@ ### Changed - Build script now outputs to temp directory (`${TMPDIR}/bashunit/build`) by default instead of `bin/` - Add `--cleanup` flag to build script to remove build artifacts after completion +- **BREAKING:** Namespace all helper functions to avoid conflicts with user code (fixes #538) + - `skip` → `bashunit::skip` + - `todo` → `bashunit::todo` + - `fail` → `bashunit::fail` + - `mock` → `bashunit::mock` + - `unmock` → `bashunit::unmock` + - `spy` → `bashunit::spy` + - `temp_file` → `bashunit::temp_file` + - `temp_dir` → `bashunit::temp_dir` + - `data_set` → `bashunit::data_set` + - `current_dir` → `bashunit::current_dir` + - `current_filename` → `bashunit::current_filename` + - `random_str` → `bashunit::random_str` + - `log` → `bashunit::log` + - `set_test_title` → `bashunit::set_test_title` + - All `assert_*` functions remain unchanged ### Fixed - Custom assertions now display the correct test function name in failure messages diff --git a/docs/assertions.md b/docs/assertions.md index 9aca937e..e43ca443 100644 --- a/docs/assertions.md +++ b/docs/assertions.md @@ -1140,8 +1140,8 @@ function test_failure() { ``` ::: -## fail -> `fail "failure message"` +## bashunit::fail +> `bashunit::fail "failure message"` Unambiguously reports an error message. Useful for reporting specific message when testing situations not covered by any `assert_*` functions. @@ -1150,12 +1150,12 @@ when testing situations not covered by any `assert_*` functions. ```bash [Example] function test_success() { if [ "$(date +%-H)" -gt 25 ]; then - fail "Something is very wrong with your clock" + bashunit::fail "Something is very wrong with your clock" fi } function test_failure() { if [ "$(date +%-H)" -lt 25 ]; then - fail "This test will always fail" + bashunit::fail "This test will always fail" fi } ``` diff --git a/docs/common-patterns.md b/docs/common-patterns.md index affce71c..4eb134f2 100644 --- a/docs/common-patterns.md +++ b/docs/common-patterns.md @@ -414,7 +414,7 @@ function set_up() { } function test_get_current_branch() { - mock git echo "feature/new-feature" + bashunit::mock git echo "feature/new-feature" local branch branch=$(get_current_branch) @@ -423,7 +423,7 @@ function test_get_current_branch() { } function test_check_for_changes() { - mock git < /dev/null 2>&1; then - fail "Invalid JSON: $json" + bashunit::fail "Invalid JSON: $json" return fi @@ -114,7 +114,7 @@ function assert_positive_number() { ## Best practices -1. **Always return after failure**: Call `return` after `bashunit::assertion_failed` or `fail` to stop execution of your custom assertion. +1. **Always return after failure**: Call `return` after `bashunit::assertion_failed` or `bashunit::fail` to stop execution of your custom assertion. 2. **Always mark success**: Call `bashunit::assertion_passed` or `state::add_assertions_passed` when your assertion succeeds. diff --git a/docs/data-providers.md b/docs/data-providers.md index d16cc4e5..6aa39428 100644 --- a/docs/data-providers.md +++ b/docs/data-providers.md @@ -23,7 +23,7 @@ function test_my_test_case() { ## Implementing a data provider -A data provider function contains one or more `data_set` lines. Each `data_set` results in a separate run of the test function with the individual `data_set` arguments being passed to it as positional arguments (`$1`, `$2`, ...). +A data provider function contains one or more `bashunit::data_set` lines. Each `bashunit::data_set` results in a separate run of the test function with the individual `bashunit::data_set` arguments being passed to it as positional arguments (`$1`, `$2`, ...). Each run is treated as a separate test, so it can pass or fail independently. Plus, [set_up](/test-files#set-up-function) and [tear_down](/test-files#tear-down-function) are called before and after each run. This reduces code repetition and helps create related tests more efficiently. @@ -32,10 +32,10 @@ A data provider function is implemented as follows: ::: code-group ```bash [Example] function provider_function() { - data_set "one" - data_set "two" "three" - data_set "value containing spaces" - data_set "" "first value is empty" + bashunit::data_set "one" + bashunit::data_set "two" "three" + bashunit::data_set "value containing spaces" + bashunit::data_set "" "first value is empty" } ``` @@ -43,7 +43,7 @@ function provider_function() { > **Note**: The previous variant of using `echo` to define data within a data provider > provider is still supported but deprecated, as it does not support empty values or -> values containing spaces. Prefer using the `data_set` function going forward. +> values containing spaces. Prefer using the `bashunit::data_set` function going forward. ## Interpolating arguments in test names @@ -59,8 +59,8 @@ function test_returns_fizz_when_multiple_of_::1::_like_::2::_given() { } function fizz_numbers() { - data_set 3 4 - data_set 3 6 + bashunit::data_set 3 4 + bashunit::data_set 3 6 } ``` ```[Output] @@ -86,7 +86,7 @@ function test_directories_exists() { } function provider_directories() { - data_set "/usr" "/etc" "/var" + bashunit::data_set "/usr" "/etc" "/var" } ``` ```[Output] @@ -107,9 +107,9 @@ function test_directory_exists() { } function provider_directories() { - data_set "/usr" - data_set "/etc" - data_set "/var" + bashunit::data_set "/usr" + bashunit::data_set "/etc" + bashunit::data_set "/var" } ``` ```[Output] @@ -134,9 +134,9 @@ function test_directory_exists() { } function provider_directories() { - data_set "outro" "/usr" - data_set "outro" "/etc" - data_set "outro" "/var" + bashunit::data_set "outro" "/usr" + bashunit::data_set "outro" "/etc" + bashunit::data_set "outro" "/var" } ``` ```[Output] diff --git a/docs/globals.md b/docs/globals.md index 4dfcb081..1696c7ce 100644 --- a/docs/globals.md +++ b/docs/globals.md @@ -34,38 +34,38 @@ log "error" "hello" "world" ``` Internal messages from bashunit include the `[INTERNAL]` prefix so you can easily spot them. You can enable them with `BASHUNIT_INTERNAL_LOG=true|false`. -## current_dir +## bashunit::current_dir -> `current_dir`: Gets the current directory name. +> `bashunit::current_dir`: Gets the current directory name. -## current_filename +## bashunit::current_filename -> `current_filename`: Gets the current filename. +> `bashunit::current_filename`: Gets the current filename. -## caller_filename +## bashunit::caller_filename -> `caller_filename`: Gets the caller filename. +> `bashunit::caller_filename`: Gets the caller filename. ## current_timestamp > `current_timestamp`: Gets the caller filename. -## random_str +## bashunit::random_str -> `random_str `: generate a random string +> `bashunit::random_str `: generate a random string -## temp_file +## bashunit::temp_file -> `temp_file `: creates a temporal file +> `bashunit::temp_file `: creates a temporal file The file is automatically deleted when bashunit completes. -## temp_dir +## bashunit::temp_dir -> `temp_dir `: creates a temporal directory +> `bashunit::temp_dir `: creates a temporal directory The directory is automatically deleted when bashunit completes. -## is_command_available +## bashunit::is_command_available -> `is_command_available`: Checks if command is available +> `bashunit::is_command_available`: Checks if command is available diff --git a/docs/skipping-incomplete.md b/docs/skipping-incomplete.md index 5add663f..dce27c3d 100644 --- a/docs/skipping-incomplete.md +++ b/docs/skipping-incomplete.md @@ -3,8 +3,8 @@ There may be various scenarios where the "passed" and "failed" outcomes for a test are not sufficient. To address these situations, the following functions are available for your use. -## skip -> `skip "[reason]"` +## bashunit::skip +> `bashunit::skip "[reason]"` Not all tests can be run in every environment; when such situations arise, you can mark a test as skipped. @@ -17,7 +17,7 @@ however, it will indicate that some tests were skipped in the final output. ```bash [Example] function test_skipped() { if [[ $OS != "GEOS" ]]; then - skip && return + bashunit::skip && return fi assert_empty "not reached" @@ -25,7 +25,7 @@ function test_skipped() { function test_skipped_with_reason() { if [[ $OS != "GEOS" ]]; then - skip "Not running under Commodore" && return + bashunit::skip "Not running under Commodore" && return fi assert_empty "not reached" @@ -42,8 +42,8 @@ Some tests skipped ``` ::: -## todo -> `todo "[pending]"` +## bashunit::todo +> `bashunit::todo "[pending]"` You may come up with a test that you'd like to implement later. Instead of leaving the test implementation empty —which would mark the test as complete— you can flag it as incomplete. @@ -56,11 +56,11 @@ however, it will indicate that some tests were incomplete in the final output. ::: code-group ```bash [Example] function test_incomplete() { - todo + bashunit::todo } function test_incomplete_with_pending_details() { - todo "Detailed description of what needs to be done" + bashunit::todo "Detailed description of what needs to be done" } ``` ```[Output] diff --git a/docs/test-doubles.md b/docs/test-doubles.md index 6f987a79..a288b9f3 100644 --- a/docs/test-doubles.md +++ b/docs/test-doubles.md @@ -7,34 +7,34 @@ Temporary files created by spies are isolated per test run, so they work reliabl Spies record their calls in temporary files scoped to each test run. This avoids clashes between processes and allows spies to work reliably when tests execute in parallel using `BASHUNIT_PARALLEL_RUN`. -## mock -> `mock "function" "body"` +## bashunit::mock +> `bashunit::mock "function" "body"` Allows you to override the behavior of a callable. ::: code-group ```bash [Example] function test_example() { - mock ps echo hello world + bashunit::mock ps echo hello world assert_same "hello world" "$(ps)" } ``` ::: -> `mock "function" <<< "output"` +> `bashunit::mock "function" <<< "output"` Allows you to override the output of a callable. When the mocked output fits on a single line you can use a here-string: ```bash -mock uname <<< "Linux" +bashunit::mock uname <<< "Linux" ``` For multi-line output rely on a here-document: ```bash -mock ps < `spy "function"` +## bashunit::spy +> `bashunit::spy "function"` Overrides the original behavior of a callable to allow you to make various assertions about its calls. ::: code-group ```bash [Example] function test_example() { - spy ps + bashunit::spy ps ps foo bar @@ -131,7 +131,7 @@ Reports an error if `spy` is not called. ::: code-group ```bash [Example] function test_success() { - spy ps + bashunit::spy ps ps @@ -139,7 +139,7 @@ function test_success() { } function test_failure() { - spy ps + bashunit::spy ps assert_have_been_called ps } @@ -154,7 +154,7 @@ Reports an error if `spy` is not called with `expected`. When `call_index` is pr ::: code-group ```bash [Example] function test_success() { - spy ps + bashunit::spy ps ps foo ps bar @@ -164,7 +164,7 @@ function test_success() { } function test_failure() { - spy ps + bashunit::spy ps ps bar @@ -182,7 +182,7 @@ Reports an error if `spy` is not called exactly `expected` times. ::: code-group ```bash [Example] function test_success() { - spy ps + bashunit::spy ps ps ps @@ -191,7 +191,7 @@ function test_success() { } function test_failure() { - spy ps + bashunit::spy ps ps ps @@ -209,13 +209,13 @@ Reports an error if `spy` has been executed at least once. ::: code-group ```bash [Example] function test_success() { - spy ps + bashunit::spy ps assert_not_called ps } function test_failure() { - spy ps + bashunit::spy ps ps diff --git a/src/assert.sh b/src/assert.sh index 85bf19ee..cfe20780 100755 --- a/src/assert.sh +++ b/src/assert.sh @@ -6,7 +6,7 @@ function assert::mark_failed() { state::mark_assertion_failed_in_test } -function fail() { +function bashunit::fail() { (( _ASSERTION_FAILED_IN_TEST )) && return 0 local message="${1:-${FUNCNAME[1]}}" @@ -27,15 +27,15 @@ function assert_true() { # Check for expected literal values first case "$actual" in "true"|"0") state::add_assertions_passed; return ;; - "false"|"1") handle_bool_assertion_failure "true or 0" "$actual"; return ;; + "false"|"1") bashunit::handle_bool_assertion_failure "true or 0" "$actual"; return ;; esac # Run command or eval and check the exit code - run_command_or_eval "$actual" + bashunit::run_command_or_eval "$actual" local exit_code=$? if [[ $exit_code -ne 0 ]]; then - handle_bool_assertion_failure "command or function with zero exit code" "exit code: $exit_code" + bashunit::handle_bool_assertion_failure "command or function with zero exit code" "exit code: $exit_code" else state::add_assertions_passed fi @@ -49,21 +49,21 @@ function assert_false() { # Check for expected literal values first case "$actual" in "false"|"1") state::add_assertions_passed; return ;; - "true"|"0") handle_bool_assertion_failure "false or 1" "$actual"; return ;; + "true"|"0") bashunit::handle_bool_assertion_failure "false or 1" "$actual"; return ;; esac # Run command or eval and check the exit code - run_command_or_eval "$actual" + bashunit::run_command_or_eval "$actual" local exit_code=$? if [[ $exit_code -eq 0 ]]; then - handle_bool_assertion_failure "command or function with non-zero exit code" "exit code: $exit_code" + bashunit::handle_bool_assertion_failure "command or function with non-zero exit code" "exit code: $exit_code" else state::add_assertions_passed fi } -function run_command_or_eval() { +function bashunit::run_command_or_eval() { local cmd="$1" if [[ "$cmd" =~ ^eval ]]; then @@ -76,7 +76,7 @@ function run_command_or_eval() { return $? } -function handle_bool_assertion_failure() { +function bashunit::handle_bool_assertion_failure() { local expected="$1" local got="$2" local test_fn diff --git a/src/benchmark.sh b/src/benchmark.sh index 32b9eb91..bb893cda 100644 --- a/src/benchmark.sh +++ b/src/benchmark.sh @@ -98,7 +98,7 @@ function benchmark::print_results() { fi printf "\nBenchmark Results (avg ms)\n" - print_line 80 "=" + bashunit::print_line 80 "=" printf "\n" local has_threshold=false diff --git a/src/env.sh b/src/env.sh index b0af723e..1007899f 100644 --- a/src/env.sh +++ b/src/env.sh @@ -132,7 +132,7 @@ function env::find_terminal_width() { } function env::print_verbose() { - internal_log "Printing verbose environment variables" + bashunit::internal_log "Printing verbose environment variables" local keys=( "BASHUNIT_DEFAULT_PATH" "BASHUNIT_DEV_LOG" @@ -157,7 +157,7 @@ function env::print_verbose() { done for key in "${keys[@]}"; do - internal_log "$key=${!key}" + bashunit::internal_log "$key=${!key}" printf "%s:%*s%s\n" "$key" $((max_length - ${#key} + 1)) "" "${!key}" done } @@ -165,7 +165,7 @@ function env::print_verbose() { EXIT_CODE_STOP_ON_FAILURE=4 # Use a unique directory per run to avoid conflicts when bashunit is invoked # recursively or multiple instances are executed in parallel. -TEMP_DIR_PARALLEL_TEST_SUITE="${TMPDIR:-/tmp}/bashunit/parallel/${_OS:-Unknown}/$(random_str 8)" +TEMP_DIR_PARALLEL_TEST_SUITE="${TMPDIR:-/tmp}/bashunit/parallel/${_OS:-Unknown}/$(bashunit::random_str 8)" TEMP_FILE_PARALLEL_STOP_ON_FAILURE="$TEMP_DIR_PARALLEL_TEST_SUITE/.stop-on-failure" TERMINAL_WIDTH="$(env::find_terminal_width)" FAILURES_OUTPUT_PATH=$(mktemp) @@ -178,5 +178,5 @@ BASHUNIT_TEMP_DIR="${TMPDIR:-/tmp}/bashunit/tmp" mkdir -p "$BASHUNIT_TEMP_DIR" && chmod -R 777 "$BASHUNIT_TEMP_DIR" if env::is_dev_mode_enabled; then - internal_log "info" "Dev log enabled" "file:$BASHUNIT_DEV_LOG" + bashunit::internal_log "info" "Dev log enabled" "file:$BASHUNIT_DEV_LOG" fi diff --git a/src/globals.sh b/src/globals.sh index 55701aa0..9e794874 100644 --- a/src/globals.sh +++ b/src/globals.sh @@ -3,31 +3,31 @@ set -euo pipefail # This file provides a set of global functions to developers. -function current_dir() { +function bashunit::current_dir() { dirname "${BASH_SOURCE[1]}" } -function current_filename() { +function bashunit::current_filename() { basename "${BASH_SOURCE[1]}" } -function caller_filename() { +function bashunit::caller_filename() { dirname "${BASH_SOURCE[2]}" } -function caller_line() { +function bashunit::caller_line() { echo "${BASH_LINENO[1]}" } -function current_timestamp() { +function bashunit::current_timestamp() { date +"%Y-%m-%d %H:%M:%S" } -function is_command_available() { +function bashunit::is_command_available() { command -v "$1" >/dev/null 2>&1 } -function random_str() { +function bashunit::random_str() { local length=${1:-6} local chars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' local str='' @@ -37,7 +37,7 @@ function random_str() { echo "$str" } -function temp_file() { +function bashunit::temp_file() { local prefix=${1:-bashunit} local test_prefix="" if [[ -n "${BASHUNIT_CURRENT_TEST_ID:-}" ]]; then @@ -50,7 +50,7 @@ function temp_file() { mktemp "$BASHUNIT_TEMP_DIR/${test_prefix}${prefix}.XXXXXXX" } -function temp_dir() { +function bashunit::temp_dir() { local prefix=${1:-bashunit} local test_prefix="" if [[ -n "${BASHUNIT_CURRENT_TEST_ID:-}" ]]; then @@ -63,22 +63,22 @@ function temp_dir() { mktemp -d "$BASHUNIT_TEMP_DIR/${test_prefix}${prefix}.XXXXXXX" } -function cleanup_testcase_temp_files() { - internal_log "cleanup_testcase_temp_files" +function bashunit::cleanup_testcase_temp_files() { + bashunit::internal_log "cleanup_testcase_temp_files" if [[ -n "${BASHUNIT_CURRENT_TEST_ID:-}" ]]; then rm -rf "$BASHUNIT_TEMP_DIR/${BASHUNIT_CURRENT_TEST_ID}"_* fi } -function cleanup_script_temp_files() { - internal_log "cleanup_script_temp_files" +function bashunit::cleanup_script_temp_files() { + bashunit::internal_log "cleanup_script_temp_files" if [[ -n "${BASHUNIT_CURRENT_SCRIPT_ID:-}" ]]; then rm -rf "$BASHUNIT_TEMP_DIR/${BASHUNIT_CURRENT_SCRIPT_ID}"_* fi } # shellcheck disable=SC2145 -function log() { +function bashunit::log() { if ! env::is_dev_mode_enabled; then return fi @@ -95,24 +95,24 @@ function log() { *) set -- "$level $@"; level="INFO" ;; esac - echo "$(current_timestamp) [$level]: $* #${BASH_SOURCE[1]}:${BASH_LINENO[0]}" >> "$BASHUNIT_DEV_LOG" + echo "$(bashunit::current_timestamp) [$level]: $* #${BASH_SOURCE[1]}:${BASH_LINENO[0]}" >> "$BASHUNIT_DEV_LOG" } -function internal_log() { +function bashunit::internal_log() { if ! env::is_dev_mode_enabled || ! env::is_internal_log_enabled; then return fi - echo "$(current_timestamp) [INTERNAL]: $* #${BASH_SOURCE[1]}:${BASH_LINENO[0]}" >> "$BASHUNIT_DEV_LOG" + echo "$(bashunit::current_timestamp) [INTERNAL]: $* #${BASH_SOURCE[1]}:${BASH_LINENO[0]}" >> "$BASHUNIT_DEV_LOG" } -function print_line() { +function bashunit::print_line() { local length="${1:-70}" # Default to 70 if not passed local char="${2:--}" # Default to '-' if not passed printf '%*s\n' "$length" '' | tr ' ' "$char" } -function data_set() { +function bashunit::data_set() { local arg local first=true diff --git a/src/helpers.sh b/src/helpers.sh index 0507ec4b..41724d15 100755 --- a/src/helpers.sh +++ b/src/helpers.sh @@ -405,7 +405,7 @@ function helper::generate_id() { local sanitized_basename sanitized_basename="$(helper::normalize_variable_name "$basename")" if env::is_parallel_run_enabled; then - echo "${sanitized_basename}_$$_$(random_str 6)" + echo "${sanitized_basename}_$$_$(bashunit::random_str 6)" else echo "${sanitized_basename}_$$" fi diff --git a/src/main.sh b/src/main.sh index de979f6a..60103eb1 100644 --- a/src/main.sh +++ b/src/main.sh @@ -275,7 +275,7 @@ function main::exec_tests() { test_files+=("$line") done < <(helper::load_test_files "$filter" "${files[@]}") - internal_log "exec_tests" "filter:$filter" "files:${test_files[*]}" + bashunit::internal_log "exec_tests" "filter:$filter" "files:${test_files[*]}" if [[ ${#test_files[@]} -eq 0 || -z "${test_files[0]}" ]]; then printf "%sError: At least one file path is required.%s\n" "${_COLOR_FAILED}" "${_COLOR_DEFAULT}" @@ -342,7 +342,7 @@ function main::exec_tests() { parallel::cleanup fi - internal_log "Finished tests" "exit_code:$exit_code" + bashunit::internal_log "Finished tests" "exit_code:$exit_code" exit $exit_code } @@ -355,7 +355,7 @@ function main::exec_benchmarks() { bench_files+=("$line") done < <(helper::load_bench_files "$filter" "${files[@]}") - internal_log "exec_benchmarks" "filter:$filter" "files:${bench_files[*]}" + bashunit::internal_log "exec_benchmarks" "filter:$filter" "files:${bench_files[*]}" if [[ ${#bench_files[@]} -eq 0 || -z "${bench_files[0]}" ]]; then printf "%sError: At least one file path is required.%s\n" "${_COLOR_FAILED}" "${_COLOR_DEFAULT}" @@ -369,14 +369,14 @@ function main::exec_benchmarks() { benchmark::print_results - internal_log "Finished benchmarks" + bashunit::internal_log "Finished benchmarks" } function main::cleanup() { printf "%sCaught Ctrl-C, killing all child processes...%s\n" "${_COLOR_SKIPPED}" "${_COLOR_DEFAULT}" # Kill all child processes of this script pkill -P $$ - cleanup_script_temp_files + bashunit::cleanup_script_temp_files if parallel::is_enabled; then parallel::cleanup fi @@ -389,7 +389,7 @@ function main::handle_stop_on_failure_sync() { console_results::print_incomplete_tests_and_reset console_results::print_skipped_tests_and_reset console_results::render_result - cleanup_script_temp_files + bashunit::cleanup_script_temp_files if parallel::is_enabled; then parallel::cleanup fi diff --git a/src/parallel.sh b/src/parallel.sh index 0d259c17..2d5d9adb 100755 --- a/src/parallel.sh +++ b/src/parallel.sh @@ -3,7 +3,7 @@ function parallel::aggregate_test_results() { local temp_dir_parallel_test_suite=$1 - internal_log "aggregate_test_results" "dir:$temp_dir_parallel_test_suite" + bashunit::internal_log "aggregate_test_results" "dir:$temp_dir_parallel_test_suite" local total_failed=0 local total_passed=0 @@ -85,7 +85,7 @@ function parallel::aggregate_test_results() { export _ASSERTIONS_INCOMPLETE=$total_incomplete export _ASSERTIONS_SNAPSHOT=$total_snapshot - internal_log "aggregate_totals" \ + bashunit::internal_log "aggregate_totals" \ "failed:$total_failed" \ "passed:$total_passed" \ "skipped:$total_skipped" \ @@ -112,7 +112,7 @@ function parallel::init() { } function parallel::is_enabled() { - internal_log "parallel::is_enabled" "requested:$BASHUNIT_PARALLEL_RUN" "os:${_OS:-Unknown}" + bashunit::internal_log "parallel::is_enabled" "requested:$BASHUNIT_PARALLEL_RUN" "os:${_OS:-Unknown}" if env::is_parallel_run_enabled && \ (check_os::is_macos || check_os::is_ubuntu || check_os::is_windows); then diff --git a/src/runner.sh b/src/runner.sh index 2ca19ace..415152cc 100755 --- a/src/runner.sh +++ b/src/runner.sh @@ -25,7 +25,7 @@ function runner::load_test_files() { unset BASHUNIT_CURRENT_TEST_ID export BASHUNIT_CURRENT_SCRIPT_ID="$(helper::generate_id "${test_file}")" scripts_ids+=("${BASHUNIT_CURRENT_SCRIPT_ID}") - internal_log "Loading file" "$test_file" + bashunit::internal_log "Loading file" "$test_file" # shellcheck source=/dev/null source "$test_file" # Update function cache after sourcing new test file @@ -48,7 +48,7 @@ function runner::load_test_files() { fi runner::clean_set_up_and_tear_down_after_script if ! parallel::is_enabled; then - cleanup_script_temp_files + bashunit::cleanup_script_temp_files fi runner::restore_workdir continue @@ -61,9 +61,9 @@ function runner::load_test_files() { runner::run_tear_down_after_script "$test_file" runner::clean_set_up_and_tear_down_after_script if ! parallel::is_enabled; then - cleanup_script_temp_files + bashunit::cleanup_script_temp_files fi - internal_log "Finished file" "$test_file" + bashunit::internal_log "Finished file" "$test_file" runner::restore_workdir done @@ -77,7 +77,7 @@ function runner::load_test_files() { printf "\r \r" # Clear the spinner output for script_id in "${scripts_ids[@]}"; do export BASHUNIT_CURRENT_SCRIPT_ID="${script_id}" - cleanup_script_temp_files + bashunit::cleanup_script_temp_files done fi } @@ -112,14 +112,14 @@ function runner::load_bench_files() { done fi runner::clean_set_up_and_tear_down_after_script - cleanup_script_temp_files + bashunit::cleanup_script_temp_files runner::restore_workdir continue fi runner::call_bench_functions "$bench_file" "$filter" runner::run_tear_down_after_script "$bench_file" runner::clean_set_up_and_tear_down_after_script - cleanup_script_temp_files + bashunit::cleanup_script_temp_files runner::restore_workdir done } @@ -337,7 +337,7 @@ function runner::call_bench_functions() { function runner::render_running_file_header() { local script="$1" - internal_log "Running file" "$script" + bashunit::internal_log "Running file" "$script" if parallel::is_enabled; then return @@ -363,7 +363,7 @@ function runner::run_test() { local fn_name="$1" shift - internal_log "Running test" "$fn_name" "$*" + bashunit::internal_log "Running test" "$fn_name" "$*" # Export a unique test identifier so that test doubles can # create temporary files scoped per test run. This prevents # race conditions when running tests in parallel. @@ -489,7 +489,7 @@ function runner::run_test() { hook_message="$(helper::decode_base64 "$encoded_hook_message")" fi - state::set_test_title "$test_title" + bashunit::set_test_title "$test_title" local label label="$(helper::normalize_test_function_name "$fn_name" "$interpolated_fn_name")" state::reset_test_title @@ -513,7 +513,7 @@ function runner::run_test() { console_results::print_error_test "$failure_function" "$error_message" reports::add_test_failed "$test_file" "$failure_label" "$duration" "$total_assertions" runner::write_failure_result_output "$test_file" "$failure_function" "$error_message" - internal_log "Test error" "$failure_label" "$error_message" + bashunit::internal_log "Test error" "$failure_label" "$error_message" return fi @@ -522,7 +522,7 @@ function runner::run_test() { reports::add_test_failed "$test_file" "$label" "$duration" "$total_assertions" runner::write_failure_result_output "$test_file" "$fn_name" "$subshell_output" - internal_log "Test failed" "$label" + bashunit::internal_log "Test failed" "$label" if env::is_stop_on_failure_enabled; then if parallel::is_enabled; then @@ -538,7 +538,7 @@ function runner::run_test() { state::add_tests_snapshot console_results::print_snapshot_test "$label" reports::add_test_snapshot "$test_file" "$label" "$duration" "$total_assertions" - internal_log "Test snapshot" "$label" + bashunit::internal_log "Test snapshot" "$label" return fi @@ -546,7 +546,7 @@ function runner::run_test() { state::add_tests_incomplete reports::add_test_incomplete "$test_file" "$label" "$duration" "$total_assertions" runner::write_incomplete_result_output "$test_file" "$fn_name" "$subshell_output" - internal_log "Test incomplete" "$label" + bashunit::internal_log "Test incomplete" "$label" return fi @@ -554,7 +554,7 @@ function runner::run_test() { state::add_tests_skipped reports::add_test_skipped "$test_file" "$label" "$duration" "$total_assertions" runner::write_skipped_result_output "$test_file" "$fn_name" "$subshell_output" - internal_log "Test skipped" "$label" + bashunit::internal_log "Test skipped" "$label" return fi @@ -565,7 +565,7 @@ function runner::run_test() { fi state::add_tests_passed reports::add_test_passed "$test_file" "$label" "$duration" "$total_assertions" - internal_log "Test passed" "$label" + bashunit::internal_log "Test passed" "$label" } function runner::cleanup_on_exit() { @@ -577,7 +577,7 @@ function runner::cleanup_on_exit() { runner::run_tear_down "$test_file" local teardown_status=$? runner::clear_mocks - cleanup_testcase_temp_files + bashunit::cleanup_testcase_temp_files if [[ $teardown_status -ne 0 ]]; then state::set_test_exit_code "$teardown_status" @@ -638,7 +638,7 @@ function runner::parse_result_parallel() { mv "$unique_test_result_file" "${unique_test_result_file}.result" unique_test_result_file="${unique_test_result_file}.result" - internal_log "[PARA]" "fn_name:$fn_name" "execution_result:$execution_result" + bashunit::internal_log "[PARA]" "fn_name:$fn_name" "execution_result:$execution_result" runner::parse_result_sync "$fn_name" "$execution_result" @@ -670,7 +670,7 @@ function runner::parse_result_sync() { test_exit_code="${BASH_REMATCH[6]}" fi - internal_log "[SYNC]" "fn_name:$fn_name" "execution_result:$execution_result" + bashunit::internal_log "[SYNC]" "fn_name:$fn_name" "execution_result:$execution_result" ((_ASSERTIONS_PASSED += assertions_passed)) || true ((_ASSERTIONS_FAILED += assertions_failed)) || true @@ -679,7 +679,7 @@ function runner::parse_result_sync() { ((_ASSERTIONS_SNAPSHOT += assertions_snapshot)) || true ((_TEST_EXIT_CODE += test_exit_code)) || true - internal_log "result_summary" \ + bashunit::internal_log "result_summary" \ "failed:$assertions_failed" \ "passed:$assertions_passed" \ "skipped:$assertions_skipped" \ @@ -769,7 +769,7 @@ function runner::execute_file_hook() { local hook_output="" local status=0 local hook_output_file - hook_output_file=$(temp_file "${hook_name}_output") + hook_output_file=$(bashunit::temp_file "${hook_name}_output") # Enable errexit and errtrace to catch any failing command in the hook. # The ERR trap saves the exit status to a global variable (since return value @@ -812,19 +812,19 @@ function runner::execute_file_hook() { function runner::run_set_up() { local _test_file="${1-}" - internal_log "run_set_up" + bashunit::internal_log "run_set_up" runner::execute_test_hook 'set_up' } function runner::run_set_up_before_script() { local test_file="$1" - internal_log "run_set_up_before_script" + bashunit::internal_log "run_set_up_before_script" runner::execute_file_hook 'set_up_before_script' "$test_file" true } function runner::run_tear_down() { local _test_file="${1-}" - internal_log "run_tear_down" + bashunit::internal_log "run_tear_down" runner::execute_test_hook 'tear_down' } @@ -836,7 +836,7 @@ function runner::execute_test_hook() { local hook_output="" local status=0 local hook_output_file - hook_output_file=$(temp_file "${hook_name}_output") + hook_output_file=$(bashunit::temp_file "${hook_name}_output") # Enable errexit and errtrace to catch any failing command in the hook. # The ERR trap saves the exit status to a global variable (since return value @@ -901,18 +901,18 @@ function runner::record_test_hook_failure() { function runner::clear_mocks() { for i in "${!MOCKED_FUNCTIONS[@]}"; do - unmock "${MOCKED_FUNCTIONS[$i]}" + bashunit::unmock "${MOCKED_FUNCTIONS[$i]}" done } function runner::run_tear_down_after_script() { local test_file="$1" - internal_log "run_tear_down_after_script" + bashunit::internal_log "run_tear_down_after_script" runner::execute_file_hook 'tear_down_after_script' "$test_file" } function runner::clean_set_up_and_tear_down_after_script() { - internal_log "clean_set_up_and_tear_down_after_script" + bashunit::internal_log "clean_set_up_and_tear_down_after_script" helper::unset_if_exists 'set_up' helper::unset_if_exists 'tear_down' helper::unset_if_exists 'set_up_before_script' diff --git a/src/skip_todo.sh b/src/skip_todo.sh index 0fa940d8..1f91ada1 100755 --- a/src/skip_todo.sh +++ b/src/skip_todo.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -function skip() { +function bashunit::skip() { local reason=${1-} local label label="$(helper::normalize_test_function_name "${FUNCNAME[1]}")" @@ -10,7 +10,7 @@ function skip() { state::add_assertions_skipped } -function todo() { +function bashunit::todo() { local pending=${1-} local label label="$(helper::normalize_test_function_name "${FUNCNAME[1]}")" diff --git a/src/state.sh b/src/state.sh index 360ef152..51ce15b9 100644 --- a/src/state.sh +++ b/src/state.sh @@ -283,7 +283,7 @@ function state::print_line() { incomplete) char="${_COLOR_INCOMPLETE}I${_COLOR_DEFAULT}" ;; snapshot) char="${_COLOR_SNAPSHOT}N${_COLOR_DEFAULT}" ;; error) char="${_COLOR_FAILED}E${_COLOR_DEFAULT}" ;; - *) char="?" && log "warning" "unknown test type '$type'" ;; + *) char="?" && bashunit::log "warning" "unknown test type '$type'" ;; esac if parallel::is_enabled; then diff --git a/src/test_doubles.sh b/src/test_doubles.sh index 6ea10bac..9cd955fc 100644 --- a/src/test_doubles.sh +++ b/src/test_doubles.sh @@ -2,7 +2,7 @@ declare -a MOCKED_FUNCTIONS=() -function unmock() { +function bashunit::unmock() { local command=$1 for i in "${!MOCKED_FUNCTIONS[@]}"; do @@ -22,7 +22,7 @@ function unmock() { done } -function mock() { +function bashunit::mock() { local command=$1 shift @@ -37,15 +37,15 @@ function mock() { MOCKED_FUNCTIONS+=("$command") } -function spy() { +function bashunit::spy() { local command=$1 local variable variable="$(helper::normalize_variable_name "$command")" local times_file params_file local test_id="${BASHUNIT_CURRENT_TEST_ID:-global}" - times_file=$(temp_file "${test_id}_${variable}_times") - params_file=$(temp_file "${test_id}_${variable}_params") + times_file=$(bashunit::temp_file "${test_id}_${variable}_times") + params_file=$(bashunit::temp_file "${test_id}_${variable}_params") echo 0 > "$times_file" : > "$params_file" export "${variable}_times_file"="$times_file" diff --git a/src/test_title.sh b/src/test_title.sh index db7c29c4..399f4383 100644 --- a/src/test_title.sh +++ b/src/test_title.sh @@ -1,5 +1,5 @@ #!/usr/bin/env bash -function set_test_title() { +function bashunit::set_test_title() { state::set_test_title "$1" } diff --git a/tests/acceptance/bashunit_execution_error_test.sh b/tests/acceptance/bashunit_execution_error_test.sh index 1248fe2a..487233fe 100644 --- a/tests/acceptance/bashunit_execution_error_test.sh +++ b/tests/acceptance/bashunit_execution_error_test.sh @@ -34,8 +34,8 @@ function test_bashunit_when_a_execution_error() { format_summary_value "0 failed" ", 0 total" ) - todo "Add snapshots with regex to assert this test (part of the error message is localized)" - todo "Add snapshots with simple/verbose modes as in bashunit_pass_test and bashunit_fail_test" + bashunit::todo "Add snapshots with regex to assert this test (part of the error message is localized)" + bashunit::todo "Add snapshots with simple/verbose modes as in bashunit_pass_test and bashunit_fail_test" local actual="$(./bashunit --no-parallel --detailed --env "$TEST_ENV_FILE" "$test_file")" assert_contains "$fixture_start" "$actual" diff --git a/tests/acceptance/bashunit_fail_test.sh b/tests/acceptance/bashunit_fail_test.sh index db0dbb04..126de6e1 100644 --- a/tests/acceptance/bashunit_fail_test.sh +++ b/tests/acceptance/bashunit_fail_test.sh @@ -21,7 +21,7 @@ function test_bashunit_when_a_test_fail_verbose_output_option() { } function test_different_verbose_snapshots_matches() { - todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" } function test_bashunit_when_a_test_fail_simple_output_env() { @@ -53,5 +53,5 @@ function test_bashunit_with_a_test_fail_and_exit_immediately() { } function test_different_simple_snapshots_matches() { - todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" } diff --git a/tests/acceptance/bashunit_init_test.sh b/tests/acceptance/bashunit_init_test.sh index 4fa35f96..a9e4f035 100644 --- a/tests/acceptance/bashunit_init_test.sh +++ b/tests/acceptance/bashunit_init_test.sh @@ -34,7 +34,7 @@ function test_bashunit_init_custom_directory() { } function test_bashunit_init_updates_env() { - skip "flaky" && return + bashunit::skip "flaky" && return pushd "$TMP_DIR" >/dev/null echo "BASHUNIT_BOOTSTRAP=old/bootstrap.sh" > .env diff --git a/tests/acceptance/bashunit_pass_test.sh b/tests/acceptance/bashunit_pass_test.sh index 437c20f2..c623d7e4 100644 --- a/tests/acceptance/bashunit_pass_test.sh +++ b/tests/acceptance/bashunit_pass_test.sh @@ -21,7 +21,7 @@ function test_bashunit_when_a_test_passes_verbose_output_option() { } function test_different_verbose_snapshots_matches() { - todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" } function test_bashunit_when_a_test_passes_simple_output_env() { @@ -39,5 +39,5 @@ function test_bashunit_when_a_test_passes_simple_output_option() { } function test_different_simple_snapshots_matches() { - todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" } diff --git a/tests/acceptance/bashunit_stop_on_failure_test.sh b/tests/acceptance/bashunit_stop_on_failure_test.sh index 8fe89cd3..1c1e4e37 100644 --- a/tests/acceptance/bashunit_stop_on_failure_test.sh +++ b/tests/acceptance/bashunit_stop_on_failure_test.sh @@ -21,7 +21,7 @@ function test_bashunit_when_stop_on_failure_env() { } function test_different_snapshots_matches() { - todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" } function test_bashunit_when_stop_on_failure_env_simple_output() { diff --git a/tests/acceptance/bashunit_test.sh b/tests/acceptance/bashunit_test.sh index dba0ebec..6840c691 100644 --- a/tests/acceptance/bashunit_test.sh +++ b/tests/acceptance/bashunit_test.sh @@ -6,7 +6,7 @@ function test_bashunit_should_display_version() { local fixture fixture=$(printf "\e[1m\e[32mbashunit\e[0m - %s" "$BASHUNIT_VERSION") - todo "Add snapshots with regex to assert this test (part of the output changes every version)" + bashunit::todo "Add snapshots with regex to assert this test (part of the output changes every version)" assert_contains "$fixture" "$(./bashunit --version)" assert_successful_code "$(./bashunit --version)" } @@ -30,7 +30,7 @@ function test_built_binary_should_display_docs_without_file_access() { local built_bin="${BASHUNIT_BUILD_DIR:-bin}/bashunit" if [[ ! -f "$built_bin" ]]; then - skip "Built binary not found - run ./build.sh first" + bashunit::skip "Built binary not found - run ./build.sh first" return fi @@ -46,7 +46,7 @@ function test_built_binary_docs_should_match_dev_docs() { local built_bin="${BASHUNIT_BUILD_DIR:-bin}/bashunit" if [[ ! -f "$built_bin" ]]; then - skip "Built binary not found - run ./build.sh first" + bashunit::skip "Built binary not found - run ./build.sh first" return fi diff --git a/tests/acceptance/bashunit_upgrade_test.sh b/tests/acceptance/bashunit_upgrade_test.sh index ac0acbf1..3487c07a 100644 --- a/tests/acceptance/bashunit_upgrade_test.sh +++ b/tests/acceptance/bashunit_upgrade_test.sh @@ -40,7 +40,7 @@ function tear_down() { } function test_do_not_upgrade_when_latest() { - skip "failing when having a new release" && return + bashunit::skip "failing when having a new release" && return local output output="$($TMP_BIN upgrade)" @@ -51,13 +51,13 @@ function test_do_not_upgrade_when_latest() { function test_upgrade_when_a_new_version_found() { if [[ "$ACTIVE_INTERNET" == false ]]; then - skip "no internet connection" && return + bashunit::skip "no internet connection" && return fi if [[ "$HAS_GIT" == false ]]; then - skip "git not installed" && return + bashunit::skip "git not installed" && return fi if [[ "$HAS_DOWNLOADER" == false ]]; then - skip "curl or wget not installed" && return + bashunit::skip "curl or wget not installed" && return fi sed -i -e \ @@ -77,16 +77,16 @@ function test_upgrade_when_a_new_version_found() { } function test_do_not_update_on_consecutive_calls() { - skip "after upgrade, binary uses old CLI syntax" && return + bashunit::skip "after upgrade, binary uses old CLI syntax" && return if [[ "$ACTIVE_INTERNET" == false ]]; then - skip "no internet connection" && return + bashunit::skip "no internet connection" && return fi if [[ "$HAS_GIT" == false ]]; then - skip "git not installed" && return + bashunit::skip "git not installed" && return fi if [[ "$HAS_DOWNLOADER" == false ]]; then - skip "curl or wget not installed" && return + bashunit::skip "curl or wget not installed" && return fi sed -i -e \ diff --git a/tests/acceptance/fixtures/script_with_setup_temp_file.sh b/tests/acceptance/fixtures/script_with_setup_temp_file.sh index 6e3292f9..d9a3211f 100644 --- a/tests/acceptance/fixtures/script_with_setup_temp_file.sh +++ b/tests/acceptance/fixtures/script_with_setup_temp_file.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash function set_up_before_script() { - SCRIPT_TEMP_FILE=$(temp_file "script-setup") - SCRIPT_TEMP_DIR=$(temp_dir "script-setup") + SCRIPT_TEMP_FILE=$(bashunit::temp_file "script-setup") + SCRIPT_TEMP_DIR=$(bashunit::temp_dir "script-setup") echo "Script temp file created: $SCRIPT_TEMP_FILE" > "$SCRIPT_TEMP_FILE" echo "Script temp dir created: $SCRIPT_TEMP_DIR" > "$SCRIPT_TEMP_DIR/marker.txt" } diff --git a/tests/acceptance/fixtures/test_bashunit_when_report_html.sh b/tests/acceptance/fixtures/test_bashunit_when_report_html.sh index eb53265c..b212eebb 100644 --- a/tests/acceptance/fixtures/test_bashunit_when_report_html.sh +++ b/tests/acceptance/fixtures/test_bashunit_when_report_html.sh @@ -9,9 +9,9 @@ function test_fail() { } function test_skipped() { - skip + bashunit::skip } function test_todo() { - todo + bashunit::todo } diff --git a/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh index f3fdea65..3c4db07c 100644 --- a/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh +++ b/tests/acceptance/fixtures/test_bashunit_with_multiple_failing_tests.sh @@ -10,11 +10,11 @@ function test_assert_failing() { } function test_assert_todo_and_skip() { - todo "foo" - skip "bar" + bashunit::todo "foo" + bashunit::skip "bar" } function test_assert_skip_and_todo() { - skip "baz" - todo "yei" + bashunit::skip "baz" + bashunit::todo "yei" } diff --git a/tests/acceptance/fixtures/test_cd_in_setup_before_script_first.sh b/tests/acceptance/fixtures/test_cd_in_setup_before_script_first.sh index fd534627..06ce723c 100644 --- a/tests/acceptance/fixtures/test_cd_in_setup_before_script_first.sh +++ b/tests/acceptance/fixtures/test_cd_in_setup_before_script_first.sh @@ -5,7 +5,7 @@ set -euo pipefail # First test file that changes directory in set_up_before_script function set_up_before_script() { - cd "$(temp_dir)" || return 1 + cd "$(bashunit::temp_dir)" || return 1 } function test_first_file_runs() { diff --git a/tests/acceptance/fixtures/test_custom_title.sh b/tests/acceptance/fixtures/test_custom_title.sh index 477a5d6b..352e0c85 100644 --- a/tests/acceptance/fixtures/test_custom_title.sh +++ b/tests/acceptance/fixtures/test_custom_title.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash function test_custom_title() { - set_test_title "🔥 handles invalid input with 💣" + bashunit::set_test_title "🔥 handles invalid input with 💣" assert_true true } diff --git a/tests/acceptance/fixtures/test_parallel_spy_file1.sh b/tests/acceptance/fixtures/test_parallel_spy_file1.sh index 9e61cfbb..6bd01dc9 100755 --- a/tests/acceptance/fixtures/test_parallel_spy_file1.sh +++ b/tests/acceptance/fixtures/test_parallel_spy_file1.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash function test_spy_file1() { - spy date + bashunit::spy date date assert_have_been_called_times 1 date } diff --git a/tests/acceptance/fixtures/test_parallel_spy_file2.sh b/tests/acceptance/fixtures/test_parallel_spy_file2.sh index 33ac7fc5..58431c2d 100755 --- a/tests/acceptance/fixtures/test_parallel_spy_file2.sh +++ b/tests/acceptance/fixtures/test_parallel_spy_file2.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash function test_spy_file2() { - spy date + bashunit::spy date date assert_have_been_called_times 1 date } diff --git a/tests/acceptance/install_test.sh b/tests/acceptance/install_test.sh index c39fb731..a44c91c1 100644 --- a/tests/acceptance/install_test.sh +++ b/tests/acceptance/install_test.sh @@ -34,10 +34,10 @@ function tear_down() { function test_install_downloads_the_latest_version() { if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then - skip "no internet connection" && return + bashunit::skip "no internet connection" && return fi if [[ "$HAS_DOWNLOADER" -eq 0 ]]; then - skip "curl or wget not installed" && return + bashunit::skip "curl or wget not installed" && return fi local installed_bashunit="./lib/bashunit" @@ -56,10 +56,10 @@ function test_install_downloads_the_latest_version() { function test_install_downloads_in_given_folder() { if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then - skip "no internet connection" && return + bashunit::skip "no internet connection" && return fi if [[ "$HAS_DOWNLOADER" -eq 0 ]]; then - skip "curl or wget not installed" && return + bashunit::skip "curl or wget not installed" && return fi local installed_bashunit="./deps/bashunit" @@ -78,10 +78,10 @@ function test_install_downloads_in_given_folder() { function test_install_downloads_the_given_version() { if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then - skip "no internet connection" && return + bashunit::skip "no internet connection" && return fi if [[ "$HAS_DOWNLOADER" -eq 0 ]]; then - skip "curl or wget not installed" && return + bashunit::skip "curl or wget not installed" && return fi local installed_bashunit="./lib/bashunit" @@ -102,10 +102,10 @@ function test_install_downloads_the_given_version() { function test_install_downloads_the_given_version_without_dir() { if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then - skip "no internet connection" && return + bashunit::skip "no internet connection" && return fi if [[ "$HAS_DOWNLOADER" -eq 0 ]]; then - skip "curl or wget not installed" && return + bashunit::skip "curl or wget not installed" && return fi local installed_bashunit="./lib/bashunit" @@ -128,17 +128,17 @@ function test_install_downloads_the_given_version_without_dir() { function test_install_downloads_the_non_stable_beta_version() { if [[ "$ACTIVE_INTERNET" -eq 1 ]]; then - skip "no internet connection" && return + bashunit::skip "no internet connection" && return fi if [[ "$HAS_GIT" -eq 0 ]]; then - skip "git not installed" && return + bashunit::skip "git not installed" && return fi if [[ "$HAS_DOWNLOADER" -eq 0 ]]; then - skip "curl or wget not installed" && return + bashunit::skip "curl or wget not installed" && return fi - mock date <<< "2023-11-13" - mock tput <<< "" + bashunit::mock date <<< "2023-11-13" + bashunit::mock tput <<< "" local installed_bashunit="./deps/bashunit" local output diff --git a/tests/acceptance/mock_test.sh b/tests/acceptance/mock_test.sh index 1df9cd0f..068a914b 100644 --- a/tests/acceptance/mock_test.sh +++ b/tests/acceptance/mock_test.sh @@ -6,10 +6,10 @@ set -euo pipefail # removing the mocks and spies from the first test # function test_runner_clear_mocks_first() { - mock ls echo foo + bashunit::mock ls echo foo assert_same "foo" "$(ls)" - spy ps + bashunit::spy ps ps foo bar assert_have_been_called_times 1 ps } diff --git a/tests/acceptance/parallel_spy_parallel_test.sh b/tests/acceptance/parallel_spy_parallel_test.sh index 10926801..96e74bf0 100755 --- a/tests/acceptance/parallel_spy_parallel_test.sh +++ b/tests/acceptance/parallel_spy_parallel_test.sh @@ -3,8 +3,8 @@ set -euo pipefail function test_spies_work_in_parallel() { - local file1="$(current_dir)/fixtures/test_parallel_spy_file1.sh" - local file2="$(current_dir)/fixtures/test_parallel_spy_file2.sh" + local file1="$(bashunit::current_dir)/fixtures/test_parallel_spy_file1.sh" + local file2="$(bashunit::current_dir)/fixtures/test_parallel_spy_file2.sh" ./bashunit --parallel "$file1" "$file2" assert_successful_code diff --git a/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_all_assert_docs.snapshot b/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_all_assert_docs.snapshot index e2204851..5144d03a 100644 --- a/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_all_assert_docs.snapshot +++ b/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_all_assert_docs.snapshot @@ -174,6 +174,6 @@ -------------- ::ignore:: -## fail +## bashunit::fail -------------- ::ignore:: diff --git a/tests/bootstrap.sh b/tests/bootstrap.sh index 948312eb..c80565b2 100644 --- a/tests/bootstrap.sh +++ b/tests/bootstrap.sh @@ -14,52 +14,52 @@ function mock_true() { } function mock_unknown_linux_os() { - mock check_os::is_linux mock_true + bashunit::mock check_os::is_linux mock_true - mock check_os::is_ubuntu mock_false - mock check_os::is_alpine mock_false - mock check_os::is_busybox mock_false - mock check_os::is_macos mock_false - mock check_os::is_windows mock_false + bashunit::mock check_os::is_ubuntu mock_false + bashunit::mock check_os::is_alpine mock_false + bashunit::mock check_os::is_busybox mock_false + bashunit::mock check_os::is_macos mock_false + bashunit::mock check_os::is_windows mock_false } function mock_ubuntu_os() { - mock check_os::is_linux mock_true - mock check_os::is_ubuntu mock_true + bashunit::mock check_os::is_linux mock_true + bashunit::mock check_os::is_ubuntu mock_true - mock check_os::is_alpine mock_false - mock check_os::is_busybox mock_false - mock check_os::is_macos mock_false - mock check_os::is_windows mock_false + bashunit::mock check_os::is_alpine mock_false + bashunit::mock check_os::is_busybox mock_false + bashunit::mock check_os::is_macos mock_false + bashunit::mock check_os::is_windows mock_false } function mock_alpine_os() { - mock check_os::is_linux mock_true - mock check_os::is_alpine mock_true - mock check_os::is_busybox mock_true + bashunit::mock check_os::is_linux mock_true + bashunit::mock check_os::is_alpine mock_true + bashunit::mock check_os::is_busybox mock_true - mock check_os::is_ubuntu mock_false - mock check_os::is_macos mock_false - mock check_os::is_windows mock_false + bashunit::mock check_os::is_ubuntu mock_false + bashunit::mock check_os::is_macos mock_false + bashunit::mock check_os::is_windows mock_false } function mock_macos() { - mock check_os::is_macos mock_true + bashunit::mock check_os::is_macos mock_true - mock check_os::is_linux mock_false - mock check_os::is_alpine mock_false - mock check_os::is_ubuntu mock_false - mock check_os::is_busybox mock_false - mock check_os::is_windows mock_false + bashunit::mock check_os::is_linux mock_false + bashunit::mock check_os::is_alpine mock_false + bashunit::mock check_os::is_ubuntu mock_false + bashunit::mock check_os::is_busybox mock_false + bashunit::mock check_os::is_windows mock_false } function mock_windows_os() { - mock check_os::is_windows mock_true + bashunit::mock check_os::is_windows mock_true - mock check_os::is_linux mock_false - mock check_os::is_alpine mock_false - mock check_os::is_ubuntu mock_false - mock check_os::is_busybox mock_false - mock check_os::is_macos mock_false + bashunit::mock check_os::is_linux mock_false + bashunit::mock check_os::is_alpine mock_false + bashunit::mock check_os::is_ubuntu mock_false + bashunit::mock check_os::is_busybox mock_false + bashunit::mock check_os::is_macos mock_false } diff --git a/tests/functional/custom_asserts_test.sh b/tests/functional/custom_asserts_test.sh index 2b66bbaf..9faf56f5 100644 --- a/tests/functional/custom_asserts_test.sh +++ b/tests/functional/custom_asserts_test.sh @@ -3,7 +3,7 @@ set -euo pipefail function set_up() { # shellcheck disable=SC1091 - source "$(current_dir)/custom_asserts.sh" + source "$(bashunit::current_dir)/custom_asserts.sh" } function test_assert_foo_passed() { diff --git a/tests/functional/doubles_test.sh b/tests/functional/doubles_test.sh index 42ebb516..48ec1685 100644 --- a/tests/functional/doubles_test.sh +++ b/tests/functional/doubles_test.sh @@ -3,22 +3,22 @@ # shellcheck disable=SC1091 function test_mock_ps_when_executing_a_script() { - mock ps cat ./tests/functional/fixtures/doubles_ps_output + bashunit::mock ps cat ./tests/functional/fixtures/doubles_ps_output assert_match_snapshot "$(source ./tests/functional/fixtures/doubles_script.sh)" } function test_mock_ps_when_executing_a_sourced_function() { source ./tests/functional/fixtures/doubles_function.sh - mock ps cat ./tests/functional/fixtures/doubles_ps_output + bashunit::mock ps cat ./tests/functional/fixtures/doubles_ps_output assert_match_snapshot "$(top_mem)" } function test_spy_commands_called_when_executing_a_script() { - spy ps - spy awk - spy head + bashunit::spy ps + bashunit::spy awk + bashunit::spy head ./tests/functional/fixtures/doubles_script.sh @@ -29,9 +29,9 @@ function test_spy_commands_called_when_executing_a_script() { function test_spy_commands_called_when_executing_a_sourced_function() { source ./tests/functional/fixtures/doubles_function.sh - spy ps - spy awk - spy head + bashunit::spy ps + bashunit::spy awk + bashunit::spy head top_mem @@ -41,9 +41,9 @@ function test_spy_commands_called_when_executing_a_sourced_function() { } function test_spy_commands_called_once_when_executing_a_script() { - spy ps - spy awk - spy head + bashunit::spy ps + bashunit::spy awk + bashunit::spy head ./tests/functional/fixtures/doubles_script.sh @@ -54,9 +54,9 @@ function test_spy_commands_called_once_when_executing_a_script() { function test_spy_commands_called_once_when_executing_a_sourced_function() { source ./tests/functional/fixtures/doubles_function.sh - spy ps - spy awk - spy head + bashunit::spy ps + bashunit::spy awk + bashunit::spy head top_mem diff --git a/tests/functional/logic_test.sh b/tests/functional/logic_test.sh index 729a7928..e4747377 100755 --- a/tests/functional/logic_test.sh +++ b/tests/functional/logic_test.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash set -euo pipefail -ROOT_DIR="$(current_dir)" +ROOT_DIR="$(bashunit::current_dir)" SCRIPT="$ROOT_DIR/logic.sh" diff --git a/tests/functional/provider_test.sh b/tests/functional/provider_test.sh index 441d6b33..fcf543ba 100644 --- a/tests/functional/provider_test.sh +++ b/tests/functional/provider_test.sh @@ -51,7 +51,7 @@ function test_empty_value_from_data_provider() { } function provide_empty_value() { - data_set "" "two" + bashunit::data_set "" "two" } # @data_provider provide_long_value @@ -61,7 +61,7 @@ function test_long_value_from_data_provider() { } function provide_long_value() { - data_set "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" + bashunit::data_set "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz" } # @data_provider provide_value_with_tabs @@ -72,7 +72,7 @@ function test_value_with_tabs_from_data_provider() { } function provide_value_with_tabs() { - data_set "value with tabs" + bashunit::data_set "value with tabs" } # @data_provider provide_value_with_newline @@ -85,7 +85,7 @@ newline" "$value" } function provide_value_with_newline() { - data_set "value + bashunit::data_set "value with newline" } @@ -100,7 +100,7 @@ function test_value_with_whitespace_from_data_provider() { } function provide_value_with_whitespace() { - data_set "first value" "second value" + bashunit::data_set "first value" "second value" } # @data_provider provide_value_with_trailing_whitespace @@ -112,9 +112,9 @@ function test_trailing_whitespace_in_last_value_from_data_provider() { } function provide_value_with_trailing_whitespace() { - # Each data_set is passed the same value twice (expected, actual) to verify preservation - data_set "value " "value " - data_set "value " "value " + # Each bashunit::data_set is passed the same value twice (expected, actual) to verify preservation + bashunit::data_set "value " "value " + bashunit::data_set "value " "value " } # @data_provider provide_eval_gotchas @@ -139,7 +139,7 @@ function test_single_arg_with_space_from_data_provider() { } function provide_single_arg_with_space() { - data_set "test test" + bashunit::data_set "test test" } # @data_provider provide_two_args_with_spaces @@ -150,5 +150,5 @@ function test_two_args_with_spaces_from_data_provider() { } function provide_two_args_with_spaces() { - data_set "first test" "second test" + bashunit::data_set "first test" "second test" } diff --git a/tests/functional/provider_with_cd_test.sh b/tests/functional/provider_with_cd_test.sh index d6604c17..f9132af9 100644 --- a/tests/functional/provider_with_cd_test.sh +++ b/tests/functional/provider_with_cd_test.sh @@ -5,7 +5,7 @@ set -euo pipefail # Data providers should work even when set_up_before_script changes directory function set_up_before_script() { - cd "$(temp_dir)" || return 1 + cd "$(bashunit::temp_dir)" || return 1 } # @data_provider provide_data diff --git a/tests/unit/assert_snapshot_test.sh b/tests/unit/assert_snapshot_test.sh index 7fb6b61b..1b00bd1a 100644 --- a/tests/unit/assert_snapshot_test.sh +++ b/tests/unit/assert_snapshot_test.sh @@ -11,7 +11,7 @@ function test_successful_assert_match_snapshot() { } function test_creates_a_snapshot() { - local snapshot_path="$(temp_dir)/assert_snapshot_test_sh.test_creates_a_snapshot.snapshot" + local snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_creates_a_snapshot.snapshot" local expected=$((_ASSERTIONS_SNAPSHOT + 1)) assert_file_not_exists "$snapshot_path" @@ -36,7 +36,7 @@ function test_successful_assert_match_snapshot_ignore_colors() { } function test_creates_a_snapshot_ignore_colors() { - local snapshot_path="$(temp_dir)/assert_snapshot_test_sh.test_creates_a_snapshot_ignore_colors.snapshot" + local snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_creates_a_snapshot_ignore_colors.snapshot" local expected=$((_ASSERTIONS_SNAPSHOT + 1)) assert_file_not_exists "$snapshot_path" @@ -59,10 +59,10 @@ function test_unsuccessful_assert_match_snapshot_ignore_colors() { function test_assert_match_snapshot_with_placeholder() { if ! dependencies::has_perl; then - skip "perl not available" && return + bashunit::skip "perl not available" && return fi - local snapshot_path="$(temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_placeholder.snapshot" + local snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_placeholder.snapshot" echo 'Run at ::ignore::' > "$snapshot_path" assert_empty "$(assert_match_snapshot "Run at $(date -u '+%F %T UTC')" "$snapshot_path")" @@ -70,10 +70,10 @@ function test_assert_match_snapshot_with_placeholder() { function test_assert_match_snapshot_with_custom_placeholder() { if ! dependencies::has_perl; then - skip "perl not available" && return + bashunit::skip "perl not available" && return fi - local snapshot_path="$(temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_custom_placeholder.snapshot" + local snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_custom_placeholder.snapshot" echo 'Value __ANY__' > "$snapshot_path" export BASHUNIT_SNAPSHOT_PLACEHOLDER='__ANY__' diff --git a/tests/unit/assert_test.sh b/tests/unit/assert_test.sh index 7e6560e6..4bec98b4 100644 --- a/tests/unit/assert_test.sh +++ b/tests/unit/assert_test.sh @@ -4,14 +4,14 @@ # shellcheck disable=SC2329 function test_successful_fail() { - true || fail "This cannot fail" + true || bashunit::fail "This cannot fail" } function test_unsuccessful_fail() { assert_same\ "$(console_results::print_failure_message \ "Unsuccessful fail" "Failure message")"\ - "$(fail "Failure message")" + "$(bashunit::fail "Failure message")" } # @data_provider provider_successful_assert_true @@ -21,9 +21,9 @@ function test_successful_assert_true() { } function provider_successful_assert_true() { - data_set true - data_set "true" - data_set 0 + bashunit::data_set true + bashunit::data_set "true" + bashunit::data_set 0 } function test_unsuccessful_assert_true() { @@ -55,9 +55,9 @@ function test_successful_assert_false() { } function provider_successful_assert_false() { - data_set false - data_set "false" - data_set 1 + bashunit::data_set false + bashunit::data_set "false" + bashunit::data_set 1 } function test_unsuccessful_assert_false() { diff --git a/tests/unit/check_os_test.sh b/tests/unit/check_os_test.sh index b7364c8f..f1c68942 100644 --- a/tests/unit/check_os_test.sh +++ b/tests/unit/check_os_test.sh @@ -1,24 +1,24 @@ #!/usr/bin/env bash function test_default_os() { - mock uname echo "bogus OS" + bashunit::mock uname echo "bogus OS" check_os::init assert_equals "Unknown" "$_OS" } function test_detect_linux_os() { - mock uname echo "Linux" - mock grep mock_non_existing_fn + bashunit::mock uname echo "Linux" + bashunit::mock grep mock_non_existing_fn check_os::init assert_equals "Linux" "$_OS" } function test_detect_alpine_linux_os() { - mock uname echo "Linux" - mock check_os::is_ubuntu mock_false - mock check_os::is_alpine mock_true + bashunit::mock uname echo "Linux" + bashunit::mock check_os::is_ubuntu mock_false + bashunit::mock check_os::is_alpine mock_true check_os::init assert_equals "Linux" "$_OS" @@ -26,15 +26,15 @@ function test_detect_alpine_linux_os() { } function test_detect_alpine_os_file() { - mock uname echo "Linux" - mock check_os::is_ubuntu mock_false - mock check_os::is_alpine mock_true + bashunit::mock uname echo "Linux" + bashunit::mock check_os::is_ubuntu mock_false + bashunit::mock check_os::is_alpine mock_true assert_successful_code "$(check_os::is_alpine)" } function test_detect_osx_os() { - mock uname echo "Darwin" + bashunit::mock uname echo "Darwin" check_os::init assert_equals "OSX" "$_OS" @@ -43,26 +43,26 @@ function test_detect_osx_os() { # @data_provider window_linux_variations function test_detect_windows_os() { local windows_linux="$1" - mock uname echo "$windows_linux" + bashunit::mock uname echo "$windows_linux" check_os::init assert_equals "Windows" "$_OS" } function window_linux_variations() { - data_set "MINGW" - data_set "junkMINGWjunk" - data_set "MSYS_NT-10.0" - data_set "junkMSYSjunk" - data_set "CYGWIN_NT-10.0" - data_set "junkCYGWINjunk" + bashunit::data_set "MINGW" + bashunit::data_set "junkMINGWjunk" + bashunit::data_set "MSYS_NT-10.0" + bashunit::data_set "junkMSYSjunk" + bashunit::data_set "CYGWIN_NT-10.0" + bashunit::data_set "junkCYGWINjunk" } function test_alpine_is_busybox() { - mock uname echo "Linux" - mock check_os::is_ubuntu mock_false - mock check_os::is_alpine mock_true + bashunit::mock uname echo "Linux" + bashunit::mock check_os::is_ubuntu mock_false + bashunit::mock check_os::is_alpine mock_true check_os::init assert_successful_code "$(check_os::is_alpine)" assert_successful_code "$(check_os::is_busybox)" @@ -70,9 +70,9 @@ function test_alpine_is_busybox() { function test_not_alpine_is_not_busybox() { - mock uname echo "Linux" - mock check_os::is_ubuntu mock_true - mock check_os::is_alpine mock_false + bashunit::mock uname echo "Linux" + bashunit::mock check_os::is_ubuntu mock_true + bashunit::mock check_os::is_alpine mock_false check_os::init assert_general_error "$(check_os::is_alpine)" assert_general_error "$(check_os::is_busybox)" diff --git a/tests/unit/clock_test.sh b/tests/unit/clock_test.sh index 529e6e70..c8b2b295 100644 --- a/tests/unit/clock_test.sh +++ b/tests/unit/clock_test.sh @@ -23,118 +23,118 @@ function mock_date_seconds() { } function test_now_with_perl() { - mock clock::shell_time mock_non_existing_fn - mock perl <<< "1720705883457" - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false + bashunit::mock clock::shell_time mock_non_existing_fn + bashunit::mock perl <<< "1720705883457" + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false assert_same "1720705883457" "$(clock::now)" } function test_now_on_linux_unknown() { mock_unknown_linux_os - mock clock::shell_time mock_non_existing_fn - mock perl mock_non_existing_fn - mock date <<< "1720705883457" - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false + bashunit::mock clock::shell_time mock_non_existing_fn + bashunit::mock perl mock_non_existing_fn + bashunit::mock date <<< "1720705883457" + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false assert_same "1720705883457" "$(clock::now)" } function test_now_on_linux_alpine() { mock_alpine_os - mock clock::shell_time mock_non_existing_fn - mock perl <<< "1720705883457" - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false + bashunit::mock clock::shell_time mock_non_existing_fn + bashunit::mock perl <<< "1720705883457" + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false assert_same "1720705883457" "$(clock::now)" } function test_now_on_windows_without_with_powershell() { mock_windows_os - mock dependencies::has_perl mock_false - mock dependencies::has_powershell mock_true - mock powershell <<< "1727768183281580800" - mock clock::shell_time mock_non_existing_fn - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false + bashunit::mock dependencies::has_perl mock_false + bashunit::mock dependencies::has_powershell mock_true + bashunit::mock powershell <<< "1727768183281580800" + bashunit::mock clock::shell_time mock_non_existing_fn + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false assert_same "1727768183281580800" "$(clock::now)" } function test_now_on_windows_without_without_powershell() { mock_windows_os - mock dependencies::has_perl mock_false - mock dependencies::has_powershell mock_false - mock date <<< "1727768951" - mock clock::shell_time mock_non_existing_fn - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false + bashunit::mock dependencies::has_perl mock_false + bashunit::mock dependencies::has_powershell mock_false + bashunit::mock date <<< "1727768951" + bashunit::mock clock::shell_time mock_non_existing_fn + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false assert_same "1727768951" "$(clock::now)" } function test_now_with_date_seconds_fallback() { mock_unknown_linux_os - mock perl mock_non_existing_fn - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false - mock clock::shell_time mock_non_existing_fn - mock date 'mock_date_seconds "$@"' + bashunit::mock perl mock_non_existing_fn + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false + bashunit::mock clock::shell_time mock_non_existing_fn + bashunit::mock date 'mock_date_seconds "$@"' assert_same "1727768951000000000" "$(clock::now)" } function test_now_on_osx_without_perl() { if check_os::is_windows; then - skip && return + bashunit::skip && return fi mock_macos - mock dependencies::has_perl mock_false - mock clock::shell_time <<< "1727708708.326957" - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false + bashunit::mock dependencies::has_perl mock_false + bashunit::mock clock::shell_time <<< "1727708708.326957" + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false assert_same "1727708708326957000" "$(clock::now)" } function test_runtime_in_milliseconds_when_not_empty_time() { - mock perl <<< "1720705883457" - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false + bashunit::mock perl <<< "1720705883457" + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false assert_not_empty "$(clock::total_runtime_in_milliseconds)" } function test_now_prefers_perl_over_shell_time() { - mock clock::shell_time <<< "1234.0" - mock perl <<< "999999999999" - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false + bashunit::mock clock::shell_time <<< "1234.0" + bashunit::mock perl <<< "999999999999" + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false assert_same "999999999999" "$(clock::now)" } function test_now_prefers_python_over_node() { - mock perl mock_non_existing_fn - mock dependencies::has_python mock_true - mock python <<< "777777777777" - mock dependencies::has_node mock_true - mock node <<< "888888888888" + bashunit::mock perl mock_non_existing_fn + bashunit::mock dependencies::has_python mock_true + bashunit::mock python <<< "777777777777" + bashunit::mock dependencies::has_node mock_true + bashunit::mock node <<< "888888888888" assert_same "777777777777" "$(clock::now)" } function test_runtime_in_milliseconds_when_empty_time() { mock_macos - mock perl mock_non_existing_fn - mock clock::shell_time mock_non_existing_fn - mock dependencies::has_python mock_false - mock dependencies::has_node mock_false - mock date mock_non_existing_fn + bashunit::mock perl mock_non_existing_fn + bashunit::mock clock::shell_time mock_non_existing_fn + bashunit::mock dependencies::has_python mock_false + bashunit::mock dependencies::has_node mock_false + bashunit::mock date mock_non_existing_fn assert_empty "$(clock::total_runtime_in_milliseconds)" } diff --git a/tests/unit/console_results_test.sh b/tests/unit/console_results_test.sh index e5ffb314..14193c68 100644 --- a/tests/unit/console_results_test.sh +++ b/tests/unit/console_results_test.sh @@ -26,7 +26,7 @@ function set_state_value() { # Set the actual variable eval "$var_name='$value'" # Mock the getter function - mock "$getter_name" echo "$value" + bashunit::mock "$getter_name" echo "$value" } function mock_all_state_getters() { @@ -335,11 +335,11 @@ function test_not_render_execution_time() { function test_render_execution_time_on_osx_without_perl() { if ! check_os::is_macos; then - skip && return + bashunit::skip && return fi mock_macos - mock dependencies::has_perl mock_false + bashunit::mock dependencies::has_perl mock_false _START_TIME=1727771758.0664479733 @@ -353,18 +353,18 @@ function test_render_execution_time_on_osx_without_perl() { function test_render_execution_time_on_osx_with_perl() { if ! check_os::is_macos; then - skip && return + bashunit::skip && return fi local render_result mock_macos - mock dependencies::has_adjtimex mock_false - mock dependencies::has_perl mock_true + bashunit::mock dependencies::has_adjtimex mock_false + bashunit::mock dependencies::has_perl mock_true _START_TIME="1726393394574382186" - mock perl <<< "1726393394574372186" - mock uname <<< "Darwin" + bashunit::mock perl <<< "1726393394574372186" + bashunit::mock uname <<< "Darwin" render_result=$( - mock perl <<< "1726393394574372186"; + bashunit::mock perl <<< "1726393394574372186"; console_results::render_result ) diff --git a/tests/unit/custom_assertions_test.sh b/tests/unit/custom_assertions_test.sh index 7c811704..c246b980 100644 --- a/tests/unit/custom_assertions_test.sh +++ b/tests/unit/custom_assertions_test.sh @@ -5,7 +5,7 @@ function _assert_valid_json() { local json="$1" if ! echo "$json" | jq . > /dev/null 2>&1; then - fail "Invalid json: $json" + bashunit::fail "Invalid json: $json" return fi diff --git a/tests/unit/dependencies_test.sh b/tests/unit/dependencies_test.sh index fe8d303f..dc808270 100644 --- a/tests/unit/dependencies_test.sh +++ b/tests/unit/dependencies_test.sh @@ -1,21 +1,21 @@ #!/usr/bin/env bash function test_has_perl_search_path_for_perl() { - spy command + bashunit::spy command dependencies::has_perl assert_have_been_called_with command "-v perl" } function test_has_adjtimex() { - spy command + bashunit::spy command dependencies::has_adjtimex assert_have_been_called_with command "-v adjtimex" } function test_has_bc() { - spy command + bashunit::spy command dependencies::has_bc @@ -23,28 +23,28 @@ function test_has_bc() { } function test_has_awk() { - spy command + bashunit::spy command dependencies::has_awk assert_have_been_called_with command "-v awk" } function test_has_git() { - spy command + bashunit::spy command dependencies::has_git assert_have_been_called_with command "-v git" } function test_has_python() { - spy command + bashunit::spy command dependencies::has_python assert_have_been_called_with command "-v python" } function test_has_node() { - spy command + bashunit::spy command dependencies::has_node assert_have_been_called_with command "-v node" diff --git a/tests/unit/directory_test.sh b/tests/unit/directory_test.sh index 33b40587..b64dc857 100644 --- a/tests/unit/directory_test.sh +++ b/tests/unit/directory_test.sh @@ -2,7 +2,7 @@ # shellcheck disable=SC2155 function test_successful_assert_directory_exists() { - local a_directory="$(current_dir)" + local a_directory="$(bashunit::current_dir)" assert_empty "$(assert_directory_exists "$a_directory")" } @@ -17,7 +17,7 @@ function test_unsuccessful_assert_directory_exists() { } function test_assert_directory_exists_should_not_work_with_files() { - local a_file="$(current_dir)/$(current_filename)" + local a_file="$(bashunit::current_dir)/$(bashunit::current_filename)" assert_same\ "$(console_results::print_failed_test \ @@ -32,7 +32,7 @@ function test_successful_assert_directory_not_exists() { } function test_unsuccessful_assert_directory_not_exists() { - local a_directory="$(current_dir)" + local a_directory="$(bashunit::current_dir)" assert_same\ "$(console_results::print_failed_test \ @@ -41,7 +41,7 @@ function test_unsuccessful_assert_directory_not_exists() { } function test_successful_assert_is_directory() { - local a_directory="$(current_dir)" + local a_directory="$(bashunit::current_dir)" assert_empty "$(assert_is_directory "$a_directory")" } @@ -56,7 +56,7 @@ function test_unsuccessful_assert_is_directory() { } function test_unsuccessful_assert_is_directory_when_a_file_is_given() { - local a_file="$(current_dir)/$(current_filename)" + local a_file="$(bashunit::current_dir)/$(bashunit::current_filename)" assert_same\ "$(console_results::print_failed_test\ @@ -71,7 +71,7 @@ function test_successful_assert_is_directory_empty() { } function test_unsuccessful_assert_is_directory_empty() { - local a_directory="$(current_dir)" + local a_directory="$(bashunit::current_dir)" assert_same\ "$(console_results::print_failed_test \ @@ -80,7 +80,7 @@ function test_unsuccessful_assert_is_directory_empty() { } function test_successful_assert_is_directory_not_empty() { - local a_directory="$(current_dir)" + local a_directory="$(bashunit::current_dir)" assert_empty "$(assert_is_directory_not_empty "$a_directory")" } @@ -101,7 +101,7 @@ function test_successful_assert_is_directory_readable() { } function test_unsuccessful_assert_is_directory_readable_when_a_file_is_given() { - local a_file="$(current_dir)/$(current_filename)" + local a_file="$(bashunit::current_dir)/$(bashunit::current_filename)" assert_same\ "$(console_results::print_failed_test\ @@ -116,7 +116,7 @@ function test_unsuccessful_assert_is_directory_readable_without_execution_permis fi if [[ $EUID -eq 0 ]]; then - skip "running as root" + bashunit::skip "running as root" return fi @@ -136,7 +136,7 @@ function test_unsuccessful_assert_is_directory_readable_without_read_permission( fi if [[ $EUID -eq 0 ]]; then - skip "running as root" + bashunit::skip "running as root" return fi @@ -156,7 +156,7 @@ function test_successful_assert_is_directory_not_readable_without_read_permissio fi if [[ $EUID -eq 0 ]]; then - skip "running as root" + bashunit::skip "running as root" return fi @@ -172,7 +172,7 @@ function test_successful_assert_is_directory_not_readable_without_execution_perm fi if [[ $EUID -eq 0 ]]; then - skip "running as root" + bashunit::skip "running as root" return fi @@ -203,7 +203,7 @@ function test_unsuccessful_assert_is_directory_writable() { fi if [[ $EUID -eq 0 ]]; then - skip "running as root" + bashunit::skip "running as root" return fi @@ -217,7 +217,7 @@ function test_unsuccessful_assert_is_directory_writable() { } function test_unsuccessful_assert_is_directory_writable_when_a_file_is_given() { - local a_file="$(current_dir)/$(current_filename)" + local a_file="$(bashunit::current_dir)/$(bashunit::current_filename)" assert_same\ "$(console_results::print_failed_test\ @@ -232,7 +232,7 @@ function test_successful_assert_is_directory_not_writable() { fi if [[ $EUID -eq 0 ]]; then - skip "running as root" + bashunit::skip "running as root" return fi diff --git a/tests/unit/file_test.sh b/tests/unit/file_test.sh index 5772d66a..986ffbe6 100644 --- a/tests/unit/file_test.sh +++ b/tests/unit/file_test.sh @@ -7,7 +7,7 @@ function set_up() { } function test_successful_assert_file_exists() { - local a_file="$(current_dir)/$(current_filename)" + local a_file="$(bashunit::current_dir)/$(bashunit::current_filename)" assert_empty "$(assert_file_exists "$a_file")" } @@ -21,7 +21,7 @@ function test_unsuccessful_assert_file_exists() { } function test_assert_file_exists_should_not_work_with_folders() { - local a_dir="$(current_dir)" + local a_dir="$(bashunit::current_dir)" assert_same\ "$(console_results::print_failed_test \ @@ -36,7 +36,7 @@ function test_successful_assert_file_not_exists() { } function test_unsuccessful_assert_file_not_exists() { - local a_file="$(current_dir)/$(current_filename)" + local a_file="$(bashunit::current_dir)/$(bashunit::current_filename)" assert_same\ "$(console_results::print_failed_test\ @@ -45,7 +45,7 @@ function test_unsuccessful_assert_file_not_exists() { } function test_successful_assert_is_file() { - local a_file="$(current_dir)/$(current_filename)" + local a_file="$(bashunit::current_dir)/$(bashunit::current_filename)" assert_empty "$(assert_is_file "$a_file")" } @@ -59,7 +59,7 @@ function test_unsuccessful_assert_is_file() { } function test_unsuccessful_assert_is_file_when_a_folder_is_given() { - local a_folder="$(current_dir)" + local a_folder="$(bashunit::current_dir)" assert_same\ "$(console_results::print_failed_test\ @@ -77,7 +77,7 @@ function test_successful_assert_is_file_empty() { } function test_unsuccessful_assert_is_file_empty() { - local a_file="$(current_dir)/$(current_filename)" + local a_file="$(bashunit::current_dir)/$(bashunit::current_filename)" assert_same\ "$(console_results::print_failed_test\ diff --git a/tests/unit/fixtures/find_total_tests/provider_test.sh b/tests/unit/fixtures/find_total_tests/provider_test.sh index a6006774..5befcfa2 100644 --- a/tests/unit/fixtures/find_total_tests/provider_test.sh +++ b/tests/unit/fixtures/find_total_tests/provider_test.sh @@ -6,7 +6,7 @@ function test_with_provider() { } function provider_lines() { - data_set "alpha beta" - data_set "gamma" - data_set "delta epsilon zeta" + bashunit::data_set "alpha beta" + bashunit::data_set "gamma" + bashunit::data_set "delta epsilon zeta" } diff --git a/tests/unit/globals_test.sh b/tests/unit/globals_test.sh index da12ec26..0c2a3200 100644 --- a/tests/unit/globals_test.sh +++ b/tests/unit/globals_test.sh @@ -5,8 +5,8 @@ set -euo pipefail function set_up_before_script() { - SCRIPT_TEMP_FILE=$(temp_file "custom-prefix") - SCRIPT_TEMP_DIR=$(temp_dir "custom-prefix") + SCRIPT_TEMP_FILE=$(bashunit::temp_file "custom-prefix") + SCRIPT_TEMP_DIR=$(bashunit::temp_dir "custom-prefix") } function tear_down_after_script() { @@ -14,7 +14,7 @@ function tear_down_after_script() { } function set_up() { - BASHUNIT_DEV_LOG=$(temp_file) + BASHUNIT_DEV_LOG=$(bashunit::temp_file) export BASHUNIT_DEV_LOG } @@ -23,109 +23,109 @@ function tear_down() { } function test_globals_current_dir() { - assert_same "tests/unit" "$(current_dir)" + assert_same "tests/unit" "$(bashunit::current_dir)" } function test_globals_current_filename() { - assert_same "globals_test.sh" "$(current_filename)" + assert_same "globals_test.sh" "$(bashunit::current_filename)" } function test_globals_caller_filename() { - assert_same "./src" "$(caller_filename)" + assert_same "./src" "$(bashunit::caller_filename)" } function test_globals_caller_line() { - assert_matches "[0-9]*" "$(caller_line)" + assert_matches "[0-9]*" "$(bashunit::caller_line)" } function test_globals_current_timestamp() { assert_matches \ "^[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$" \ - "$(current_timestamp)" + "$(bashunit::current_timestamp)" } function test_globals_is_command_available() { function existing_fn(){ return 0 } - assert_successful_code "$(is_command_available existing_fn)" + assert_successful_code "$(bashunit::is_command_available existing_fn)" } function test_globals_is_command_not_available() { - assert_general_error "$(is_command_available non_existing_fn)" + assert_general_error "$(bashunit::is_command_available non_existing_fn)" } function test_globals_random_str_default_len() { - assert_matches "^[A-Za-z0-9]{6}$" "$(random_str)" + assert_matches "^[A-Za-z0-9]{6}$" "$(bashunit::random_str)" } function test_globals_random_str_custom_len() { - assert_matches "^[A-Za-z0-9]{3}$" "$(random_str 3)" + assert_matches "^[A-Za-z0-9]{3}$" "$(bashunit::random_str 3)" } function test_globals_temp_file_in_test_function() { # shellcheck disable=SC2155 - local temp_file=$(temp_file "custom-prefix") + local temp_file=$(bashunit::temp_file "custom-prefix") assert_file_exists "$temp_file" - cleanup_testcase_temp_files + bashunit::cleanup_testcase_temp_files assert_file_not_exists "$temp_file" } function test_globals_temp_dir_in_test_function() { # shellcheck disable=SC2155 - local temp_dir=$(temp_dir "custom-prefix") + local temp_dir=$(bashunit::temp_dir "custom-prefix") assert_directory_exists "$temp_dir" - cleanup_testcase_temp_files + bashunit::cleanup_testcase_temp_files assert_directory_not_exists "$temp_dir" } function test_globals_temp_dir_and_file_in_script() { assert_directory_exists "$SCRIPT_TEMP_DIR" assert_file_exists "$SCRIPT_TEMP_FILE" - cleanup_script_temp_files + bashunit::cleanup_script_temp_files assert_directory_not_exists "$SCRIPT_TEMP_DIR" assert_file_not_exists "$SCRIPT_TEMP_FILE" } function test_globals_log_level_error() { - log "error" "hello," "error" + bashunit::log "error" "hello," "error" assert_file_contains "$BASHUNIT_DEV_LOG" "[ERROR]: hello, error" } function test_globals_log_level_warning() { - log "warning" "hello," "warning" + bashunit::log "warning" "hello," "warning" assert_file_contains "$BASHUNIT_DEV_LOG" "[WARNING]: hello, warning" } function test_globals_log_level_debug() { - log "debug" "hello," "debug" + bashunit::log "debug" "hello," "debug" assert_file_contains "$BASHUNIT_DEV_LOG" "[DEBUG]: hello, debug" } function test_globals_log_level_critical() { - log "critical" "hello," "critical" + bashunit::log "critical" "hello," "critical" assert_file_contains "$BASHUNIT_DEV_LOG" "[CRITICAL]: hello, critical" } function test_globals_log_level_info() { - log "info" "hello," "info" + bashunit::log "info" "hello," "info" assert_file_contains "$BASHUNIT_DEV_LOG" "[INFO]: hello, info" } function test_globals_log_level_default() { - log "hello," "info" + bashunit::log "hello," "info" assert_file_contains "$BASHUNIT_DEV_LOG" "[INFO]: hello, info" } function test_internal_log_prefix() { export BASHUNIT_INTERNAL_LOG=true - internal_log "info" "some" "message" + bashunit::internal_log "info" "some" "message" export BASHUNIT_INTERNAL_LOG=false assert_file_contains "$BASHUNIT_DEV_LOG" "[INTERNAL]: info some message" diff --git a/tests/unit/helpers_test.sh b/tests/unit/helpers_test.sh index bb5b2f59..d14a5815 100644 --- a/tests/unit/helpers_test.sh +++ b/tests/unit/helpers_test.sh @@ -35,7 +35,7 @@ function test_normalize_test_function_name_camel_case() { } function test_normalize_test_function_name_custom_title() { - set_test_title "🔥 handles invalid input with 💣" + bashunit::set_test_title "🔥 handles invalid input with 💣" assert_same "🔥 handles invalid input with 💣" "$(helper::normalize_test_function_name "test_handles_invalid_input")" } @@ -102,21 +102,21 @@ function test_successful_unset_if_exists() { function test_check_duplicate_functions_with_duplicates() { local file - file="$(current_dir)/fixtures/duplicate_functions.sh" + file="$(bashunit::current_dir)/fixtures/duplicate_functions.sh" assert_general_error "$(helper::check_duplicate_functions "$file")" } function test_check_duplicate_functions_without_duplicates() { local file - file="$(current_dir)/fixtures/no_duplicate_functions.sh" + file="$(bashunit::current_dir)/fixtures/no_duplicate_functions.sh" assert_successful_code "$(helper::check_duplicate_functions "$file")" } function test_check_duplicate_functions_without_function_keyword() { local file - file="$(current_dir)/fixtures/no_function_keyword_duplicates.sh" + file="$(bashunit::current_dir)/fixtures/no_function_keyword_duplicates.sh" assert_general_error "$(helper::check_duplicate_functions "$file")" } @@ -150,7 +150,7 @@ function test_get_provider_data() { function fake_provider_data_array() { local data=("one" "two" "three") - data_set "${data[@]}" + bashunit::data_set "${data[@]}" } function test_get_provider_data_array() { @@ -189,7 +189,7 @@ function test_trim() { function test_find_files_recursive_given_file() { local path - path="$(current_dir)/fixtures/tests/example1_test.sh" + path="$(bashunit::current_dir)/fixtures/tests/example1_test.sh" local result result=$(helper::find_files_recursive "$path") @@ -199,7 +199,7 @@ function test_find_files_recursive_given_file() { function test_find_files_recursive_given_dir() { local path - path="$(current_dir)/fixtures/tests" + path="$(bashunit::current_dir)/fixtures/tests" local result result=$(helper::find_files_recursive "$path") @@ -212,7 +212,7 @@ tests/unit/fixtures/tests/example3_test.bash"\ function test_find_files_recursive_given_wildcard() { local path - path="$(current_dir)/fixtures/tests/*2_test.sh" + path="$(bashunit::current_dir)/fixtures/tests/*2_test.sh" local result result=$(helper::find_files_recursive "$path") @@ -222,7 +222,7 @@ function test_find_files_recursive_given_wildcard() { function test_find_files_recursive_given_bash_extension() { local path - path="$(current_dir)/fixtures/tests/*3_test.bash" + path="$(bashunit::current_dir)/fixtures/tests/*3_test.bash" local result result=$(helper::find_files_recursive "$path") @@ -231,7 +231,7 @@ function test_find_files_recursive_given_bash_extension() { } function test_get_latest_tag() { - mock git< Date: Sat, 6 Dec 2025 15:31:48 +0100 Subject: [PATCH 2/3] fix: linter --- tests/acceptance/bashunit_fail_test.sh | 4 ++-- tests/acceptance/bashunit_pass_test.sh | 4 ++-- tests/acceptance/bashunit_stop_on_failure_test.sh | 2 +- tests/unit/assert_snapshot_test.sh | 6 ++++-- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/acceptance/bashunit_fail_test.sh b/tests/acceptance/bashunit_fail_test.sh index 126de6e1..8afabb43 100644 --- a/tests/acceptance/bashunit_fail_test.sh +++ b/tests/acceptance/bashunit_fail_test.sh @@ -21,7 +21,7 @@ function test_bashunit_when_a_test_fail_verbose_output_option() { } function test_different_verbose_snapshots_matches() { - bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?" } function test_bashunit_when_a_test_fail_simple_output_env() { @@ -53,5 +53,5 @@ function test_bashunit_with_a_test_fail_and_exit_immediately() { } function test_different_simple_snapshots_matches() { - bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?" } diff --git a/tests/acceptance/bashunit_pass_test.sh b/tests/acceptance/bashunit_pass_test.sh index c623d7e4..9297f445 100644 --- a/tests/acceptance/bashunit_pass_test.sh +++ b/tests/acceptance/bashunit_pass_test.sh @@ -21,7 +21,7 @@ function test_bashunit_when_a_test_passes_verbose_output_option() { } function test_different_verbose_snapshots_matches() { - bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?" } function test_bashunit_when_a_test_passes_simple_output_env() { @@ -39,5 +39,5 @@ function test_bashunit_when_a_test_passes_simple_output_option() { } function test_different_simple_snapshots_matches() { - bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?" } diff --git a/tests/acceptance/bashunit_stop_on_failure_test.sh b/tests/acceptance/bashunit_stop_on_failure_test.sh index 1c1e4e37..ff55b0bd 100644 --- a/tests/acceptance/bashunit_stop_on_failure_test.sh +++ b/tests/acceptance/bashunit_stop_on_failure_test.sh @@ -21,7 +21,7 @@ function test_bashunit_when_stop_on_failure_env() { } function test_different_snapshots_matches() { - bashunit::todo "The different snapshots for these tests should also be identical to each other, option to choose snapshot name?" + bashunit::todo "The different snapshots for these tests should also be identical, option to choose snapshot name?" } function test_bashunit_when_stop_on_failure_env_simple_output() { diff --git a/tests/unit/assert_snapshot_test.sh b/tests/unit/assert_snapshot_test.sh index 1b00bd1a..a1a5c0ed 100644 --- a/tests/unit/assert_snapshot_test.sh +++ b/tests/unit/assert_snapshot_test.sh @@ -62,7 +62,8 @@ function test_assert_match_snapshot_with_placeholder() { bashunit::skip "perl not available" && return fi - local snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_placeholder.snapshot" + local snapshot_path + snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_placeholder.snapshot" echo 'Run at ::ignore::' > "$snapshot_path" assert_empty "$(assert_match_snapshot "Run at $(date -u '+%F %T UTC')" "$snapshot_path")" @@ -73,7 +74,8 @@ function test_assert_match_snapshot_with_custom_placeholder() { bashunit::skip "perl not available" && return fi - local snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_custom_placeholder.snapshot" + local snapshot_path + snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_custom_placeholder.snapshot" echo 'Value __ANY__' > "$snapshot_path" export BASHUNIT_SNAPSHOT_PLACEHOLDER='__ANY__' From 1a39cce6df23e996db5303b436872b0a16f096a2 Mon Sep 17 00:00:00 2001 From: Chemaclass Date: Sat, 6 Dec 2025 15:34:47 +0100 Subject: [PATCH 3/3] fix: linter --- tests/unit/assert_snapshot_test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/assert_snapshot_test.sh b/tests/unit/assert_snapshot_test.sh index a1a5c0ed..18b09295 100644 --- a/tests/unit/assert_snapshot_test.sh +++ b/tests/unit/assert_snapshot_test.sh @@ -69,13 +69,13 @@ function test_assert_match_snapshot_with_placeholder() { assert_empty "$(assert_match_snapshot "Run at $(date -u '+%F %T UTC')" "$snapshot_path")" } -function test_assert_match_snapshot_with_custom_placeholder() { +function test_assert_snapshot_with_custom_placeholder() { if ! dependencies::has_perl; then bashunit::skip "perl not available" && return fi local snapshot_path - snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_assert_match_snapshot_with_custom_placeholder.snapshot" + snapshot_path="$(bashunit::temp_dir)/assert_snapshot_test_sh.test_assert_snapshot_with_custom_placeholder.snapshot" echo 'Value __ANY__' > "$snapshot_path" export BASHUNIT_SNAPSHOT_PLACEHOLDER='__ANY__'