Skip to content

Commit a800992

Browse files
committed
new convention
1 parent cc1cf35 commit a800992

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,8 @@ repos:
110110
language: system
111111
files: ^resources/.*\.php$
112112
exclude: ^resources/lib/UnityHTTPD\.php$
113+
- id: assert-no-assertTrue
114+
name: Assert `assertTrue` is not used
115+
entry: bash ./test/assert-no-assertTrue.bash
116+
language: system
117+
files: ^test/.*\.php$

CONTRIBUTING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
This will enable strict mode and throw an exception rather than returning `false`.
2323
- `UnityHTTPD`'s user-facing error functionality (ex: `badRequest`) should only be called from `webroot/**/*.php`.
2424
`resources/**/*.php` should throw exceptions instead.
25+
- No code should call `PHPUnit\Framework\TestCase::assertTrue`, instead `assert`.
26+
`assert` is better because it doesn't just say "something is false", it actually shows what is false.
2527

2628
This repository will automatically check PRs for linting compliance.
2729

test/assert-no-assertTrue.bash

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set -euo pipefail
2+
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
3+
if [[ $# -lt 1 ]]; then
4+
echo "at least one argument required"
5+
exit 1
6+
fi
7+
8+
funcs=(assertTrue)
9+
rc=0
10+
for func in "${funcs[@]}"; do
11+
# --color=never because magit git output log doesn't support it
12+
grep_rc=0; grep -H --color=never --line-number -P '\b'"$func"'\s*[\(;]' "$@" || grep_rc=$?
13+
case "$grep_rc" in
14+
0)
15+
echo "$func() is not allowed! use an exception instead."; rc=1 ;;
16+
1)
17+
: ;; # code is good, do nothing
18+
*)
19+
echo "grep failed!"; rc=1 ;;
20+
esac
21+
done
22+
exit "$rc"

0 commit comments

Comments
 (0)