2011-12-28 23:21:48 +01:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
2012-11-16 21:25:45 +01:00
|
|
|
load test_helper
|
|
|
|
fixtures bats
|
2011-12-28 23:21:48 +01:00
|
|
|
|
2011-12-29 00:12:17 +01:00
|
|
|
@test "no arguments prints usage instructions" {
|
2011-12-28 23:21:48 +01:00
|
|
|
run bats
|
2011-12-29 01:25:05 +01:00
|
|
|
[ $status -eq 1 ]
|
2013-10-21 19:03:45 +02:00
|
|
|
[ $(expr "${lines[1]}" : "Usage:") -ne 0 ]
|
2011-12-30 21:12:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@test "-v and --version print version number" {
|
|
|
|
run bats -v
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ $(expr "$output" : "Bats [0-9][0-9.]*") -ne 0 ]
|
2011-12-28 23:21:48 +01:00
|
|
|
}
|
|
|
|
|
2013-10-21 19:03:45 +02:00
|
|
|
@test "-h and --help print help" {
|
|
|
|
run bats -h
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "${#lines[@]}" -gt 3 ]
|
|
|
|
}
|
|
|
|
|
2011-12-29 00:12:17 +01:00
|
|
|
@test "invalid filename prints an error" {
|
2011-12-28 23:21:48 +01:00
|
|
|
run bats nonexistent
|
2011-12-29 01:25:05 +01:00
|
|
|
[ $status -eq 1 ]
|
|
|
|
[ $(expr "$output" : ".*does not exist") -ne 0 ]
|
2011-12-28 23:21:48 +01:00
|
|
|
}
|
|
|
|
|
2011-12-29 00:12:17 +01:00
|
|
|
@test "empty test file runs zero tests" {
|
2011-12-28 23:21:48 +01:00
|
|
|
run bats "$FIXTURE_ROOT/empty.bats"
|
2011-12-29 01:25:05 +01:00
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ $output = "1..0" ]
|
2011-12-28 23:21:48 +01:00
|
|
|
}
|
2011-12-29 00:12:37 +01:00
|
|
|
|
|
|
|
@test "one passing test" {
|
2011-12-29 03:06:05 +01:00
|
|
|
run bats "$FIXTURE_ROOT/passing.bats"
|
2011-12-29 01:25:05 +01:00
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ ${lines[0]} = "1..1" ]
|
|
|
|
[ ${lines[1]} = "ok 1 a passing test" ]
|
2011-12-29 00:12:37 +01:00
|
|
|
}
|
2011-12-29 02:14:10 +01:00
|
|
|
|
2013-10-31 01:10:00 +01:00
|
|
|
@test "summary passing tests" {
|
|
|
|
run filter_control_sequences bats -p $FIXTURE_ROOT/passing.bats
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "${lines[1]}" = "1 test, 0 failures" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "summary passing and skipping tests" {
|
|
|
|
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_and_skipping.bats
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "${lines[2]}" = "2 tests, 0 failures, 1 skipped" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "summary passing and failing tests" {
|
|
|
|
run filter_control_sequences bats -p $FIXTURE_ROOT/failing_and_passing.bats
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "${lines[4]}" = "2 tests, 1 failure" ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "summary passing, failing and skipping tests" {
|
|
|
|
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_failing_and_skipping.bats
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "${lines[5]}" = "3 tests, 1 failure, 1 skipped" ]
|
|
|
|
}
|
|
|
|
|
2011-12-29 02:14:10 +01:00
|
|
|
@test "one failing test" {
|
2011-12-29 03:06:05 +01:00
|
|
|
run bats "$FIXTURE_ROOT/failing.bats"
|
2011-12-29 02:14:10 +01:00
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[0]}" = '1..1' ]
|
|
|
|
[ "${lines[1]}" = 'not ok 1 a failing test' ]
|
2014-08-12 23:56:52 +02:00
|
|
|
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing.bats, line 4)" ]
|
2014-08-12 23:22:43 +02:00
|
|
|
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed" ]
|
2011-12-29 02:14:10 +01:00
|
|
|
}
|
2011-12-29 03:06:05 +01:00
|
|
|
|
|
|
|
@test "one failing and one passing test" {
|
|
|
|
run bats "$FIXTURE_ROOT/failing_and_passing.bats"
|
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[0]}" = '1..2' ]
|
|
|
|
[ "${lines[1]}" = 'not ok 1 a failing test' ]
|
2014-08-12 23:56:52 +02:00
|
|
|
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_and_passing.bats, line 2)" ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[3]}" = "# \`false' failed" ]
|
|
|
|
[ "${lines[4]}" = 'ok 2 a passing test' ]
|
2011-12-29 03:06:05 +01:00
|
|
|
}
|
2011-12-29 03:23:52 +01:00
|
|
|
|
2014-08-12 23:22:43 +02:00
|
|
|
@test "failing test with significant status" {
|
|
|
|
STATUS=2 run bats "$FIXTURE_ROOT/failing.bats"
|
|
|
|
[ $status -eq 1 ]
|
|
|
|
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
|
|
|
|
}
|
|
|
|
|
2013-11-04 19:20:55 +01:00
|
|
|
@test "failing helper function logs the test case's line number" {
|
|
|
|
run bats "$FIXTURE_ROOT/failing_helper.bats"
|
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[1]}" = 'not ok 1 failing helper function' ]
|
2014-08-12 23:56:52 +02:00
|
|
|
[ "${lines[2]}" = "# (from function \`failing_helper' in file $RELATIVE_FIXTURE_ROOT/test_helper.bash, line 6," ]
|
|
|
|
[ "${lines[3]}" = "# in test file $RELATIVE_FIXTURE_ROOT/failing_helper.bats, line 5)" ]
|
2014-08-13 00:28:03 +02:00
|
|
|
[ "${lines[4]}" = "# \`failing_helper' failed" ]
|
2013-11-04 19:20:55 +01:00
|
|
|
}
|
|
|
|
|
2011-12-29 03:23:52 +01:00
|
|
|
@test "test environments are isolated" {
|
|
|
|
run bats "$FIXTURE_ROOT/environment.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
}
|
2011-12-29 03:46:24 +01:00
|
|
|
|
|
|
|
@test "setup is run once before each test" {
|
|
|
|
rm -f "$TMP/setup.log"
|
|
|
|
run bats "$FIXTURE_ROOT/setup.bats"
|
2011-12-29 04:20:43 +01:00
|
|
|
[ $status -eq 0 ]
|
2011-12-29 03:46:24 +01:00
|
|
|
run cat "$TMP/setup.log"
|
|
|
|
[ ${#lines[@]} -eq 3 ]
|
|
|
|
}
|
2011-12-29 04:20:43 +01:00
|
|
|
|
|
|
|
@test "teardown is run once after each test, even if it fails" {
|
|
|
|
rm -f "$TMP/teardown.log"
|
|
|
|
run bats "$FIXTURE_ROOT/teardown.bats"
|
|
|
|
[ $status -eq 1 ]
|
|
|
|
run cat "$TMP/teardown.log"
|
|
|
|
[ ${#lines[@]} -eq 3 ]
|
|
|
|
}
|
2011-12-29 04:41:23 +01:00
|
|
|
|
2013-11-04 20:34:37 +01:00
|
|
|
@test "setup failure" {
|
2013-11-04 19:20:55 +01:00
|
|
|
run bats "$FIXTURE_ROOT/failing_setup.bats"
|
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[1]}" = 'not ok 1 truth' ]
|
2014-08-12 23:56:52 +02:00
|
|
|
[ "${lines[2]}" = "# (from function \`setup' in test file $RELATIVE_FIXTURE_ROOT/failing_setup.bats, line 2)" ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[3]}" = "# \`false' failed" ]
|
2013-11-04 19:20:55 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 20:34:37 +01:00
|
|
|
@test "passing test with teardown failure" {
|
2013-11-04 19:20:55 +01:00
|
|
|
PASS=1 run bats "$FIXTURE_ROOT/failing_teardown.bats"
|
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[1]}" = 'not ok 1 truth' ]
|
2014-08-12 23:56:52 +02:00
|
|
|
[ "${lines[2]}" = "# (from function \`teardown' in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 2)" ]
|
2014-08-12 23:22:43 +02:00
|
|
|
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed" ]
|
2013-11-04 19:20:55 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 20:34:37 +01:00
|
|
|
@test "failing test with teardown failure" {
|
2013-11-04 19:20:55 +01:00
|
|
|
PASS=0 run bats "$FIXTURE_ROOT/failing_teardown.bats"
|
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[1]}" = 'not ok 1 truth' ]
|
2014-08-12 23:56:52 +02:00
|
|
|
[ "${lines[2]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/failing_teardown.bats, line 6)" ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[3]}" = $'# `[ "$PASS" = "1" ]\' failed' ]
|
2013-11-04 19:20:55 +01:00
|
|
|
}
|
|
|
|
|
2014-08-12 23:22:43 +02:00
|
|
|
@test "teardown failure with significant status" {
|
|
|
|
PASS=1 STATUS=2 run bats "$FIXTURE_ROOT/failing_teardown.bats"
|
|
|
|
[ $status -eq 1 ]
|
|
|
|
[ "${lines[3]}" = "# \`eval \"( exit \${STATUS:-1} )\"' failed with status 2" ]
|
|
|
|
}
|
|
|
|
|
2014-08-12 23:56:52 +02:00
|
|
|
@test "failing test file outside of BATS_CWD" {
|
|
|
|
cd "$TMP"
|
|
|
|
run bats "$FIXTURE_ROOT/failing.bats"
|
|
|
|
[ $status -eq 1 ]
|
|
|
|
[ "${lines[2]}" = "# (in test file $FIXTURE_ROOT/failing.bats, line 4)" ]
|
|
|
|
}
|
|
|
|
|
2011-12-29 04:41:23 +01:00
|
|
|
@test "load sources scripts relative to the current test file" {
|
|
|
|
run bats "$FIXTURE_ROOT/load.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
}
|
2011-12-29 06:50:49 +01:00
|
|
|
|
2012-11-16 21:35:48 +01:00
|
|
|
@test "load aborts if the specified script does not exist" {
|
|
|
|
HELPER_NAME="nonexistent" run bats "$FIXTURE_ROOT/load.bats"
|
|
|
|
[ $status -eq 1 ]
|
|
|
|
}
|
|
|
|
|
2014-05-21 06:10:55 +02:00
|
|
|
@test "load sources scripts by absolute path" {
|
|
|
|
HELPER_NAME="${FIXTURE_ROOT}/test_helper.bash" run bats "$FIXTURE_ROOT/load.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
}
|
|
|
|
|
|
|
|
@test "load aborts if the script, specified by an absolute path, does not exist" {
|
|
|
|
HELPER_NAME="${FIXTURE_ROOT}/nonexistent" run bats "$FIXTURE_ROOT/load.bats"
|
|
|
|
[ $status -eq 1 ]
|
|
|
|
}
|
|
|
|
|
2011-12-29 06:50:49 +01:00
|
|
|
@test "output is discarded for passing tests and printed for failing tests" {
|
|
|
|
run bats "$FIXTURE_ROOT/output.bats"
|
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[6]}" = '# failure stdout 1' ]
|
|
|
|
[ "${lines[7]}" = '# failure stdout 2' ]
|
|
|
|
[ "${lines[11]}" = '# failure stderr' ]
|
2011-12-29 06:50:49 +01:00
|
|
|
}
|
2012-04-09 06:25:19 +02:00
|
|
|
|
|
|
|
@test "-c prints the number of tests" {
|
|
|
|
run bats -c "$FIXTURE_ROOT/empty.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "$output" = "0" ]
|
|
|
|
|
|
|
|
run bats -c "$FIXTURE_ROOT/output.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "$output" = "4" ]
|
|
|
|
}
|
2013-04-06 14:01:03 +02:00
|
|
|
|
|
|
|
@test "dash-e is not mangled on beginning of line" {
|
|
|
|
run bats "$FIXTURE_ROOT/intact.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "${lines[1]}" = "ok 1 dash-e on beginning of line" ]
|
|
|
|
}
|
2013-05-23 03:20:39 +02:00
|
|
|
|
|
|
|
@test "dos line endings are stripped before testing" {
|
|
|
|
run bats "$FIXTURE_ROOT/dos_line.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
}
|
2013-10-18 23:05:20 +02:00
|
|
|
|
2013-10-21 19:45:49 +02:00
|
|
|
@test "test file without trailing newline" {
|
|
|
|
run bats "$FIXTURE_ROOT/without_trailing_newline.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "${lines[1]}" = "ok 1 truth" ]
|
|
|
|
}
|
|
|
|
|
2013-10-21 18:32:36 +02:00
|
|
|
@test "skipped tests" {
|
2013-10-18 23:05:20 +02:00
|
|
|
run bats "$FIXTURE_ROOT/skipped.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
[ "${lines[1]}" = "ok 1 # skip a skipped test" ]
|
|
|
|
[ "${lines[2]}" = "ok 2 # skip (a reason) a skipped test with a reason" ]
|
|
|
|
}
|
2013-10-21 18:32:09 +02:00
|
|
|
|
|
|
|
@test "extended syntax" {
|
|
|
|
run bats-exec-test -x "$FIXTURE_ROOT/failing_and_passing.bats"
|
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[1]}" = 'begin 1 a failing test' ]
|
|
|
|
[ "${lines[2]}" = 'not ok 1 a failing test' ]
|
|
|
|
[ "${lines[5]}" = 'begin 2 a passing test' ]
|
|
|
|
[ "${lines[6]}" = 'ok 2 a passing test' ]
|
2013-10-21 18:32:09 +02:00
|
|
|
}
|
2013-10-21 19:03:45 +02:00
|
|
|
|
|
|
|
@test "pretty and tap formats" {
|
|
|
|
run bats --tap "$FIXTURE_ROOT/passing.bats"
|
|
|
|
tap_output="$output"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
|
|
|
|
run bats --pretty "$FIXTURE_ROOT/passing.bats"
|
|
|
|
pretty_output="$output"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
|
|
|
|
[ "$tap_output" != "$pretty_output" ]
|
|
|
|
}
|
2013-10-28 20:46:30 +01:00
|
|
|
|
|
|
|
@test "pretty formatter bails on invalid tap" {
|
|
|
|
run bats --tap "$FIXTURE_ROOT/invalid_tap.bats"
|
|
|
|
[ $status -eq 1 ]
|
|
|
|
[ "${lines[0]}" = "This isn't TAP!" ]
|
|
|
|
[ "${lines[1]}" = "Good day to you" ]
|
|
|
|
}
|
2013-11-17 20:04:57 +01:00
|
|
|
|
|
|
|
@test "single-line tests" {
|
|
|
|
run bats "$FIXTURE_ROOT/single_line.bats"
|
|
|
|
[ $status -eq 1 ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[1]}" = 'ok 1 empty' ]
|
|
|
|
[ "${lines[2]}" = 'ok 2 passing' ]
|
|
|
|
[ "${lines[3]}" = 'ok 3 input redirection' ]
|
|
|
|
[ "${lines[4]}" = 'not ok 4 failing' ]
|
2014-08-12 23:56:52 +02:00
|
|
|
[ "${lines[5]}" = "# (in test file $RELATIVE_FIXTURE_ROOT/single_line.bats, line 9)" ]
|
2014-06-28 21:16:32 +02:00
|
|
|
[ "${lines[6]}" = $'# `@test "failing" { false; }\' failed' ]
|
2013-11-17 20:04:57 +01:00
|
|
|
}
|