diff --git a/test/git-check-assertions.bats b/test/git-check-assertions.bats index 1755820..beb29ca 100755 --- a/test/git-check-assertions.bats +++ b/test/git-check-assertions.bats @@ -1,5 +1,19 @@ #!/usr/bin/env bats +init_repo() { + local repo_dir="$1" + local main_branch="$2" + + mkdir "$repo_dir" + cd "$repo_dir" + git init -b "$main_branch" + git config user.email "john.doe@example.com" + git config user.name "John Doe" + touch readme + git add readme + git commit -m "initial" +} + setup() { set -euo pipefail @@ -10,14 +24,7 @@ setup() { DIR="$(cd "$(dirname "$BATS_TEST_FILENAME")" >/dev/null 2>&1 && pwd)" PATH="$DIR/../bin:$PATH" - mkdir "$BATS_TEST_TMPDIR/repo" - cd "$BATS_TEST_TMPDIR/repo" - git init -b main - git config user.email "john.doe@example.com" - git config user.name "John Doe" - touch readme - git add readme - git commit -m "initial" + init_repo "$BATS_TEST_TMPDIR/repo" main } commit_with_assertion() { @@ -50,6 +57,19 @@ commit_with_assertion() { assert_file_not_exists ../test } +@test "should not run any assertion blocks from master when on a feature branch" { + init_repo "$BATS_TEST_TMPDIR/repo-master" master + + commit_with_assertion "touch ../test" + git checkout -b feature + git commit --allow-empty -m "feature" + + run git-check-assertions + + assert_success + assert_file_not_exists ../test +} + @test "should run all succeeding assertion blocks on the feature branch and finally return to the original branch" { git checkout -b feature commit_with_assertion "touch ../test1"