Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose option #374

Merged
merged 5 commits into from
Oct 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- `BASHUNIT_DEV_LOG="dev.log"`
- `BASHUNIT_LOAD_FILE="tests/bootstrap.sh"`
- Add check that git is installed to `install.sh`
- Add `-vvv|--verbose` to display internal details of each test
- Fixed `-S|--stop-on-failure` behaviour
- Improved time taken display
- Improved clean up temporal files and directories
Expand Down
3 changes: 3 additions & 0 deletions bashunit
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ while [[ $# -gt 0 ]]; do
export BASHUNIT_REPORT_HTML="$2";
shift
;;
-vvv|--verbose)
export BASHUNIT_VERBOSE=true
;;
-v|--version)
console_header::print_version
trap '' EXIT && exit 0
Expand Down
15 changes: 15 additions & 0 deletions docs/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,21 @@ to make this behavior permanent.
```
:::

## Verbose

> `bashunit -vvv|--verbose`

Display internal details for each test

You can use `BASHUNIT_VERBOSE` option in your [configuration](/configuration#verbose)
to make this behavior permanent.

::: code-group
```bash [Example]
./bashunit --verbose
```
:::

## Version

> `bashunit --version`
Expand Down
14 changes: 14 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,20 @@ log "warning" "different log level messages!"
```
:::

## Verbose

> `BASHUNIT_VERBOSE=bool`

Display internal details for each test.

Similarly, you can use the command line option for this: [command line](/command-line#verbose).

::: code-group
```bash [Example]
BASHUNIT_VERBOSE=true
```
:::

<script setup>
import pkg from '../package.json'
</script>
3 changes: 3 additions & 0 deletions src/console_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ Options:
Print all executed shell commands to the terminal.
If a file-path is passed, it will redirect the output to that file.

-vvv, --verbose
Display internal details for each test.

--version
Displays the current version of bashunit.

Expand Down
6 changes: 6 additions & 0 deletions src/env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ _DEFAULT_SIMPLE_OUTPUT="false"
_DEFAULT_STOP_ON_FAILURE="false"
_DEFAULT_SHOW_EXECUTION_TIME="true"
_DEFAULT_DEV_MODE="false"
_DEFAULT_VERBOSE="false"

: "${BASHUNIT_PARALLEL_RUN:=${PARALLEL_RUN:=$_DEFAULT_PARALLEL_RUN}}"
: "${BASHUNIT_SHOW_HEADER:=${SHOW_HEADER:=$_DEFAULT_SHOW_HEADER}}"
Expand All @@ -35,6 +36,7 @@ _DEFAULT_DEV_MODE="false"
: "${BASHUNIT_STOP_ON_FAILURE:=${STOP_ON_FAILURE:=$_DEFAULT_STOP_ON_FAILURE}}"
: "${BASHUNIT_SHOW_EXECUTION_TIME:=${SHOW_EXECUTION_TIME:=$_DEFAULT_SHOW_EXECUTION_TIME}}"
: "${BASHUNIT_DEV_MODE:=${DEV_MODE:=$_DEFAULT_DEV_MODE}}"
: "${BASHUNIT_VERBOSE:=${VERBOSE:=$_DEFAULT_VERBOSE}}"

function env::is_parallel_run_enabled() {
[[ "$BASHUNIT_PARALLEL_RUN" == "true" ]]
Expand Down Expand Up @@ -64,6 +66,10 @@ function env::is_dev_mode_enabled() {
[[ "$BASHUNIT_DEV_MODE" == "true" ]]
}

function env::is_verbose_enabled() {
[[ "$BASHUNIT_VERBOSE" == "true" ]]
}

function env::find_terminal_width() {
local cols=""

Expand Down
21 changes: 17 additions & 4 deletions src/runner.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,23 @@ function runner::run_test() {
# Closes FD 3, which was used temporarily to hold the original stdout.
exec 3>&-

local end_time=$(clock::now)
local duration_ns=$(math::calculate "($end_time - $start_time) ")
local duration=$(math::calculate "$duration_ns / 1000000")

if env::is_verbose_enabled; then
if env::is_simple_output_enabled; then
echo ""
fi

printf '%*s\n' "$TERMINAL_WIDTH" '' | tr ' ' '='
printf "%s\n" "File: $test_file"
printf "%s\n" "Function: $function_name"
printf "%s\n" "Duration: $duration ms"
printf "%s\n" "##ASSERTIONS_${test_execution_result#*##ASSERTIONS_}"
printf '%*s\n' "$TERMINAL_WIDTH" '' | tr ' ' '-'
fi

local subshell_output=$(runner::decode_subshell_output "$test_execution_result")

if [[ -n "$subshell_output" ]]; then
Expand Down Expand Up @@ -175,10 +192,6 @@ function runner::run_test() {

local total_assertions="$(state::calculate_total_assertions "$test_execution_result")"

local end_time=$(clock::now)
local duration_ns=$(math::calculate "($end_time - $start_time) ")
local duration=$(math::calculate "$duration_ns / 1000000")

if [[ -n $runtime_error ]]; then
state::add_tests_failed
console_results::print_error_test "$function_name" "$runtime_error"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/fixtures/.env.default
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ BASHUNIT_HEADER_ASCII_ART=false
BASHUNIT_SIMPLE_OUTPUT=false
BASHUNIT_STOP_ON_FAILURE=false
BASHUNIT_SHOW_EXECUTION_TIME=false
BASHUNIT_VERBOSE=false
1 change: 1 addition & 0 deletions tests/acceptance/fixtures/.env.log_junit
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ BASHUNIT_HEADER_ASCII_ART=false
BASHUNIT_SIMPLE_OUTPUT=false
BASHUNIT_STOP_ON_FAILURE=false
BASHUNIT_SHOW_EXECUTION_TIME=false
BASHUNIT_VERBOSE=false
1 change: 1 addition & 0 deletions tests/acceptance/fixtures/.env.report_html
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ BASHUNIT_HEADER_ASCII_ART=false
BASHUNIT_SIMPLE_OUTPUT=false
BASHUNIT_STOP_ON_FAILURE=false
BASHUNIT_SHOW_EXECUTION_TIME=false
BASHUNIT_VERBOSE=false
1 change: 1 addition & 0 deletions tests/acceptance/fixtures/.env.simple
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ BASHUNIT_HEADER_ASCII_ART=false
BASHUNIT_SIMPLE_OUTPUT=true
BASHUNIT_STOP_ON_FAILURE=false
BASHUNIT_SHOW_EXECUTION_TIME=false
BASHUNIT_VERBOSE=false
1 change: 1 addition & 0 deletions tests/acceptance/fixtures/.env.stop_on_failure
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ BASHUNIT_HEADER_ASCII_ART=false
BASHUNIT_SIMPLE_OUTPUT=false
BASHUNIT_STOP_ON_FAILURE=true
BASHUNIT_SHOW_EXECUTION_TIME=false
BASHUNIT_VERBOSE=false
1 change: 1 addition & 0 deletions tests/acceptance/fixtures/.env.with_path
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ BASHUNIT_HEADER_ASCII_ART=false
BASHUNIT_SIMPLE_OUTPUT=false
BASHUNIT_STOP_ON_FAILURE=false
BASHUNIT_SHOW_EXECUTION_TIME=false
BASHUNIT_VERBOSE=false
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ Options:
Print all executed shell commands to the terminal.
If a file-path is passed, it will redirect the output to that file.

-vvv, --verbose
Display internal details for each test.

--version
Displays the current version of bashunit.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ Options:
Print all executed shell commands to the terminal.
If a file-path is passed, it will redirect the output to that file.

-vvv, --verbose
Display internal details for each test.

--version
Displays the current version of bashunit.

Expand Down
Loading