Fhtagn
Literate testing for command-line programs
Install / Use
/learn @xonixx/FhtagnREADME
fhtagn
fhtagn.awk is a tiny CLI tool for literate testing for command-line programs.
File tests.fhtagn:
$ 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.fhtagn
In fact, this is a re-implementation of darius/tush, adolfopa/tush. But simpler (single tiny AWK script) and faster, because:
- it uses
/dev/shmwhere available instead of/tmp - it compares the expected result with the actual in the code and only calls
diffto show the difference if they don't match - it doesn't create a sandbox folder for each test
- it doesn't use
mktempbut rather generates random name in the code
Usage
./fhtagn.awk f1.fhtagn [ f2.fhtagn [ f3.fhtagn [...] ] ]
This will stop on the first error found.
Example:
$ ./fhtagn.awk tests/1.fhtagn tests/2.fhtagn tests/3.fhtagn
tests/2.fhtagn: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.fhtagn [ f2.fhtagn [ f3.fhtagn [...] ] ]
Useful for running in CI.
Example:
$ ALL=1 ./fhtagn.awk tests/1.fhtagn tests/2.fhtagn tests/3.fhtagn
tests/2.fhtagn: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.fhtagn:7: $ echo bbb
--- expected
+++ actual
@@ -1,2 +1,2 @@
-| BBB
+| bbb
result=FAIL, failure=2, success=4, total=6, files=3
Parameterized tests
You can use variable substitution to parametrize tests. This works like so:
# in your .fhtagn file you have
$ command {{VAR1}} '{{VAR2}}'
| expected output
And you run it like so:
./fhtagn.awk tests.fhtagn VAR1=value VAR2='other value'
The example use case here is to check the correctness of the same command when ran by different versions of a programming language. This is what we do to test fhtagn itself with different AWKs: link1, link2, link3.
Note that in case of test failure, you will see an expanded command line, which is helpful for debugging.
Related Skills
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
