Skip to content

Commit

Permalink
Add launch.json for debugging Go code
Browse files Browse the repository at this point in the history
  • Loading branch information
tomoconnor committed Oct 2, 2024
1 parent 666a053 commit b320858
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -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", "./..."]
}
]
}
17 changes: 12 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -353,14 +359,15 @@ func listDirTests(dir string) ([]string, error) {
}
tests = filteredTests
}
fmt.Println("Filtered tests: ", tests)

return tests, nil
}

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))
Expand Down
3 changes: 1 addition & 2 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/stretchr/testify/require"
"go.uber.org/goleak"
)

func TestRun(t *testing.T) {
Expand Down Expand Up @@ -43,7 +42,7 @@ func ExampleList() {
}

func TestMain(m *testing.M) {
goleak.VerifyTestMain(m)
// goleak.VerifyTestMain(m)
}

func checkErr(err error) {
Expand Down

0 comments on commit b320858

Please sign in to comment.