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

Fix strictmode #285

Merged
merged 4 commits into from
Jul 12, 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- Support for displaying the clock without `perl` (for non-macOS)
- Add `-l|--log-junit <log.xml>` option
- Add `-r|--report-html <report.html>` option
- Foundation to enable strictmode
- Enable strictmode

## [0.13.0](https://github.com/TypedDevs/bashunit/compare/0.12.0...0.13.0) - 2024-06-23

Expand Down
16 changes: 10 additions & 6 deletions bashunit
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/bin/bash
set -euo pipefail

# shellcheck disable=SC2034
declare -r BASHUNIT_VERSION="0.13.0"

readonly BASHUNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
# shellcheck disable=SC2155
declare -r BASHUNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
export BASHUNIT_ROOT_DIR

source "$BASHUNIT_ROOT_DIR/src/default_env_config.sh"
Expand Down Expand Up @@ -40,15 +42,15 @@ while [[ $# -gt 0 ]]; do
shift
;;
-s|--simple)
SIMPLE_OUTPUT=true
export SIMPLE_OUTPUT=true
shift
;;
-v|--verbose)
SIMPLE_OUTPUT=false
export SIMPLE_OUTPUT=false
shift
;;
-S|--stop-on-failure)
STOP_ON_FAILURE=true
export STOP_ON_FAILURE=true
shift
;;
-e|--env)
Expand All @@ -58,12 +60,12 @@ while [[ $# -gt 0 ]]; do
shift
;;
-l|--log-junit)
LOG_JUNIT="$2";
export LOG_JUNIT="$2";
shift
shift
;;
-r|--report-html)
REPORT_HTML="$2";
export REPORT_HTML="$2";
shift
shift
;;
Expand All @@ -88,6 +90,8 @@ while [[ $# -gt 0 ]]; do
esac
done

set +eu

if [[ -n "$_ASSERT_FN" ]]; then
main::exec_assert "$_ASSERT_FN" "${_ARGS[@]}"
else
Expand Down
2 changes: 1 addition & 1 deletion src/colors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ sgr() {
echo $'\e'"[${codes}m"
}

_COLOR_DEFAULT="$(sgr 0)"
_COLOR_BOLD="$(sgr 1)"
_COLOR_FAINT="$(sgr 2)"
_COLOR_BLACK="$(sgr 30)"
Expand All @@ -31,3 +30,4 @@ _COLOR_RETURN_SUCCESS="$(sgr 42)$_COLOR_BLACK$_COLOR_BOLD"
_COLOR_RETURN_SKIPPED="$(sgr 43)$_COLOR_BLACK$_COLOR_BOLD"
_COLOR_RETURN_INCOMPLETE="$(sgr 46)$_COLOR_BLACK$_COLOR_BOLD"
_COLOR_RETURN_SNAPSHOT="$(sgr 44)$_COLOR_BLACK$_COLOR_BOLD"
_COLOR_DEFAULT="$(sgr 0)"
4 changes: 2 additions & 2 deletions src/console_results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ function console_results::print_failed_test() {
local expected=$2
local failure_condition_message=$3
local actual=$4
local extra_key=$5
local extra_value=$6
local extra_key=${5-}
local extra_value=${6-}

printf "\
${_COLOR_FAILED}βœ— Failed${_COLOR_DEFAULT}: %s
Expand Down
2 changes: 1 addition & 1 deletion src/test_doubles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function assert_have_been_called_times() {
actual="${variable}_times"
local label="${3:-$(helper::normalize_test_function_name "${FUNCNAME[1]}")}"

if [[ ${!actual} -ne $expected ]]; then
if [[ -z "${!actual-}" && $expected -ne 0 || ${!actual-0} -ne $expected ]]; then
state::add_assertions_failed
console_results::print_failed_test "${label}" "${command}" "to has been called" "${expected} times"
return
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_direct_fn_call_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_execution_error_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_fail_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_find_tests_command_line_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_pass_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_path_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_report_html_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_stop_on_failure_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/bashunit_upgrade_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up() {
./build.sh >/dev/null
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/install_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up_before_script() {
TEST_ENV_FILE="./tests/acceptance/fixtures/.env.default"
Expand Down
1 change: 1 addition & 0 deletions tests/acceptance/mock_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

#
# Make sure that the `runner::clear_mocks()` is being called,
Expand Down
1 change: 1 addition & 0 deletions tests/functional/custom_asserts_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

function set_up() {
_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
Expand Down
1 change: 1 addition & 0 deletions tests/functional/logic_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"

Expand Down
1 change: 1 addition & 0 deletions tests/functional/multi_invoker_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

_TEST_MULTI_INVOKER_ITERATION_FILE=""

Expand Down
1 change: 1 addition & 0 deletions tests/functional/provider_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

_TEST_GET_DATA_FROM_PROVIDER_ITERATION_FILE=""

Expand Down
1 change: 1 addition & 0 deletions tests/unit/redirect_error_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -euo pipefail

_ERROR_LOG=temp_error.log

Expand Down