forked from CompSciLauren/awesome-git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for search-term hook (CompSciLauren#24)
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |