Skip to content

Commit 93f5b97

Browse files
authored
Merge pull request #285 from TypedDevs/fix/283-strictmode
Fix strictmode
2 parents a2eb9bd + ed27112 commit 93f5b97

22 files changed

+32
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- Support for displaying the clock without `perl` (for non-macOS)
1010
- Add `-l|--log-junit <log.xml>` option
1111
- Add `-r|--report-html <report.html>` option
12-
- Foundation to enable strictmode
12+
- Enable strictmode
1313

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

bashunit

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
# shellcheck disable=SC2034
45
declare -r BASHUNIT_VERSION="0.13.0"
56

6-
readonly BASHUNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
7+
# shellcheck disable=SC2155
8+
declare -r BASHUNIT_ROOT_DIR="$(dirname "${BASH_SOURCE[0]}")"
79
export BASHUNIT_ROOT_DIR
810

911
source "$BASHUNIT_ROOT_DIR/src/default_env_config.sh"
@@ -40,15 +42,15 @@ while [[ $# -gt 0 ]]; do
4042
shift
4143
;;
4244
-s|--simple)
43-
SIMPLE_OUTPUT=true
45+
export SIMPLE_OUTPUT=true
4446
shift
4547
;;
4648
-v|--verbose)
47-
SIMPLE_OUTPUT=false
49+
export SIMPLE_OUTPUT=false
4850
shift
4951
;;
5052
-S|--stop-on-failure)
51-
STOP_ON_FAILURE=true
53+
export STOP_ON_FAILURE=true
5254
shift
5355
;;
5456
-e|--env)
@@ -58,12 +60,12 @@ while [[ $# -gt 0 ]]; do
5860
shift
5961
;;
6062
-l|--log-junit)
61-
LOG_JUNIT="$2";
63+
export LOG_JUNIT="$2";
6264
shift
6365
shift
6466
;;
6567
-r|--report-html)
66-
REPORT_HTML="$2";
68+
export REPORT_HTML="$2";
6769
shift
6870
shift
6971
;;
@@ -88,6 +90,8 @@ while [[ $# -gt 0 ]]; do
8890
esac
8991
done
9092

93+
set +eu
94+
9195
if [[ -n "$_ASSERT_FN" ]]; then
9296
main::exec_assert "$_ASSERT_FN" "${_ARGS[@]}"
9397
else

src/colors.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ sgr() {
1717
echo $'\e'"[${codes}m"
1818
}
1919

20-
_COLOR_DEFAULT="$(sgr 0)"
2120
_COLOR_BOLD="$(sgr 1)"
2221
_COLOR_FAINT="$(sgr 2)"
2322
_COLOR_BLACK="$(sgr 30)"
@@ -31,3 +30,4 @@ _COLOR_RETURN_SUCCESS="$(sgr 42)$_COLOR_BLACK$_COLOR_BOLD"
3130
_COLOR_RETURN_SKIPPED="$(sgr 43)$_COLOR_BLACK$_COLOR_BOLD"
3231
_COLOR_RETURN_INCOMPLETE="$(sgr 46)$_COLOR_BLACK$_COLOR_BOLD"
3332
_COLOR_RETURN_SNAPSHOT="$(sgr 44)$_COLOR_BLACK$_COLOR_BOLD"
33+
_COLOR_DEFAULT="$(sgr 0)"

src/console_results.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ function console_results::print_failed_test() {
143143
local expected=$2
144144
local failure_condition_message=$3
145145
local actual=$4
146-
local extra_key=$5
147-
local extra_value=$6
146+
local extra_key=${5-}
147+
local extra_value=${6-}
148148

149149
printf "\
150150
${_COLOR_FAILED}✗ Failed${_COLOR_DEFAULT}: %s

src/test_doubles.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function assert_have_been_called_times() {
8888
actual="${variable}_times"
8989
local label="${3:-$(helper::normalize_test_function_name "${FUNCNAME[1]}")}"
9090

91-
if [[ ${!actual} -ne $expected ]]; then
91+
if [[ -z "${!actual-}" && $expected -ne 0 || ${!actual-0} -ne $expected ]]; then
9292
state::add_assertions_failed
9393
console_results::print_failed_test "${label}" "${command}" "to has been called" "${expected} times"
9494
return

tests/acceptance/bashunit_direct_fn_call_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
function set_up_before_script() {
45
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"

tests/acceptance/bashunit_execution_error_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
function set_up_before_script() {
45
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"

tests/acceptance/bashunit_fail_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
function set_up_before_script() {
45
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"

tests/acceptance/bashunit_find_tests_command_line_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
function set_up_before_script() {
45
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"

tests/acceptance/bashunit_pass_test.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/bin/bash
2+
set -euo pipefail
23

34
function set_up_before_script() {
45
TEST_ENV_FILE="tests/acceptance/fixtures/.env.default"

0 commit comments

Comments
 (0)