Skip to content

Commit

Permalink
Add tests for search-term hook (CompSciLauren#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
zackse committed Oct 25, 2019
1 parent 77c0865 commit 426922f
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/search-term-test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bats

LOG="./tests/tests.log"

logTest() {
# $1 indicates the test status [PASS, FAIL]
date >> "$LOG"
echo "search-term test: $1" >> "$LOG"
echo "" >> "$LOG"
echo "--------------------------------------------" >> "$LOG"
echo "" >> "$LOG"
}

setup() {
# create branch for our test content
git checkout -b search-term-test-throwaway origin/master
}

teardown() {
# unstage, remove test file
git reset
rm -f search-term-test-throwaway.txt

# return to previous branch
git checkout -

# remove test branch
git branch -D search-term-test-throwaway
}

@test "content matching search term prevents commit" {
echo "FIXME:" > search-term-test-throwaway.txt
git add search-term-test-throwaway.txt

if ! git commit -m "add search term trigger"; then
logTest "PASS"
else
logTest "FAIL"
[ "$output" = "commit containing search term was allowed" ]
fi
}

@test "content not matching search term is allowed" {
echo "TODO": > search-term-test-throwaway.txt
git add search-term-test-throwaway.txt

if git commit -m "add content without search term"; then
logTest "PASS"
else
logTest "FAIL"
[ "$output" = "commit failed even without search term in content" ]
fi
}

0 comments on commit 426922f

Please sign in to comment.