Skip to content

Commit b7093f1

Browse files
Add hook to stop accidentally committing test flag
1 parent 480c946 commit b7093f1

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

Tests/Readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
* Most tests are "characterization" tests, meaning they represent the current output. This does not mean that it's the ideal output.
44
* If you need to change an existing characterization, that's fine, so long as you're convinced it's no less correct than what was previously there.
5-
* See TestConstants for an automated way to rewrite the expected output en masse.
5+
* See TestConstants for an automated way to rewrite the expected output en masse
6+
* Run hooks/enable-hooks.cmd to enable a pre-commit hook which stops you committing the flag when true
67

78
## Types
89

hooks/enable-hooks.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
git config core.hooksPath hooks

hooks/pre-commit

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
#
3+
# Stop us from committing the test constants flag
4+
#
5+
disallowed="RecharacterizeByWritingExpectedOverActual.*=.*true"
6+
7+
git diff --cached --name-status | egrep TestConstants | while read x file; do
8+
if [ "$x" == 'D' ]; then continue; fi
9+
if egrep "$disallowed" "$file" ; then
10+
echo "ERROR: Disallowed expression \"${disallowed}\" in file: ${file}"
11+
exit 1
12+
fi
13+
14+
done || exit $?

0 commit comments

Comments
 (0)