diff --git a/.env.example b/.env.example index 6e3108a6..5d454a26 100644 --- a/.env.example +++ b/.env.example @@ -1,7 +1,8 @@ BASHUNIT_DEFAULT_PATH= +BASHUNIT_DEV_LOG= +BASHUNIT_LOAD_FILE= BASHUNIT_LOG_JUNIT= BASHUNIT_REPORT_HTML= -BASHUNIT_LOAD_FILE= # Booleans BASHUNIT_PARALLEL_RUN= diff --git a/.gitignore b/.gitignore index 2d402ece..f4c9adaf 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,4 @@ report.html # internal local/ -out.log +dev.log diff --git a/CHANGELOG.md b/CHANGELOG.md index d12d655d..5ff738e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,10 +5,12 @@ - Added `-p|--parallel` to enable running tests in parallel - Added `assert_file_contains` and `assert_file_not_contains` - Added `assert_true` and `assert_false` -- Added `BASHUNIT_LOG_PATH` +- Added `BASHUNIT_DEV_LOG` - Added global util functions - current_dir - current_filename + - caller_filename + - caller_line - current_timestamp - is_command_available - random_str @@ -17,15 +19,17 @@ - cleanup_temp_files - log - Add default env values: - - `DEFAULT_PATH="tests"` - - `LOG_PATH="out.log"` - - `LOAD_FILE="tests/bootstrap.sh"` + - `BASHUNIT_DEFAULT_PATH="tests"` + - `BASHUNIT_DEV_LOG="dev.log"` + - `BASHUNIT_LOAD_FILE="tests/bootstrap.sh"` - Add check that git is installed to `install.sh` - Fixed `-S|--stop-on-failure` behaviour - Improved time taken display - Improved clean up temporal files and directories - Improved CI test speed by running them in parallel - Removed git dependency for stable installations +- Rename option `--verbose` to `--detailed` + - which is the default display behaviour, the opposite as `--simple` ## [0.17.0](https://github.com/TypedDevs/bashunit/compare/0.16.0...0.17.0) - 2024-10-01 diff --git a/bashunit b/bashunit index 98d9a439..8714a3fd 100755 --- a/bashunit +++ b/bashunit @@ -51,7 +51,7 @@ while [[ $# -gt 0 ]]; do -s|--simple) export BASHUNIT_SIMPLE_OUTPUT=true ;; - -vvv|--verbose) + --detailed) export BASHUNIT_SIMPLE_OUTPUT=false ;; --debug) @@ -91,7 +91,7 @@ while [[ $# -gt 0 ]]; do upgrade::upgrade trap '' EXIT && exit 0 ;; - --help) + -h|--help) console_header::print_help trap '' EXIT && exit 0 ;; diff --git a/docs/command-line.md b/docs/command-line.md index c228fc6c..b421408f 100644 --- a/docs/command-line.md +++ b/docs/command-line.md @@ -137,7 +137,7 @@ Creates a report HTML file that contains information about the test results of y > `bashunit -s|--simple` > -> `bashunit -vvv|--verbose` +> `bashunit -vvv|--detailed` Enables simplified or verbose output to the console. @@ -170,7 +170,7 @@ Running tests/functional/logic_test.sh ✓ Passed: Text should not match a regular expression ``` ```bash [Example] -./bashunit ./tests --verbose +./bashunit ./tests --detailed ``` ::: diff --git a/docs/configuration.md b/docs/configuration.md index 32e409e3..3db6ea69 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -38,7 +38,7 @@ Enables simplified output to the console. `false` by default. Verbose is the default output, but it can be overridden by the environment configuration. -Similar as using `-s|--simple | -vvv|--verbose` option on the [command line](/command-line#output). +Similar as using `-s|--simple | -vvv|--detailed` option on the [command line](/command-line#output). ::: code-group ```bash [Simple output] @@ -204,13 +204,13 @@ BASHUNIT_LOAD_FILE="tests/globals.sh" ## Log path -> `BASHUNIT_LOG_PATH=file` +> `BASHUNIT_DEV_LOG=file` > See: [Globals > log](/globals#log) ::: code-group ```bash [Setup] -BASHUNIT_LOG_PATH="out.log" +BASHUNIT_DEV_LOG="out.log" ``` ```bash [Usage] log "I am tracing something..." diff --git a/docs/globals.md b/docs/globals.md index 9261ccad..89e943bf 100644 --- a/docs/globals.md +++ b/docs/globals.md @@ -75,7 +75,7 @@ function test_globals_temp_dir() { ## log -Write into the `BASHUNIT_LOG_PATH` a log message. +Write into the `BASHUNIT_DEV_LOG` a log message. > See: [Log path](/configuration#log-path) diff --git a/src/console_header.sh b/src/console_header.sh index d7ff1472..3b35cdea 100644 --- a/src/console_header.sh +++ b/src/console_header.sh @@ -60,44 +60,41 @@ Arguments: If you use wildcards, bashunit will run any tests it finds. Options: - -a|--assert + -a, --assert Run a core assert function standalone without a test context. - --debug - Print all executed shell commands to the terminal. - If a file-path is passed, it will redirect the output to that file. - - -e|--env|--load + -e, --env, --load Load a custom file, overriding the existing .env variables or loading a file with global functions. - -f|--filter + -f, --filter Filters the tests to run based on the test name. - -l|--log-junit + -l, --log-junit Create a report JUnit XML file that contains information about the test results. - -p|--parallel + -p, --parallel || --no-parallel [default] Run each test in child process, randomizing the tests execution order. - --no-parallel - Disable the --parallel option. Util to disable parallel tests from within another test. - - -r|--report-html + -r, --report-html Create a report HTML file that contains information about the test results. - -s|simple || -v|verbose - Enables simplified or verbose output to the console. + -s, --simple || --detailed [default] + Enables simple or detailed output to the console. - -S|--stop-on-failure + -S, --stop-on-failure Force to stop the runner right after encountering one failing test. + --debug + Print all executed shell commands to the terminal. + If a file-path is passed, it will redirect the output to that file. + --version Displays the current version of bashunit. --upgrade Upgrade to latest version of bashunit. - --help + -h, --help This message. See more: https://bashunit.typeddevs.com/command-line diff --git a/src/env.sh b/src/env.sh index 3188eaf8..33f0a354 100644 --- a/src/env.sh +++ b/src/env.sh @@ -8,16 +8,16 @@ set -o allexport set +o allexport _DEFAULT_DEFAULT_PATH="tests" -_DEFAULT_LOG_PATH="out.log" +_DEFAULT_DEV_LOG="dev.log" _DEFAULT_LOAD_FILE="tests/bootstrap.sh" _DEFAULT_LOG_JUNIT="" _DEFAULT_REPORT_HTML="" : "${BASHUNIT_DEFAULT_PATH:=${DEFAULT_PATH:=$_DEFAULT_DEFAULT_PATH}}" +: "${BASHUNIT_DEV_LOG:=${DEV_LOG:=$_DEFAULT_DEV_LOG}}" +: "${BASHUNIT_LOAD_FILE:=${LOAD_FILE:=$_DEFAULT_LOAD_FILE}}" : "${BASHUNIT_LOG_JUNIT:=${LOG_JUNIT:=$_DEFAULT_LOG_JUNIT}}" -: "${BASHUNIT_LOG_PATH:=${LOG_PATH:=$_DEFAULT_LOG_PATH}}" : "${BASHUNIT_REPORT_HTML:=${REPORT_HTML:=$_DEFAULT_REPORT_HTML}}" -: "${BASHUNIT_LOAD_FILE:=${LOAD_FILE:=$_DEFAULT_LOAD_FILE}}" # Booleans _DEFAULT_PARALLEL_RUN="false" diff --git a/src/globals.sh b/src/globals.sh index 515cd73c..4ff70e2c 100644 --- a/src/globals.sh +++ b/src/globals.sh @@ -11,6 +11,14 @@ function current_filename() { basename "${BASH_SOURCE[1]}" } +function caller_filename() { + dirname "${BASH_SOURCE[2]}" +} + +function caller_line() { + echo "${BASH_LINENO[1]}" +} + function current_timestamp() { date +"%Y-%m-%d %H:%M:%S" } @@ -54,5 +62,5 @@ function log() { *) set -- "$level $@"; level="INFO" ;; esac - echo "$(current_timestamp) [$level]: $@" >> "$BASHUNIT_LOG_PATH" + echo "$(current_timestamp) [$level]: $@" >> "$BASHUNIT_DEV_LOG" } diff --git a/tests/acceptance/bashunit_fail_test.sh b/tests/acceptance/bashunit_fail_test.sh index 08b23fec..03604036 100644 --- a/tests/acceptance/bashunit_fail_test.sh +++ b/tests/acceptance/bashunit_fail_test.sh @@ -16,8 +16,8 @@ function test_bashunit_when_a_test_fail_verbose_output_env() { function test_bashunit_when_a_test_fail_verbose_output_option() { local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_test_fail.sh - assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_SIMPLE" "$test_file" --verbose)" - assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_SIMPLE" "$test_file" --verbose)" + assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_SIMPLE" "$test_file" --detailed)" + assert_general_error "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_SIMPLE" "$test_file" --detailed)" } function test_different_verbose_snapshots_matches() { diff --git a/tests/acceptance/bashunit_pass_test.sh b/tests/acceptance/bashunit_pass_test.sh index 4d71a6f3..2159ccf4 100644 --- a/tests/acceptance/bashunit_pass_test.sh +++ b/tests/acceptance/bashunit_pass_test.sh @@ -16,8 +16,8 @@ function test_bashunit_when_a_test_passes_verbose_output_env() { function test_bashunit_when_a_test_passes_verbose_output_option() { local test_file=./tests/acceptance/fixtures/test_bashunit_when_a_test_passes.sh - assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_SIMPLE" "$test_file" --verbose)" - assert_successful_code "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_SIMPLE" "$test_file" --verbose)" + assert_match_snapshot "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_SIMPLE" "$test_file" --detailed)" + assert_successful_code "$(./bashunit --no-parallel --env "$TEST_ENV_FILE_SIMPLE" "$test_file" --detailed)" } function test_different_verbose_snapshots_matches() { diff --git a/tests/acceptance/snapshots/bashunit_path_test_sh.test_bashunit_without_path_env_nor_argument.snapshot b/tests/acceptance/snapshots/bashunit_path_test_sh.test_bashunit_without_path_env_nor_argument.snapshot index c0945093..195b3b8b 100644 --- a/tests/acceptance/snapshots/bashunit_path_test_sh.test_bashunit_without_path_env_nor_argument.snapshot +++ b/tests/acceptance/snapshots/bashunit_path_test_sh.test_bashunit_without_path_env_nor_argument.snapshot @@ -7,44 +7,41 @@ Arguments: If you use wildcards, bashunit will run any tests it finds. Options: - -a|--assert + -a, --assert Run a core assert function standalone without a test context. - --debug - Print all executed shell commands to the terminal. - If a file-path is passed, it will redirect the output to that file. - - -e|--env|--load + -e, --env, --load Load a custom file, overriding the existing .env variables or loading a file with global functions. - -f|--filter + -f, --filter Filters the tests to run based on the test name. - -l|--log-junit + -l, --log-junit Create a report JUnit XML file that contains information about the test results. - -p|--parallel + -p, --parallel || --no-parallel [default] Run each test in child process, randomizing the tests execution order. - --no-parallel - Disable the --parallel option. Util to disable parallel tests from within another test. - - -r|--report-html + -r, --report-html Create a report HTML file that contains information about the test results. - -s|simple || -v|verbose - Enables simplified or verbose output to the console. + -s, --simple || --detailed [default] + Enables simple or detailed output to the console. - -S|--stop-on-failure + -S, --stop-on-failure Force to stop the runner right after encountering one failing test. + --debug + Print all executed shell commands to the terminal. + If a file-path is passed, it will redirect the output to that file. + --version Displays the current version of bashunit. --upgrade Upgrade to latest version of bashunit. - --help + -h, --help This message. See more: https://bashunit.typeddevs.com/command-line diff --git a/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_help.snapshot b/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_help.snapshot index 76737976..b870750f 100644 --- a/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_help.snapshot +++ b/tests/acceptance/snapshots/bashunit_test_sh.test_bashunit_should_display_help.snapshot @@ -6,44 +6,41 @@ Arguments: If you use wildcards, bashunit will run any tests it finds. Options: - -a|--assert + -a, --assert Run a core assert function standalone without a test context. - --debug - Print all executed shell commands to the terminal. - If a file-path is passed, it will redirect the output to that file. - - -e|--env|--load + -e, --env, --load Load a custom file, overriding the existing .env variables or loading a file with global functions. - -f|--filter + -f, --filter Filters the tests to run based on the test name. - -l|--log-junit + -l, --log-junit Create a report JUnit XML file that contains information about the test results. - -p|--parallel + -p, --parallel || --no-parallel [default] Run each test in child process, randomizing the tests execution order. - --no-parallel - Disable the --parallel option. Util to disable parallel tests from within another test. - - -r|--report-html + -r, --report-html Create a report HTML file that contains information about the test results. - -s|simple || -v|verbose - Enables simplified or verbose output to the console. + -s, --simple || --detailed [default] + Enables simple or detailed output to the console. - -S|--stop-on-failure + -S, --stop-on-failure Force to stop the runner right after encountering one failing test. + --debug + Print all executed shell commands to the terminal. + If a file-path is passed, it will redirect the output to that file. + --version Displays the current version of bashunit. --upgrade Upgrade to latest version of bashunit. - --help + -h, --help This message. See more: https://bashunit.typeddevs.com/command-line diff --git a/tests/unit/globals_test.sh b/tests/unit/globals_test.sh index c3b59445..cf879169 100644 --- a/tests/unit/globals_test.sh +++ b/tests/unit/globals_test.sh @@ -1,13 +1,13 @@ #!/bin/bash set -euo pipefail -function set_up_before_script() { - BASHUNIT_LOG_PATH=$(temp_file) - export BASHUNIT_LOG_PATH +function set_up() { + BASHUNIT_DEV_LOG=$(temp_file) + export BASHUNIT_DEV_LOG } -function tear_down_after_script() { - rm "$BASHUNIT_LOG_PATH" +function tear_down() { + rm "$BASHUNIT_DEV_LOG" } function test_globals_current_dir() { @@ -18,6 +18,14 @@ function test_globals_current_filename() { assert_same "globals_test.sh" "$(current_filename)" } +function test_globals_caller_filename() { + assert_same "./src" "$(caller_filename)" +} + +function test_globals_caller_line() { + assert_matches "[0-9]*" "$(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}$" \ @@ -36,11 +44,11 @@ function test_globals_is_command_not_available() { assert_general_error "$(is_command_available non_existing_fn)" } -function test_globals_random_str_default() { +function test_globals_random_str_default_len() { assert_matches "^[A-Za-z0-9]{6}$" "$(random_str)" } -function test_globals_random_str_custom() { +function test_globals_random_str_custom_len() { assert_matches "^[A-Za-z0-9]{3}$" "$(random_str 3)" } @@ -63,35 +71,35 @@ function test_globals_temp_dir() { function test_globals_log_level_error() { log "error" "hello," "error" - assert_file_contains "$BASHUNIT_LOG_PATH" "[ERROR]: hello, error" + assert_file_contains "$BASHUNIT_DEV_LOG" "[ERROR]: hello, error" } function test_globals_log_level_warning() { log "warning" "hello," "warning" - assert_file_contains "$BASHUNIT_LOG_PATH" "[WARNING]: hello, warning" + assert_file_contains "$BASHUNIT_DEV_LOG" "[WARNING]: hello, warning" } function test_globals_log_level_debug() { log "debug" "hello," "debug" - assert_file_contains "$BASHUNIT_LOG_PATH" "[DEBUG]: hello, debug" + assert_file_contains "$BASHUNIT_DEV_LOG" "[DEBUG]: hello, debug" } function test_globals_log_level_critical() { log "critical" "hello," "critical" - assert_file_contains "$BASHUNIT_LOG_PATH" "[CRITICAL]: hello, critical" + assert_file_contains "$BASHUNIT_DEV_LOG" "[CRITICAL]: hello, critical" } function test_globals_log_level_info() { log "info" "hello," "info" - assert_file_contains "$BASHUNIT_LOG_PATH" "[INFO]: hello, info" + assert_file_contains "$BASHUNIT_DEV_LOG" "[INFO]: hello, info" } function test_globals_log_level_default() { log "hello," "info" - assert_file_contains "$BASHUNIT_LOG_PATH" "[INFO]: hello, info" + assert_file_contains "$BASHUNIT_DEV_LOG" "[INFO]: hello, info" }