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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Jakub Jarosz
February 23, 2023
Programming
0
240
Testing Go CLI Apps with TestScript
Jakub Jarosz
February 23, 2023
Tweet
Share
More Decks by Jakub Jarosz
See All by Jakub Jarosz
Benchmarking - First Steps
jakubjarosz
0
55
Communicating with Tests
jakubjarosz
0
140
Testing Go Code
jakubjarosz
0
230
Releasing Go Apps with GoReleaser
jakubjarosz
0
370
Building Environments with Ansible
jakubjarosz
0
400
a quick look at webtest & pytest
jakubjarosz
1
1.2k
Data Driven Integration Testing
jakubjarosz
2
310
Multi Mechanize
jakubjarosz
0
150
Embracing Python for Software Testing - BDD Style
jakubjarosz
0
380
Other Decks in Programming
See All in Programming
FOSDEM 2026: STUNMESH-go: Building P2P WireGuard Mesh Without Self-Hosted Infrastructure
tjjh89017
0
160
責任感のあるCloudWatchアラームを設計しよう
akihisaikeda
3
160
コマンドとリード間の連携に対する脅威分析フレームワーク
pandayumi
1
450
AI Agent Tool のためのバックエンドアーキテクチャを考える #encraft
izumin5210
6
1.8k
Kotlin Multiplatform Meetup - Compose Multiplatform 외부 의존성 아키텍처 설계부터 운영까지
wisemuji
0
190
360° Signals in Angular: Signal Forms with SignalStore & Resources @ngLondon 01/2026
manfredsteyer
PRO
0
120
Lambda のコードストレージ容量に気をつけましょう
tattwan718
0
110
AIエージェントのキホンから学ぶ「エージェンティックコーディング」実践入門
masahiro_nishimi
5
340
フロントエンド開発の勘所 -複数事業を経験して見えた判断軸の違い-
heimusu
7
2.8k
React 19でつくる「気持ちいいUI」- 楽観的UIのすすめ
himorishige
11
6k
Basic Architectures
denyspoltorak
0
660
フルサイクルエンジニアリングをAI Agentで全自動化したい 〜構想と現在地〜
kamina_zzz
0
400
Featured
See All Featured
Testing 201, or: Great Expectations
jmmastey
46
8k
Discover your Explorer Soul
emna__ayadi
2
1.1k
Test your architecture with Archunit
thirion
1
2.1k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
1
300
The Mindset for Success: Future Career Progression
greggifford
PRO
0
230
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
0
3.4k
Unsuck your backbone
ammeep
671
58k
Paper Plane (Part 1)
katiecoart
PRO
0
4k
We Have a Design System, Now What?
morganepeng
54
8k
Ten Tips & Tricks for a 🌱 transition
stuffmc
0
64
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
55k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
72
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