Skip to content

Commit

Permalink
Add support for --skip in envtool tests run (FerretDB#3805)
Browse files Browse the repository at this point in the history
  • Loading branch information
KrishnaSindhur authored Dec 21, 2023
1 parent 3db735b commit df1499d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ tasks:
--shard-index={{.SHARD_INDEX}}
--shard-total={{.SHARD_TOTAL}}
--run='{{.TEST_RUN}}'
--skip='{{.TEST_SKIP}}'
--
-count=1
-timeout={{.TEST_TIMEOUT}}
Expand All @@ -228,6 +229,7 @@ tasks:
--shard-index={{.SHARD_INDEX}}
--shard-total={{.SHARD_TOTAL}}
--run='{{.TEST_RUN}}'
--skip='{{.TEST_SKIP}}'
--
-count=1
-timeout={{.TEST_TIMEOUT}}
Expand All @@ -253,6 +255,7 @@ tasks:
--shard-index={{.SHARD_INDEX}}
--shard-total={{.SHARD_TOTAL}}
--run='{{.TEST_RUN}}'
--skip='{{.TEST_SKIP}}'
--
-count=1
-timeout={{.TEST_TIMEOUT}}
Expand All @@ -278,6 +281,7 @@ tasks:
--shard-index={{.SHARD_INDEX}}
--shard-total={{.SHARD_TOTAL}}
--run='{{.TEST_RUN}}'
--skip='{{.TEST_SKIP}}'
--
-count=1
-timeout={{.TEST_TIMEOUT}}
Expand All @@ -303,6 +307,7 @@ tasks:
--shard-index={{.SHARD_INDEX}}
--shard-total={{.SHARD_TOTAL}}
--run='{{.TEST_RUN}}'
--skip='{{.TEST_SKIP}}'
--
-count=1
-timeout={{.TEST_TIMEOUT}}
Expand Down
3 changes: 2 additions & 1 deletion cmd/envtool/envtool.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ var cli struct {
ShardIndex uint `help:"Shard index, starting from 1."`
ShardTotal uint `help:"Total number of shards."`
Run string `help:"Run only tests matching the regexp."`
Skip string `help:"Skip tests matching the regexp."`

Args []string `arg:"" help:"Other arguments and flags for 'go test'." passthrough:""`
} `cmd:"" help:"Run tests."`
Expand Down Expand Up @@ -525,7 +526,7 @@ func main() {
err = testsRun(
ctx,
cli.Tests.Run.ShardIndex, cli.Tests.Run.ShardTotal,
cli.Tests.Run.Run, cli.Tests.Run.Args,
cli.Tests.Run.Run, cli.Tests.Run.Skip, cli.Tests.Run.Args,
logger,
)

Expand Down
12 changes: 10 additions & 2 deletions cmd/envtool/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func runGoTest(ctx context.Context, args []string, total int, times bool, logger
}()

cmd := exec.CommandContext(ctx, "go", append([]string{"test", "-json"}, args...)...)

logger.Debugf("Running %s", strings.Join(cmd.Args, " "))

cmd.Stderr = os.Stderr
Expand Down Expand Up @@ -354,7 +355,7 @@ func runGoTest(ctx context.Context, args []string, total int, times bool, logger

// testsRun runs tests specified by the shard index and total or by the run regex
// using `go test` with given extra args.
func testsRun(ctx context.Context, index, total uint, run string, args []string, logger *zap.SugaredLogger) error {
func testsRun(ctx context.Context, index, total uint, run, skip string, args []string, logger *zap.SugaredLogger) error {
logger.Debugf("testsRun: index=%d, total=%d, run=%q, args=%q", index, total, run, args)

var totalTest int
Expand Down Expand Up @@ -386,7 +387,14 @@ func testsRun(ctx context.Context, index, total uint, run string, args []string,
run += ")$"
}

return runGoTest(ctx, append([]string{"-run=" + run}, args...), totalTest, true, logger)
if skip != "" {
totalTest = 0
args = append(args, "-run="+run, "-skip="+skip)
} else {
args = append(args, "-run="+run)
}

return runGoTest(ctx, args, totalTest, true, logger)
}

// listTestFuncs returns a sorted slice of all top-level test functions (tests, benchmarks, examples, fuzz functions)
Expand Down

0 comments on commit df1499d

Please sign in to comment.