Skip to content

Instantly share code, notes, and snippets.

@laurentsenta
Last active August 24, 2023 09:05
Show Gist options
  • Save laurentsenta/5ed9fe9954605eefc1ed9ee2db7f66a9 to your computer and use it in GitHub Desktop.
Save laurentsenta/5ed9fe9954605eefc1ed9ee2db7f66a9 to your computer and use it in GitHub Desktop.
Tests Skips with Go
package skips
import (
"testing"
)
func TestAnother(t *testing.T) {
t.Run("a", func(t *testing.T) {
t.Run("b", func(t *testing.T) {
t.Fail()
})
t.Run("2", func(t *testing.T) {
})
})
}
func TestThird(t *testing.T) {
t.Run("a", func(t *testing.T) {
t.Run("b", func(t *testing.T) {
t.Fail()
})
t.Run("2", func(t *testing.T) {
})
})
}
func TestSkips(t *testing.T) {
t.Run("a", func(t *testing.T) {
t.Run("b", func(t *testing.T) {
t.Fail()
})
t.Run("2", func(t *testing.T) {
})
})
}
› go test ./skips/... -v ☹
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/b
=== RUN TestAnother/a/2
--- FAIL: TestAnother (0.00s)
--- FAIL: TestAnother/a (0.00s)
--- FAIL: TestAnother/a/b (0.00s)
--- PASS: TestAnother/a/2 (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/b
=== RUN TestThird/a/2
--- FAIL: TestThird (0.00s)
--- FAIL: TestThird/a (0.00s)
--- FAIL: TestThird/a/b (0.00s)
--- PASS: TestThird/a/2 (0.00s)
=== RUN TestSkips
=== RUN TestSkips/a
=== RUN TestSkips/a/b
=== RUN TestSkips/a/2
--- FAIL: TestSkips (0.00s)
--- FAIL: TestSkips/a (0.00s)
--- FAIL: TestSkips/a/b (0.00s)
--- PASS: TestSkips/a/2 (0.00s)
FAIL
FAIL github.com/ipfs/gateway-conformance/skips 0.377s
FAIL
# simple regexp, result is expected
› go test ./skips/... -skip "TestAnother/a/b" -v ☹
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/2
--- PASS: TestAnother (0.00s)
--- PASS: TestAnother/a (0.00s)
--- PASS: TestAnother/a/2 (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/b
=== RUN TestThird/a/2
--- FAIL: TestThird (0.00s)
--- FAIL: TestThird/a (0.00s)
--- FAIL: TestThird/a/b (0.00s)
--- PASS: TestThird/a/2 (0.00s)
=== RUN TestSkips
=== RUN TestSkips/a
=== RUN TestSkips/a/b
=== RUN TestSkips/a/2
--- FAIL: TestSkips (0.00s)
--- FAIL: TestSkips/a (0.00s)
--- FAIL: TestSkips/a/b (0.00s)
--- PASS: TestSkips/a/2 (0.00s)
FAIL
FAIL github.com/ipfs/gateway-conformance/skips 0.106s
FAIL
(
# equiv of (TestSkips) | (TestAnother/a/b)
› go test ./skips/... -skip "TestSkips|TestAnother/a/b" -v ☹
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/2
--- PASS: TestAnother (0.00s)
--- PASS: TestAnother/a (0.00s)
--- PASS: TestAnother/a/2 (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/b
=== RUN TestThird/a/2
--- FAIL: TestThird (0.00s)
--- FAIL: TestThird/a (0.00s)
--- FAIL: TestThird/a/b (0.00s)
--- PASS: TestThird/a/2 (0.00s)
FAIL
FAIL github.com/ipfs/gateway-conformance/skips 0.103s
FAIL
› go test ./skips/... -skip "(TestSkips|TestAnother)/a/b" -v ☹
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/2
--- PASS: TestAnother (0.00s)
--- PASS: TestAnother/a (0.00s)
--- PASS: TestAnother/a/2 (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/b
=== RUN TestThird/a/2
--- FAIL: TestThird (0.00s)
--- FAIL: TestThird/a (0.00s)
--- FAIL: TestThird/a/b (0.00s)
--- PASS: TestThird/a/2 (0.00s)
=== RUN TestSkips
=== RUN TestSkips/a
=== RUN TestSkips/a/2
--- PASS: TestSkips (0.00s)
--- PASS: TestSkips/a (0.00s)
--- PASS: TestSkips/a/2 (0.00s)
FAIL
FAIL github.com/ipfs/gateway-conformance/skips 0.271s
FAIL
› go test ./skips/... -v -skip "TestSkips|.*/a/b" ☹
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/2
--- PASS: TestAnother (0.00s)
--- PASS: TestAnother/a (0.00s)
--- PASS: TestAnother/a/2 (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/2
--- PASS: TestThird (0.00s)
--- PASS: TestThird/a (0.00s)
--- PASS: TestThird/a/2 (0.00s)
PASS
ok github.com/ipfs/gateway-conformance/skips 0.295s
# TestSkips is never matched,
# seems like this is due to golang's splitting the regexp + operator
# operator precedence means we are matching:
# [part1] against (.*)
# [part2] against a
# [part3] against (b|TestSkips)
# which gives a surprising results.
# we would use:
# (.*/a/b)|(TestSkips)
› go test ./skips/... -v -skip ".*/a/b|TestSkips" ☺
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/2
--- PASS: TestAnother (0.00s)
--- PASS: TestAnother/a (0.00s)
--- PASS: TestAnother/a/2 (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/2
--- PASS: TestThird (0.00s)
--- PASS: TestThird/a (0.00s)
--- PASS: TestThird/a/2 (0.00s)
=== RUN TestSkips
=== RUN TestSkips/a
--- PASS: TestSkips (0.00s)
--- PASS: TestSkips/a (0.00s)
PASS
ok github.com/ipfs/gateway-conformance/skips 0.100s
(
# Equivalent of Piotr's example:
# https://github.com/ipfs/gateway-conformance/pull/148#discussion_r1300140500
# Result is not expected, because we are matching:
# [part1] against (TestSkips|TestAnother/a/.*)
# Which means that TestSkips is skipped as expected
# "TestAnother/a/.*" does NOT match "TestAnother"
#
› go test ./skips/... -skip "(TestSkips|TestAnother/a/.*)" -v ☹
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/b
=== RUN TestAnother/a/2
--- FAIL: TestAnother (0.00s)
--- FAIL: TestAnother/a (0.00s)
--- FAIL: TestAnother/a/b (0.00s)
--- PASS: TestAnother/a/2 (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/b
=== RUN TestThird/a/2
--- FAIL: TestThird (0.00s)
--- FAIL: TestThird/a (0.00s)
--- FAIL: TestThird/a/b (0.00s)
--- PASS: TestThird/a/2 (0.00s)
FAIL
FAIL github.com/ipfs/gateway-conformance/skips 0.108s
FAIL
# these two results are confusing:
# in the first attempt, ".*/a/b|TestSkips", TestSkips is NOT matched, (see above, how parts are split)
# but in the second attempt, "TestAnother/a/2|TestSkips", TestSkips is matched.
# It seems like the presence of a regexp syntax changes precedence?
› go test ./skips/... -v -skip ".*/a/b|TestSkips" ☹
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/2
--- PASS: TestAnother (0.00s)
--- PASS: TestAnother/a (0.00s)
--- PASS: TestAnother/a/2 (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/2
--- PASS: TestThird (0.00s)
--- PASS: TestThird/a (0.00s)
--- PASS: TestThird/a/2 (0.00s)
=== RUN TestSkips
=== RUN TestSkips/a
--- PASS: TestSkips (0.00s)
--- PASS: TestSkips/a (0.00s)
PASS
ok github.com/ipfs/gateway-conformance/skips 0.100s
in ~/dev/plabs/gateway-conformance on feat-generate-dashboard
› go test ./skips/... -skip "TestAnother/a/2|TestSkips" -v ☺
=== RUN TestAnother
=== RUN TestAnother/a
=== RUN TestAnother/a/b
--- FAIL: TestAnother (0.00s)
--- FAIL: TestAnother/a (0.00s)
--- FAIL: TestAnother/a/b (0.00s)
=== RUN TestThird
=== RUN TestThird/a
=== RUN TestThird/a/b
=== RUN TestThird/a/2
--- FAIL: TestThird (0.00s)
--- FAIL: TestThird/a (0.00s)
--- FAIL: TestThird/a/b (0.00s)
--- PASS: TestThird/a/2 (0.00s)
FAIL
FAIL github.com/ipfs/gateway-conformance/skips 0.099s
FAIL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment