From aecc6b55dcd125ccb627452079991bf1765de440 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Wed, 28 Dec 2011 20:46:24 -0600 Subject: [PATCH] Test that setup runs once before each test --- test/bats.bats | 12 ++++++++++++ test/fixtures/setup.bats | 17 +++++++++++++++++ test/tmp/.gitignore | 2 ++ 3 files changed, 31 insertions(+) create mode 100644 test/fixtures/setup.bats create mode 100644 test/tmp/.gitignore diff --git a/test/bats.bats b/test/bats.bats index 0eec271..924b733 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -1,6 +1,11 @@ #!/usr/bin/env bats FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures" +TMP="$BATS_TEST_DIRNAME/tmp" + +teardown() { + rm -f "$TMP"/* +} @test "no arguments prints usage instructions" { run bats @@ -46,3 +51,10 @@ FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures" run bats "$FIXTURE_ROOT/environment.bats" [ $status -eq 0 ] } + +@test "setup is run once before each test" { + rm -f "$TMP/setup.log" + run bats "$FIXTURE_ROOT/setup.bats" + run cat "$TMP/setup.log" + [ ${#lines[@]} -eq 3 ] +} diff --git a/test/fixtures/setup.bats b/test/fixtures/setup.bats new file mode 100644 index 0000000..d96b0af --- /dev/null +++ b/test/fixtures/setup.bats @@ -0,0 +1,17 @@ +TMP="$BATS_TEST_DIRNAME/../tmp" + +setup() { + echo "$BATS_TEST_NAME" >> "$TMP/setup.log" +} + +@test "one" { + true +} + +@test "two" { + true +} + +@test "three" { + true +} diff --git a/test/tmp/.gitignore b/test/tmp/.gitignore new file mode 100644 index 0000000..241e560 --- /dev/null +++ b/test/tmp/.gitignore @@ -0,0 +1,2 @@ +* +