Skip to content

Commit 7aa78d4

Browse files
author
Aki Arvio
committed
Use existing common assertions with run wrapper
1 parent 1533875 commit 7aa78d4

2 files changed

Lines changed: 14 additions & 49 deletions

File tree

README.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ test_command_fails_when_expected_success(){
780780

781781
```output
782782
Running test_command_fails_when_expected_success ... FAILURE
783-
expected run command to succeed but status was 1
783+
expected [0] but was [1]
784784
doc:8:test_command_fails_when_expected_success()
785785
Running test_command_succeeds ... SUCCESS
786786
```
@@ -806,7 +806,7 @@ test_command_succeeds_when_expected_failure(){
806806
```output
807807
Running test_command_fails ... SUCCESS
808808
Running test_command_succeeds_when_expected_failure ... FAILURE
809-
expected run command to fail but status was 0
809+
expected different value than [0] but was the same
810810
doc:8:test_command_succeeds_when_expected_failure()
811811
```
812812

@@ -831,7 +831,7 @@ test_wrong_exit_code(){
831831
```output
832832
Running test_specific_exit_code ... SUCCESS
833833
Running test_wrong_exit_code ... FAILURE
834-
expected run command to have status code 0 but was 1
834+
expected [0] but was [1]
835835
doc:8:test_wrong_exit_code()
836836
```
837837

@@ -855,7 +855,7 @@ test_output_differs(){
855855

856856
```output
857857
Running test_output_differs ... FAILURE
858-
expected run output [expected] but was [actual]
858+
expected [expected] but was [actual]
859859
doc:8:test_output_differs()
860860
Running test_output_matches ... SUCCESS
861861
```
@@ -880,7 +880,7 @@ test_output_does_not_match(){
880880

881881
```output
882882
Running test_output_does_not_match ... FAILURE
883-
expected run output to match regex [Error:] but was [Success]
883+
expected regex [Error:] to match [Success]
884884
doc:8:test_output_does_not_match()
885885
Running test_output_matches_pattern ... SUCCESS
886886
```
@@ -905,7 +905,7 @@ test_error_differs(){
905905

906906
```output
907907
Running test_error_differs ... FAILURE
908-
expected run error [expected error] but was [actual error]
908+
expected [expected error] but was [actual error]
909909
doc:8:test_error_differs()
910910
Running test_error_matches ... SUCCESS
911911
```
@@ -930,7 +930,7 @@ test_error_does_not_match(){
930930

931931
```output
932932
Running test_error_does_not_match ... FAILURE
933-
expected run error to match regex [Warning:] but was [Info: all good]
933+
expected regex [Warning:] to match [Info: all good]
934934
doc:8:test_error_does_not_match()
935935
Running test_error_matches_pattern ... SUCCESS
936936
```

bash_unit

Lines changed: 7 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -222,71 +222,36 @@ run() {
222222
}
223223

224224
assert_run_success() {
225-
local message=${1:-}
226-
[[ -z $message ]] || message="$message\n"
227-
228-
if [ "$BASH_UNIT_RUN_STATUS" != 0 ]; then
229-
fail "${message}expected run command to succeed but status was $BASH_UNIT_RUN_STATUS"
230-
fi
225+
assert_equals 0 "$BASH_UNIT_RUN_STATUS" "${1:-}"
231226
}
232227

233228
assert_run_fails() {
234-
local message=${1:-}
235-
[[ -z $message ]] || message="$message\n"
236-
237-
if [ "$BASH_UNIT_RUN_STATUS" == 0 ]; then
238-
fail "${message}expected run command to fail but status was 0"
239-
fi
229+
assert_not_equals 0 "$BASH_UNIT_RUN_STATUS" "${1:-}"
240230
}
241231

242232
assert_run_status_code() {
243233
local expected=$1
244-
local message=${2:-}
245-
[[ -z $message ]] || message="$message\n"
246-
247-
if [ "$BASH_UNIT_RUN_STATUS" != "$expected" ]; then
248-
fail "${message}expected run command to have status code $expected but was $BASH_UNIT_RUN_STATUS"
249-
fi
234+
assert_equals "$expected" "$BASH_UNIT_RUN_STATUS" "${2:-}"
250235
}
251236

252237
assert_run_output_equals() {
253238
local expected=$1
254-
local message=${2:-}
255-
[[ -z $message ]] || message="$message\n"
256-
257-
if [ "$expected" != "$BASH_UNIT_RUN_OUTPUT" ]; then
258-
fail "${message}expected run output [$expected] but was [$BASH_UNIT_RUN_OUTPUT]"
259-
fi
239+
assert_equals "$expected" "$BASH_UNIT_RUN_OUTPUT" "${2:-}"
260240
}
261241

262242
assert_run_output_matches() {
263243
local pattern=$1
264-
local message=${2:-}
265-
[[ -z $message ]] || message="$message\n"
266-
267-
if [[ ! "$BASH_UNIT_RUN_OUTPUT" =~ $pattern ]]; then
268-
fail "${message}expected run output to match regex [$pattern] but was [$BASH_UNIT_RUN_OUTPUT]"
269-
fi
244+
assert_matches "$pattern" "$BASH_UNIT_RUN_OUTPUT" "${2:-}"
270245
}
271246

272247
assert_run_error_equals() {
273248
local expected=$1
274-
local message=${2:-}
275-
[[ -z $message ]] || message="$message\n"
276-
277-
if [ "$expected" != "$BASH_UNIT_RUN_ERROR" ]; then
278-
fail "${message}expected run error [$expected] but was [$BASH_UNIT_RUN_ERROR]"
279-
fi
249+
assert_equals "$expected" "$BASH_UNIT_RUN_ERROR" "${2:-}"
280250
}
281251

282252
assert_run_error_matches() {
283253
local pattern=$1
284-
local message=${2:-}
285-
[[ -z $message ]] || message="$message\n"
286-
287-
if [[ ! "$BASH_UNIT_RUN_ERROR" =~ $pattern ]]; then
288-
fail "${message}expected run error to match regex [$pattern] but was [$BASH_UNIT_RUN_ERROR]"
289-
fi
254+
assert_matches "$pattern" "$BASH_UNIT_RUN_ERROR" "${2:-}"
290255
}
291256

292257
fake() {

0 commit comments

Comments
 (0)