Skip to content

Commit

Permalink
feat: rename LOAD_FILE to BOOTSTRAP
Browse files Browse the repository at this point in the history
  • Loading branch information
Chemaclass committed Oct 16, 2024
1 parent 848c257 commit 682394f
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 45 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ indent_size = 2
[{Makefile,**.mk,.git*}]
indent_style = tab

[{tests/acceptance/**.sh,src/console_header.sh}]
[{tests/acceptance/**.sh,src/console_header.sh,docs/command-line.md}]
indent_size = unset
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BASHUNIT_DEFAULT_PATH=
BASHUNIT_DEV_LOG=
BASHUNIT_LOAD_FILE=
BASHUNIT_BOOTSTRAP=
BASHUNIT_LOG_JUNIT=
BASHUNIT_REPORT_HTML=

Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- log
- Add default env values:
- `BASHUNIT_DEFAULT_PATH="tests"`
- `BASHUNIT_LOAD_FILE="tests/bootstrap.sh"`
- `BASHUNIT_BOOTSTRAP="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
Expand All @@ -43,7 +43,7 @@
- Added failing tests after running the entire suite
- Improved runtime errors handling
- Simplified total tests display on the header
- Renamed `BASHUNIT_TESTS_ENV` to `BASHUNIT_LOAD_FILE`
- Renamed `BASHUNIT_TESTS_ENV` to `BASHUNIT_BOOTSTRAP`
- Better handler runtime errors
- Display failing tests after running the entire suite
- Added defer expressions with `eval` when using standalone assertions
Expand Down
4 changes: 2 additions & 2 deletions bashunit
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ while [[ $# -gt 0 ]]; do
--no-parallel)
export BASHUNIT_PARALLEL_RUN=false
;;
-e|--env|--load)
-e|--env|--boot)
# shellcheck disable=SC1090
source "$2"
shift
Expand Down Expand Up @@ -108,7 +108,7 @@ while [[ $# -gt 0 ]]; do
done

# shellcheck disable=SC1090
[[ -f "$BASHUNIT_LOAD_FILE" ]] && source "$BASHUNIT_LOAD_FILE"
[[ -f "$BASHUNIT_BOOTSTRAP" ]] && source "$BASHUNIT_BOOTSTRAP"

set +eu

Expand Down
2 changes: 1 addition & 1 deletion docs/blog/2024-10-01-release-0-17.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Testing.php:3:Method Testing::bar() has no return type specified.

* Add support for Alpine (Linux Distro) in [#331](https://github.com/TypedDevs/bashunit/pull/331)
* Improve debug output [#332](https://github.com/TypedDevs/bashunit/pull/332)
* Improve loading extra file with BASHUNIT_LOAD_FILE [#330](https://github.com/TypedDevs/bashunit/pull/330)
* Enable loading extra file with BASHUNIT_BOOTSTRAP [#330](https://github.com/TypedDevs/bashunit/pull/330)
* Remove deprecated assertions [#344](https://github.com/TypedDevs/bashunit/pull/344)
* Some required dependencies now optional: perl, coreutils [#345](https://github.com/TypedDevs/bashunit/pull/345)
* Upgrade and install script can now use `wget` if `curl` is not installed [#345](https://github.com/TypedDevs/bashunit/pull/345)
Expand Down
176 changes: 148 additions & 28 deletions docs/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,32 +45,35 @@ Run a core assert function standalone without a test context. Read more: [Standa
```
:::

## Debug
## Bootstrap

> `bashunit --debug <?file-path>`
> `bashunit -e|--env|--boot "file path"`
Enables a shell mode in which all executed commands are printed to the terminal,
or printed into a file if this is specified.
Load a custom file, overriding the existing `.env` variables or loading a bootstrap file.

Printing every command as executed may help you visualize the script's control flow if it is not working as expected.
> You can use `BASHUNIT_BOOTSTRAP` option in your [configuration](/configuration#bootstrap).
::: code-group
```bash [Example]
./bashunit --debug local/debug.sh
```bash [Example: --boot]
./bashunit tests --boot tests/globals.sh
```
```bash [Example: --env]
./bashunit tests --env .env.tests
```
:::

## Environment
## Debug

> `bashunit -e|--env|--load "file path"`
> `bashunit --debug <?file-path>`
Load a custom file, overriding the existing `.env` variables or loading a file with global functions.
Enables a shell mode in which all executed commands are printed to the terminal,
or printed into a file if this is specified.

You can use `BASHUNIT_LOAD_FILE` option in your [configuration](/configuration#tests-env).
Printing every command as executed may help you visualize the script's control flow if it is not working as expected.

::: code-group
```bash [Example]
./bashunit tests --env .env.tests
./bashunit --debug local/debug.sh
```
:::

Expand All @@ -82,12 +85,12 @@ Filters the tests to be run based on the `test name`.

::: code-group
```bash [Example]
# run all test functions including "something" in it's name
# run all test functions including "something" in the name
./bashunit ./tests --filter "something"
```
:::

## Logging
## JUnit Logging

> `bashunit -l|--log-junit <out.xml>`
Expand All @@ -97,6 +100,27 @@ Creates a report XML file that follows the JUnit XML format and contains informa
```bash [Example]
./bashunit ./tests --log-junit log-junit.xml
```
```xml [log-junit.xml]
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="bashunit" tests="340"
passed="328" failures="0" incomplete="10"
skipped="1" snapshot="1"
time="43344">
<testcase file="tests/acceptance/bashunit_direct_fn_call_test.sh"
name="test_bashunit_direct_fn_call_passes"
status="passed"
assertions="1"
time="45">
</testcase>
<testcase file="tests/acceptance/bashunit_direct_fn_call_test.sh"
name="test_bashunit_direct_fn_call_without_assert_prefix_passes"
status="passed"
assertions="1"
time="51">
</testcase>
... etc
```
:::

## Parallel
Expand All @@ -121,7 +145,7 @@ You can use `BASHUNIT_PARALLEL_RUN` option in your [configuration](/configuratio
If parallel testing is enabled by default or within a script, you can disable it using the --no-parallel option. This is useful if you need to run tests in sequence or if parallel execution is causing issues during debugging.

## Report
## HTML report

> `bashunit -r|--report-html <out.html>`
Expand All @@ -131,13 +155,67 @@ Creates a report HTML file that contains information about the test results of y
```bash [Example]
./bashunit ./tests --report-html report.html
```

```html [report.html]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Report</title>
<style>
body { font-family: Arial, sans-serif; }
table { width: 100%; border-collapse: collapse; }
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
th { background-color: #f2f2f2; }
.passed { background-color: #dff0d8; }
.failed { background-color: #f2dede; }
.skipped { background-color: #fcf8e3; }
.incomplete { background-color: #d9edf7; }
.snapshot { background-color: #dfe6e9; }
</style>
</head>
<body>
<h1>Test Report</h1>
<table>
<thead>
<tr>
<th>Total Tests</th>
<th>Passed</th>
<th>Failed</th>
<th>Incomplete</th>
<th>Skipped</th>
<th>Snapshot</th>
<th>Time (ms)</th>
</tr>
</thead>
<tbody>
<tr>
<td>340</td>
<td>328</td>
<td>0</td>
<td>10</td>
<td>1</td>
<td>1</td>
<td>46811</td>
</tr>
</tbody>
</table>
<p>Time: 46811 ms</p>
<h2>File: tests/acceptance/bashunit_direct_fn_call_test.sh</h2>
<table>
<thead>
<tr>
<th>Test Name</th>
... etc
```
:::

## Output

> `bashunit -s|--simple`
>
> `bashunit -vvv|--detailed`
> `bashunit --detailed` [Default]
Enables simplified or verbose output to the console.

Expand All @@ -149,15 +227,18 @@ You can use `BASHUNIT_SIMPLE_OUTPUT` option in your [configuration](/configurati
to choose the default output display.

::: code-group
```[Output]
........
```
```bash [Example]
./bashunit ./tests --simple
```
```[Output]
........
```
:::

::: code-group
```bash [Example]
./bashunit ./tests --detailed
```
```[Output]
Running tests/functional/logic_test.sh
✓ Passed: Other way of using the exit code
Expand All @@ -169,9 +250,6 @@ Running tests/functional/logic_test.sh
✓ Passed: Text should not contain
✓ Passed: Text should not match a regular expression
```
```bash [Example]
./bashunit ./tests --detailed
```
:::

## Stop on failure
Expand Down Expand Up @@ -202,6 +280,45 @@ to make this behavior permanent.
```bash [Example]
./bashunit --verbose
```
```bash [Output]
bashunit - 0.17.0 | Tests: ~333
########################################################################################################################################
Filter: None
Total files: 36
Test files:
- tests/acceptance/bashunit_direct_fn_call_test.sh
- tests/acceptance/bashunit_execution_error_test.sh
- tests/acceptance/bashunit_fail_test.sh
- tests/acceptance/bashunit_find_tests_command_line_test.sh
- tests/acceptance/bashunit_log_junit_test.sh
- ... etc
........................................................................................................................................
BASHUNIT_DEFAULT_PATH: tests
BASHUNIT_DEV_LOG: dev.log
BASHUNIT_BOOTSTRAP: tests/bootstrap.sh
BASHUNIT_LOG_JUNIT: local/log-junit.xml
BASHUNIT_REPORT_HTML: local/report.html
BASHUNIT_PARALLEL_RUN: false
BASHUNIT_SHOW_HEADER: true
BASHUNIT_HEADER_ASCII_ART: false
BASHUNIT_SIMPLE_OUTPUT: false
BASHUNIT_STOP_ON_FAILURE: false
BASHUNIT_SHOW_EXECUTION_TIME: true
BASHUNIT_DEV_MODE: true
BASHUNIT_VERBOSE: true
########################################################################################################################################

Running tests/acceptance/bashunit_direct_fn_call_test.sh
========================================================================================================================================
File: tests/acceptance/bashunit_direct_fn_call_test.sh
Function: test_bashunit_direct_fn_call_passes
Duration: 48 ms
##ASSERTIONS_FAILED=0##ASSERTIONS_PASSED=1##ASSERTIONS_SKIPPED=0##ASSERTIONS_INCOMPLETE=0##ASSERTIONS_SNAPSHOT=0##TEST_OUTPUT=##
----------------------------------------------------------------------------------------------------------------------------------------
✓ Passed: Bashunit direct fn call passes 48 ms
========================================================================================================================================
... etc
```
:::

## Version
Expand All @@ -211,12 +328,12 @@ to make this behavior permanent.
Displays the current version of **bashunit**.

::: code-group
```-vue [Output]
bashunit - {{ pkg.version }}
```
```bash [Example]
./bashunit --version
```
```-vue [Output]
bashunit - {{ pkg.version }}
```
:::

## Upgrade
Expand All @@ -229,6 +346,9 @@ Upgrade **bashunit** to latest version.
```bash [Example]
./bashunit --upgrade
```
```bash [Output]
> You are already on latest version
```
:::

## Help
Expand All @@ -238,6 +358,9 @@ Upgrade **bashunit** to latest version.
Displays a help message with all allowed arguments and options.

::: code-group
```bash [Example]
./bashunit --help
```
```[Output]
bashunit [arguments] [options]
Expand All @@ -250,9 +373,6 @@ Options:
[...]
```
```bash [Example]
./bashunit --help
```
:::

<script setup>
Expand Down
11 changes: 7 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ BASHUNIT_REPORT_HTML=report.html
```
:::

## Load file
## Bootstrap

> `BASHUNIT_LOAD_FILE=file`
> `BASHUNIT_BOOTSTRAP=file`
Specifies an additional file to be loaded for all tests cases.
Useful to set up global variables or functions accessible in all your tests.
Expand All @@ -195,10 +195,13 @@ Similarly, you can use load an additional file via the [command line](/command-l
::: code-group
```bash [Example]
# a simple .env file
BASHUNIT_LOAD_FILE=".env.tests"
BASHUNIT_BOOTSTRAP=".env.tests"

# or a complete script file
BASHUNIT_LOAD_FILE="tests/globals.sh"
BASHUNIT_BOOTSTRAP="tests/globals.sh"

# Default value
BASHUNIT_BOOTSTRAP="tests/bootstrap.sh"
```
:::

Expand Down
2 changes: 1 addition & 1 deletion src/console_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Options:
-a, --assert <function ...args>
Run a core assert function standalone without a test context.
-e, --env, --load <file-path>
-e, --env, --boot <file-path>
Load a custom file, overriding the existing .env variables or loading a file with global functions.
-f, --filter <filter>
Expand Down
Loading

0 comments on commit 682394f

Please sign in to comment.