Skip to main content

A single command to test all my changed Go packages

go test $(git ls-files --modified | xargs dirname | uniq | xargs -I '{}' echo "./{}")

I work in a Go monolith with many packages, and my patches often span multiple patches. Before I push to CI, I like to test all the packages with changed files, but enumerating all those packages by hand is tedious.

I’ve automated this with a short shell script:

go test $(git ls-files --modified \
  | xargs dirname \
  | uniq \
  | xargs -I '{}' echo "./{}")

Here’s how it works: