Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Testing Go CLI Apps with TestScript
Search
Jakub Jarosz
February 23, 2023
Programming
270
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
78
Communicating with Tests
jakubjarosz
0
180
Testing Go Code
jakubjarosz
0
250
Releasing Go Apps with GoReleaser
jakubjarosz
0
390
Building Environments with Ansible
jakubjarosz
0
420
a quick look at webtest & pytest
jakubjarosz
1
1.3k
Data Driven Integration Testing
jakubjarosz
2
330
Multi Mechanize
jakubjarosz
0
150
Embracing Python for Software Testing - BDD Style
jakubjarosz
0
400
Other Decks in Programming
See All in Programming
Apple Intelligence を用いた個人情報誤送信防止、及びユーザーリクエスト体験の改善について
yukiny
0
330
HTML-in-Canvasで作る未来のWeb UI表現
clockmaker
4
4.7k
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
180
Atomic Design, Enforced: Scaling Mobile Design Systems (next.app devCon / droidCon Berlin 2026)
steliosf
PRO
0
170
Kotlinの15年とServer-Side Kotlin
n_takehata
1
110
phperだってパンチカードでコーディングしたい
o0h
PRO
0
290
contenteditable と日本語入力に向き合う
colorful12
0
190
コードレビューのボトルネックを"する側"と"される側"の両面から解消する
yub0n
2
1.6k
APNsからLive Activityを開始する話
yumnumm
0
170
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
110
パーソナライズPodcastを作った話
repunit11
0
140
Kubernetes祭り #2 OP/ED
bells17
0
110
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
The SEO identity crisis: Don't let AI make you average
varn
0
590
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
A Modern Web Designer's Workflow
chriscoyier
699
190k
Building a Scalable Design System with Sketch
lauravandoore
464
34k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
5
800
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
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