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 ```git-check-assertions
[success] dotnet build dotnet build
[success] dotnet test --no-build dotnet test --no-build
``` ```
~~~ ~~~
Each block is parsed line-by-line: 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 `[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] ` runs the rest of the line as a shell command and asserts that it exits with a non-zero status. * 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. * 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 ## Multiple blocks in one commit message
@ -89,7 +89,7 @@ Assert that a commit builds:
~~~ ~~~
```git-check-assertions ```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 ```git-check-assertions
[success] dotnet build dotnet build
[success] dotnet test --no-build dotnet test --no-build
``` ```
~~~ ~~~
@ -106,8 +106,8 @@ Assert that a commit builds, but that the tests do not succeed:
~~~ ~~~
```git-check-assertions ```git-check-assertions
[success] dotnet build dotnet build
[failure] dotnet test --no-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 ```git-check-assertions
[success] dotnet build dotnet build
[failure] dotnet test --no-build dotnet test --no-build
Invalid URL Invalid URL
``` ```
~~~ ~~~
@ -125,10 +125,10 @@ Assert that a specific change breaks the tests (as discussed [here](https://sven
~~~ ~~~
```git-check-assertions ```git-check-assertions
[success] dotnet test dotnet test
[success] sed -i '/crucial code/d' Main.fs sed -i '/crucial code/d' Main.fs
[failure] dotnet test dotnet test
``` ```
~~~ ~~~
@ -136,10 +136,10 @@ Assert that a specific change in a commit is necessary for the tests to succeed:
~~~ ~~~
```git-check-assertions ```git-check-assertions
[success] dotnet test dotnet test
[success] git checkout HEAD~ Main.fs git checkout HEAD~ Main.fs
[failure] dotnet test dotnet test
Invalid URL Invalid URL
``` ```
~~~ ~~~

View file

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

View file

@ -368,6 +368,34 @@ commit_with_assertion() {
assert_output --partial "Expected command to fail, but it succeeded." 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" { @test "an output line should succeed if the output contains the given string" {
git checkout -b feature git checkout -b feature
commit_with_assertion $'[success] echo hello\nhello' commit_with_assertion $'[success] echo hello\nhello'