A Practical Guide to go‑internal/testscript for Testing Command‑Line Tools

Today, I discovered an excellent testing package by Roger Peppe: go-internal/testscript. At work, I’ve been using Bats for testing cli stuff. All of our cli stuff is almost migrated from legacy Perl-scripts to Go (using the kong cmdline parser). Bats allows you to run cli programs and check the results. It does not care about the inner workings, as long as it outputs or generates the right results, the tests pass. But using a shell framework for testing Go stuff just does not feel performant. It’s a bit clumsy (demo later on). Also, its a PITA to setup up a CI pipeline. ...

April 7, 2026 · Bram Daams