Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix line comment #14

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions mod.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -37,8 +36,9 @@ func WithModules(t *testing.T, srcdir string, gomodfile io.Reader) (dir string)
t.Fatal("cannot copy a directory:", err)
}

src := filepath.Join(dir, "src")
var ok bool
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
err := filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
Expand All @@ -47,7 +47,7 @@ func WithModules(t *testing.T, srcdir string, gomodfile io.Reader) (dir string)
return nil
}

files, err := ioutil.ReadDir(path)
files, err := os.ReadDir(path)
if err != nil {
return err
}
Expand All @@ -56,7 +56,7 @@ func WithModules(t *testing.T, srcdir string, gomodfile io.Reader) (dir string)
// Prepend line directive to .go files
if filepath.Ext(file.Name()) == ".go" {
fn := filepath.Join(path, file.Name())
rel, err := filepath.Rel(dir, fn)
rel, err := filepath.Rel(src, fn)
if err != nil {
t.Fatal("cannot get relative path:", err)
}
Expand Down Expand Up @@ -98,7 +98,6 @@ func WithModules(t *testing.T, srcdir string, gomodfile io.Reader) (dir string)
t.Fatal("does not find go.mod")
}

src := filepath.Join(dir, "src")
entries, err := os.ReadDir(src)
if err != nil {
t.Fatal("unexpected error:", err)
Expand Down
25 changes: 16 additions & 9 deletions mod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package testutil
import (
"os"
"path/filepath"
"strings"
"testing"

"golang.org/x/tools/go/analysis/analysistest"
Expand All @@ -17,17 +18,23 @@ func TestWithModules(t *testing.T) {
path string
want string
}{
{filepath.Join(testdata, "src", "a", "a.go"), "//line src/a/a.go:1"},
{filepath.Join(testdata, "src", "a", "b", "b.go"), "//line src/a/b/b.go:1"},
{filepath.Join(testdata, "src", "a", "a.go"), "//line a/a.go:1"},
{filepath.Join(testdata, "src", "a", "b", "b.go"), "//line a/b/b.go:1"},
}
for _, tt := range tests {
b, err := os.ReadFile(tt.path)
if err != nil {
t.Fatal(err)
}
if got := string(b[:len(tt.want)]); got != tt.want {
t.Errorf("got %q, want %q", got, tt.want)
}
t.Run(tt.path, func(t *testing.T) {
t.Parallel()

src, err := os.ReadFile(tt.path)
if err != nil {
t.Fatal(err)
}

got, _, _ := strings.Cut(string(src), "\n")
if got != tt.want {
t.Errorf("got %q, want %q", got, tt.want)
}
})
}
})
}
Loading