Support ✓/✗ as alternatives to [success]/[failure]

This commit is contained in:
Sven van Heugten 2026-04-16 17:01:40 +02:00
parent 4704cc088d
commit 0719fa33c2
No known key found for this signature in database
GPG key ID: D612F88666F4F660
3 changed files with 49 additions and 21 deletions

View file

@ -60,18 +60,18 @@ Simply add a `git-check-assertions` block to a commit message, e.g.:
~~~
```git-check-assertions
[success] dotnet build
[success] dotnet test --no-build
dotnet build
dotnet test --no-build
```
~~~
Each block is parsed line-by-line:
* A line starting with `[success] ` runs the rest of the line as a shell command and asserts that it exits with status `0`.
* A line starting with `[failure] ` runs the rest of the line as a shell command and asserts that it exits with a non-zero status.
* A line starting with `[success] ` or `✓ ` runs the rest of the line as a shell command and asserts that it exits with status `0`.
* A line starting with `[failure] ` or `✗ ` runs the rest of the line as a shell command and asserts that it exits with a non-zero status.
* Any following non-empty line belongs to the most recent command and asserts that the combined stdout/stderr from that command contains that string.
Blank lines are ignored. A new `[success]` or `[failure]` line starts a new command block.
Blank lines are ignored. A new `[success]`, `[failure]`, `✓`, or `✗` line starts a new command block.
## Multiple blocks in one commit message
@ -89,7 +89,7 @@ Assert that a commit builds:
~~~
```git-check-assertions
[success] dotnet build
dotnet build
```
~~~
@ -97,8 +97,8 @@ Assert that a commit builds and that the tests succeed:
~~~
```git-check-assertions
[success] dotnet build
[success] dotnet test --no-build
dotnet build
dotnet test --no-build
```
~~~
@ -106,8 +106,8 @@ Assert that a commit builds, but that the tests do not succeed:
~~~
```git-check-assertions
[success] dotnet build
[failure] dotnet test --no-build
dotnet build
dotnet test --no-build
```
~~~
@ -115,8 +115,8 @@ Assert that a commit builds, and that the tests fail with the error that you exp
~~~
```git-check-assertions
[success] dotnet build
[failure] dotnet test --no-build
dotnet build
dotnet test --no-build
Invalid URL
```
~~~
@ -125,10 +125,10 @@ Assert that a specific change breaks the tests (as discussed [here](https://sven
~~~
```git-check-assertions
[success] dotnet test
dotnet test
[success] sed -i '/crucial code/d' Main.fs
[failure] dotnet test
sed -i '/crucial code/d' Main.fs
dotnet test
```
~~~
@ -136,10 +136,10 @@ Assert that a specific change in a commit is necessary for the tests to succeed:
~~~
```git-check-assertions
[success] dotnet test
dotnet test
[success] git checkout HEAD~ Main.fs
[failure] dotnet test
git checkout HEAD~ Main.fs
dotnet test
Invalid URL
```
~~~

View file

@ -91,10 +91,10 @@ for commit_hash in "${commits[@]}"; do
if not line.strip():
continue
match = re.match(r"^\\[(success|failure)\\]\\s+(.+)$", line)
match = re.match(r"^(\\[success\\]|\\[failure\\]|✓|✗)\\s+(.+)$", line)
if match:
current_step = {
"expects_success": match.group(1) == "success",
"expects_success": match.group(1) in ("[success]", "✓"),
"command": match.group(2),
"assertions": [],
}
@ -104,7 +104,7 @@ for commit_hash in "${commits[@]}"; do
if current_step is None:
print(
f"DSL parse error on line {line_number}: "
"assertion text must follow [success] or [failure]."
"assertion text must follow [success], [failure], ✓, or ✗."
)
sys.exit(1)

View file

@ -368,6 +368,34 @@ commit_with_assertion() {
assert_output --partial "Expected command to fail, but it succeeded."
}
@test "a ✓ command should succeed if the executed command succeeded" {
git checkout -b feature
commit_with_assertion '✓ exit 0'
run git-check-assertions
assert_success
}
@test "a ✗ command should succeed if the executed command failed" {
git checkout -b feature
commit_with_assertion '✗ exit 1'
run git-check-assertions
assert_success
}
@test "you can mix symbols and bracketed asserts in the same block" {
git checkout -b feature
commit_with_assertion $'✓ echo hello\nhello\n[failure] exit 0'
run git-check-assertions
assert_failure
assert_output --partial "Expected command to fail, but it succeeded."
}
@test "an output line should succeed if the output contains the given string" {
git checkout -b feature
commit_with_assertion $'[success] echo hello\nhello'