Skip to content

Commit 6a64eec

Browse files
committed
Add project-path flag to runner
1 parent c706391 commit 6a64eec

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

tools/flakeguard/cmd/run.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ var RunTestsCmd = &cobra.Command{
1515
Use: "run",
1616
Short: "Run tests to check if they are flaky",
1717
Run: func(cmd *cobra.Command, args []string) {
18+
projectPath, _ := cmd.Flags().GetString("project-path")
1819
testPackagesJson, _ := cmd.Flags().GetString("test-packages-json")
1920
testPackagesArg, _ := cmd.Flags().GetStringSlice("test-packages")
2021
runCount, _ := cmd.Flags().GetInt("run-count")
@@ -34,10 +35,11 @@ var RunTestsCmd = &cobra.Command{
3435
}
3536

3637
runner := runner.Runner{
37-
Verbose: true,
38-
RunCount: runCount,
39-
UseRace: useRace,
40-
FailFast: threshold == 1.0, // Fail test on first test run if threshold is 1.0
38+
ProjectPath: projectPath,
39+
Verbose: true,
40+
RunCount: runCount,
41+
UseRace: useRace,
42+
FailFast: threshold == 1.0, // Fail test on first test run if threshold is 1.0
4143
}
4244

4345
testResults, err := runner.RunTests(testPackages)
@@ -82,6 +84,7 @@ var RunTestsCmd = &cobra.Command{
8284
}
8385

8486
func init() {
87+
RunTestsCmd.Flags().StringP("project-path", "r", ".", "The path to the Go project. Default is the current directory. Useful for subprojects.")
8588
RunTestsCmd.Flags().String("test-packages-json", "", "JSON-encoded string of test packages")
8689
RunTestsCmd.Flags().StringSlice("test-packages", nil, "Comma-separated list of test packages to run")
8790
RunTestsCmd.Flags().IntP("run-count", "c", 1, "Number of times to run the tests")

tools/flakeguard/runner/runner.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import (
1414
)
1515

1616
type Runner struct {
17-
Verbose bool // If true, provides detailed logging.
18-
RunCount int // Number of times to run the tests.
19-
UseRace bool // Enable race detector.
20-
FailFast bool // Stop on first test failure.
17+
ProjectPath string // Path to the Go project directory.
18+
Verbose bool // If true, provides detailed logging.
19+
RunCount int // Number of times to run the tests.
20+
UseRace bool // Enable race detector.
21+
FailFast bool // Stop on first test failure.
2122
}
2223

2324
// RunTests executes the tests for each provided package and aggregates all results.
@@ -58,6 +59,7 @@ func (r *Runner) runTestPackage(testPackage string) ([]byte, bool, error) {
5859
log.Printf("Running command: go %s\n", strings.Join(args, " "))
5960
}
6061
cmd := exec.Command("go", args...)
62+
cmd.Dir = r.ProjectPath
6163

6264
// cmd.Env = append(cmd.Env, "GOFLAGS=-extldflags=-Wl,-ld_classic") // Ensure modules are enabled
6365
var out bytes.Buffer

0 commit comments

Comments
 (0)