2011-12-28 23:21:48 +01:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures"
|
2011-12-29 03:57:58 +01:00
|
|
|
export TMP="$BATS_TEST_DIRNAME/tmp"
|
2011-12-29 03:46:24 +01:00
|
|
|
|
|
|
|
teardown() {
|
|
|
|
rm -f "$TMP"/*
|
|
|
|
}
|
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 ]
|
|
|
|
[ $(expr "$output" : "usage:") -ne 0 ]
|
2011-12-28 23:21:48 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
@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 ]
|
|
|
|
[ ${lines[0]} = "1..1" ]
|
|
|
|
[ ${lines[1]} = "not ok 1 a failing test" ]
|
|
|
|
}
|
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 ]
|
|
|
|
[ ${lines[0]} = "1..2" ]
|
|
|
|
[ ${lines[1]} = "not ok 1 a failing test" ]
|
|
|
|
[ ${lines[2]} = "ok 2 a passing test" ]
|
|
|
|
}
|
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
|
|
|
|
|
|
|
@test "load sources scripts relative to the current test file" {
|
|
|
|
run bats "$FIXTURE_ROOT/load.bats"
|
|
|
|
[ $status -eq 0 ]
|
|
|
|
}
|