Skip to content

Commit

Permalink
Test test suites with multiple files loading common constants
Browse files Browse the repository at this point in the history
  • Loading branch information
debarshiray committed Apr 19, 2024
1 parent b30a6ae commit 745b619
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 0 deletions.
5 changes: 5 additions & 0 deletions test/fixtures/suite/errors_in_multiple_load/a.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load test_helper

@test "truth" {
true
}
5 changes: 5 additions & 0 deletions test/fixtures/suite/errors_in_multiple_load/b.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load test_helper

@test "more truth" {
true
}
5 changes: 5 additions & 0 deletions test/fixtures/suite/errors_in_multiple_load/c.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load nonexistent

@test "yet more truth" {
true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
call-to-undefined-command
5 changes: 5 additions & 0 deletions test/fixtures/suite/multiple_load_constants/a.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load test_helper

@test "constant" {
[ "$A_CONSTANT" = "value" ]
}
5 changes: 5 additions & 0 deletions test/fixtures/suite/multiple_load_constants/b.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
load test_helper

@test "constant (again)" {
[ "$A_CONSTANT" = "value" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
readonly A_CONSTANT="value"
27 changes: 27 additions & 0 deletions test/suite.bats
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,40 @@ setup() {
echo "$output" | grep "^ok . quasi-truth"
}

@test "aggregated output of multiple tests in a suite loading common constants" {
reentrant_run bats "$FIXTURE_ROOT/multiple_load_constants"
[ $status -eq 0 ]
[ "${lines[0]}" = "1..2" ]
[ "${lines[1]}" = "ok 1 constant" ]
[ "${lines[2]}" = "ok 2 constant (again)" ]
}

@test "a failing test in a suite results in an error exit code" {
FLUNK=1 reentrant_run bats "$FIXTURE_ROOT/multiple"
[ $status -eq 1 ]
[ "${lines[0]}" = "1..3" ]
echo "$output" | grep "^not ok . quasi-truth"
}

@test "errors when loading common helper from multiple tests in a suite" {
reentrant_run bats "$FIXTURE_ROOT/errors_in_multiple_load"
[ $status -eq 1 ]
[ "${lines[0]}" = "1..3" ]
regex="test_helper\.bash: line 1: call-to-undefined-command: command not found"
[[ "${lines[1]}" =~ $regex ]]
regex="Error while sourcing library loader at '.*test_helper\.bash'"
[[ "${lines[2]}" =~ $regex ]]
[ "${lines[3]}" = "not ok 1 setup_file failed" ]
regex="test_helper\.bash: line 1: call-to-undefined-command: command not found"
[[ "${lines[8]}" =~ $regex ]]
regex="Error while sourcing library loader at '.*test_helper\.bash'"
[[ "${lines[9]}" =~ $regex ]]
[ "${lines[10]}" = "not ok 2 setup_file failed" ]
regex="bats_load_safe: Could not find '.*nonexistent'\[\.bash\]"
[[ "${lines[15]}" =~ $regex ]]
[ "${lines[16]}" = "not ok 3 setup_file failed" ]
}

@test "running an ad-hoc suite by specifying multiple test files" {
reentrant_run bats "$FIXTURE_ROOT/multiple/a.bats" "$FIXTURE_ROOT/multiple/b.bats"
[ $status -eq 0 ]
Expand Down

0 comments on commit 745b619

Please sign in to comment.