From b3208586b8ed6ff066d0fea33f4c0a3ef56e136d Mon Sep 17 00:00:00 2001 From: Tom O'Connor Date: Wed, 2 Oct 2024 16:49:27 +0100 Subject: [PATCH] Add launch.json for debugging Go code --- .vscode/launch.json | 16 ++++++++++++++++ main.go | 17 ++++++++++++----- main_test.go | 3 +-- 3 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..ccf6859 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,16 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Launch Package", + "type": "go", + "request": "launch", + "mode": "auto", + "program": "${fileDirname}", + "args": ["list", "./..."] + } + ] +} \ No newline at end of file diff --git a/main.go b/main.go index be0d184..a5d4990 100644 --- a/main.go +++ b/main.go @@ -209,7 +209,7 @@ func runTest(ctx context.Context, args []string) error { args = append(args, "-test.run", fmt.Sprintf("^%s$", test)) for i := opts.Retry; i >= 0; i-- { cmd := exec.Command(bin, args...) - fmt.Println(cmd.String()) + // fmt.Println(cmd.String()) out, err := cmd.CombinedOutput() if err != nil { if i == 0 { @@ -284,7 +284,8 @@ func compileTestBin(pkg Package, tempdir string) (string, error) { func listDirTests(dir string) ([]string, error) { cmd := exec.Command("go", "test", "-list", ".") cmd.Dir = dir - fmt.Println(cmd.String()) + fmt.Println("Directory: ", dir) + // fmt.Println(cmd.String()) out, err := cmd.CombinedOutput() if err != nil { return nil, err @@ -301,9 +302,14 @@ func listDirTests(dir string) ([]string, error) { tests = append(tests, line) } + fmt.Printf("Found %d tests\n", len(tests)) + + if opts.Skip == nil && opts.Run == nil { + return tests, nil + } if len(opts.Skip) > 0 { - fmt.Println("skip", opts.Skip) + // fmt.Println("skip", opts.Skip) var filteredTests []string for _, test := range tests { shouldKeep := true @@ -329,7 +335,7 @@ func listDirTests(dir string) ([]string, error) { } if len(opts.Run) > 0 { - fmt.Println("run", opts.Run) + // fmt.Println("run", opts.Run) var filteredTests []string for _, test := range tests { shouldKeep := false @@ -353,6 +359,7 @@ func listDirTests(dir string) ([]string, error) { } tests = filteredTests } + fmt.Println("Filtered tests: ", tests) return tests, nil } @@ -360,7 +367,7 @@ func listDirTests(dir string) ([]string, error) { func listPackagesWithTests(patterns []string) ([]Package, error) { cmdArgs := append([]string{"list", "-test", "-f", "{{.ImportPath}} {{.Dir}}"}, patterns...) cmd := exec.Command("go", cmdArgs...) - fmt.Println(cmd.String()) + // fmt.Println(cmd.String()) out, err := cmd.CombinedOutput() if err != nil { fmt.Fprintln(os.Stderr, string(out)) diff --git a/main_test.go b/main_test.go index 3ee05fc..57b7b41 100644 --- a/main_test.go +++ b/main_test.go @@ -6,7 +6,6 @@ import ( "testing" "github.com/stretchr/testify/require" - "go.uber.org/goleak" ) func TestRun(t *testing.T) { @@ -43,7 +42,7 @@ func ExampleList() { } func TestMain(m *testing.M) { - goleak.VerifyTestMain(m) + // goleak.VerifyTestMain(m) } func checkErr(err error) {