Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Testing Go CLI Apps with TestScript
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Jakub Jarosz
February 23, 2023
Programming
260
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Testing Go CLI Apps with TestScript
Jakub Jarosz
February 23, 2023
More Decks by Jakub Jarosz
See All by Jakub Jarosz
Benchmarking - First Steps
jakubjarosz
0
70
Communicating with Tests
jakubjarosz
0
160
Testing Go Code
jakubjarosz
0
250
Releasing Go Apps with GoReleaser
jakubjarosz
0
380
Building Environments with Ansible
jakubjarosz
0
410
a quick look at webtest & pytest
jakubjarosz
1
1.2k
Data Driven Integration Testing
jakubjarosz
2
320
Multi Mechanize
jakubjarosz
0
150
Embracing Python for Software Testing - BDD Style
jakubjarosz
0
390
Other Decks in Programming
See All in Programming
Creating Composable Callables in Contemporary C++
rollbear
0
150
Make SRE Operations Easier with Azure SRE Agent
kkamegawa
0
7k
メソッドのジェネリクスでGoの夢は広がるか? / Kyoto.go #65
utgwkk
3
850
TSKaigi Night Talks 2026_TypeScriptでサプライチェーンの整合性を型に閉じ込める
geekplus_tech
0
400
作って学ぶ、 JSX (TSX) ランタイムの基本
syumai
7
1.7k
「なぜそう決めたのか」を残し続ける仕組み ― Notion AI カスタムエージェント × Slack連携による設計判断の自動記録 - NIKKEI Tech Talk #47
niftycorp
PRO
0
210
RTSPクライアントを自作してみた話
simotin13
0
620
Lessons from Spec-Driven Development
simas
PRO
0
210
JJUG CCC 2026 Spring: JSpecify で実現する Kotlin フレンドリーな Java API 設計
ternbusty
1
180
Datadog × OpenTelemetry 入門と実践のあいだ
kn_to_maxpno
1
160
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
270
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
140
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
46
8.2k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.8k
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3.5k
Amusing Abliteration
ianozsvald
1
210
Building an army of robots
kneath
306
46k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
34
2.8k
New Earth Scene 8
popppiees
3
2.3k
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
180
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
200
Transcript
Testing Go CLI Applications with Test Script Jakub Jarosz Belfast
Gophers Meetup - February 2023
cli applications http://blog.chriss-baumann.de/2010/07/26/because-life-is-too-short-for-manual-testing
cli applications & testscript http://blog.chriss-baumann.de/2010/07/26/because-life-is-too-short-for-manual-testing
testscript - run commands exec echo 'Hello Gophers!' stdout 'Hello
Gophers\n'
testscript - run commands ! exec cat not_existing_file.txt stderr 'cat:
not_existing_file.txt: No such file or directory'
testscript - run binaries exec hello stdout 'Hello Belfast Gophers\n'
testscript - run binaries with args exec hello Shawn stdout
'Hello Gopher, Shawn' ! stderr .
testscript - run binaries with args ! exec hello !
stdout . stderr 'usage: Hello Gopher NAME'
testscript - code coverage
testscript - cmp & golden files exec hello Kate cmp
stdout golden.txt -- golden.txt -- Hello Gopher, Kate!
testscript - exists, grep & regex exec hello Michael -o
greet.txt exists greet.out grep 'Michael' greet.out
testscript - txtar files & dir structure -- misc/file1.txt --
... -- misc/subfolder/file2.txt -- ... -- etc/file3.txt -- ...
testscript - file operations cp rm mv mkdir …
testscript - comments & test phases # Test 1 -
run hello without argos ... # Test 2 - run hello with args ... # Test 3 - run hello with invalid args ...
testscript - env vars env API_KEY= ! exec myprog stderr
'API_KEY must be set'
testscript - conditions [go1.16] exec echo 'We have at least
Go 1.16' [!arm64] exec echo 'This is a non-arm64 machine' [darwin] exec echo 'We''re on macOS'
testscript - extensions (custom functions)
testscript - background test steps
testscript - example project structure ── hello ├── go.mod ├──
go.sum ├── hello.go ├── hello_test.go └── testdata └── script └── hello.txtar
testscript.Run func TestScript(t *testing.T) { testscript.Run(t, testscript.Params{ Dir: "testdata/script", })
}
testscript.RunMain func TestMain(m *testing.M) { os.Exit(testscript.RunMain(m, map[string]func() int{ "hello": hello.RunCLI,
})) }
testscript - standalone testscript runner testscript testdata/script/*
summary • Excellent for testing CLI tools and binaries •
Runs along other tests • Saves time • Builds confidence • It’s derived directly from the code used to test Go tool itself!
resources • pkg.go.dev/github.com/rogpeppe/go-i nternal/testscript • github.com/mvdan/go-internal • bitfieldconsulting.com/books/tests • github.com/MariaLetta/free-gophers-
pack • github.com/qba73/belfast-go-meetup • github.com/qba73/habit
Thank You! Jakub Jarosz github, twitter @qba73 | linkedin.com/in/jakubjarosz