In my project I have multiple packages and sub-directories. In top directory, I can run go test ./...
and it runs all the tests in all sub-directories. I have been reading for quite some time on how test only tests matching a given pattern or test name but unable to find a solution. By going through these (1 2 3 and godocs) I thought I could use this:
go test ./... -run mypattern
to run tests matching mypattern but for me it runs all the tests. For now I am using a combination of cd, find and grep to run tests matching my criteria.
You can try this:
git clone https://github.com/grafana/grafana-plugin-sdk-go.git
> go test -run TestJSON
=== RUN TestJSONNotice
=== RUN TestJSONNotice/notice_with_severity_and_text
--- PASS: TestJSONNotice (0.00s)
--- PASS: TestJSONNotice/notice_with_severity_and_text (0.00s)
=== RUN TestJSON
=== RUN TestJSON/json.Unmarshal_and_json.Marshal
=== RUN TestJSON/json.Unmarshal_and_json.Marshal/Should_run_without_error
=== RUN TestJSON/json.Unmarshal_and_json.Marshal/Should_create_equal_data
--- PASS: TestJSON (0.00s)
--- PASS: TestJSON/json.Unmarshal_and_json.Marshal (0.00s)
--- PASS: TestJSON/json.Unmarshal_and_json.Marshal/Should_run_without_error (0.00s)
--- PASS: TestJSON/json.Unmarshal_and_json.Marshal/Should_create_equal_data (0.00s)
PASS
ok github.com/grafana/grafana-plugin-sdk-go/data 0.016s
> cd data
> go test -run *TestJSON*
zsh: no matches found: *TestJSON*
> go test -run ^TestJSON*
zsh: no matches found: ^TestJSON*
> go test -v -cover --short -race ./... -run ^TestFloatAt*
zsh: no matches found: ^TestFloatAt*
Can someone please tell me how test only tests matching a given pattern or test name?