Home

Awesome

Stand With Ukraine

fhtagn

Run tests coverage

fhtagn.awk is a tiny CLI tool for literate testing for command-line programs.

File tests.tush:

$ command --that --should --execute correctly
| expected stdout output

$ command --that --will --cause error
@ expected stderr output
? expected-exit-code

Run the tests:

./fhtagn.awk tests.tush

In fact this is a re-implementation of darius/tush, adolfopa/tush. But simpler (single tiny AWK script) and faster, because:

Usage

./fhtagn.awk f1.tush [ f2.tush [ f3.tush [...] ] ]

This will stop on the first error found.

Example:

$ ./fhtagn.awk tests/1.tush tests/2.tush tests/3.tush 
tests/2.tush:12: $ echo "hello world"; echo "error msg" >&2; exit 7
--- expected
+++ actual
@@ -1,4 +1,4 @@
 | hello world
-@ error msg 444
-? 8
+@ error msg
+? 7
 

Fail at the end

Set ALL=1 environment variable.

This runs all tests, collects all errors, and shows the stats at the end.

ALL=1 ./fhtagn.awk f1.tush [ f2.tush [ f3.tush [...] ] ]

Useful for running in CI.

Example:

$ ALL=1 ./fhtagn.awk tests/1.tush tests/2.tush tests/3.tush 
tests/2.tush:12: $ echo "hello world"; echo "error msg" >&2; exit 7
--- expected
+++ actual
@@ -1,4 +1,4 @@
 | hello world
-@ error msg 444
-? 8
+@ error msg
+? 7
 
tests/3.tush:7: $ echo bbb
--- expected
+++ actual
@@ -1,2 +1,2 @@
-| BBB
+| bbb
 
result=FAIL, failure=2, success=4, total=6, files=3