| 225 | } |
| 226 | |
| 227 | func RunSubtestFromContext(ctx context.Context, conf SubtestConfig) bool { |
| 228 | t := MustTFromContext(ctx) |
| 229 | t.Helper() |
| 230 | // NOTE: When `-failfast` is specified, t.Run may not run and return true. |
| 231 | // https://github.com/golang/go/blob/ae658cb19a265f3f4694cd4aec508b4565bda6aa/src/testing/testing.go#L1158-L1160 |
| 232 | var called bool |
| 233 | ok := t.Run(conf.Name, func(t *testing.T) { |
| 234 | called = true |
| 235 | t.Helper() |
| 236 | |
| 237 | timeout := conf.Timeout |
| 238 | if timeout == 0 { |
| 239 | timeout = defaultSubtestTimeout |
| 240 | } |
| 241 | _, ctx = NewWithContext(ctx, t) |
| 242 | runTestFromContext(ctx, TestConfig{ |
| 243 | Parallel: conf.Parallel, |
| 244 | Timeout: timeout, |
| 245 | Func: func(ctx context.Context, a *assertions.Assertion) { |
| 246 | t.Helper() |
| 247 | conf.Func(ctx, t, a) |
| 248 | }, |
| 249 | }) |
| 250 | }) |
| 251 | if ok && !called { |
| 252 | t.Skip("Subtest did not execute, perhaps due to `-failfast`") |
| 253 | } |
| 254 | return ok && called |
| 255 | } |
| 256 | |
| 257 | func RunSubtest(t *testing.T, conf SubtestConfig) bool { |
| 258 | t.Helper() |