diff --git a/musttag_test.go b/musttag_test.go index 3fe4d99..f4885cd 100644 --- a/musttag_test.go +++ b/musttag_test.go @@ -1,41 +1,38 @@ -package musttag +package musttag_test import ( "io" - "os" - "os/exec" - "path/filepath" "testing" "go-simpler.org/assert" . "go-simpler.org/assert/EF" + "go-simpler.org/musttag" "golang.org/x/tools/go/analysis/analysistest" ) func TestAnalyzer(t *testing.T) { testdata := analysistest.TestData() - setupModules(t, testdata) t.Run("tests", func(t *testing.T) { - analyzer := New( - Func{Name: "example.com/custom.Function", Tag: "custom", ArgPos: 0}, - Func{Name: "(example.com/custom.Struct).Method", Tag: "custom", ArgPos: 0}, - Func{Name: "(example.com/custom.Interface).Method", Tag: "custom", ArgPos: 0}, + analyzer := musttag.New( + musttag.Func{Name: "example.com/custom.Function", Tag: "custom", ArgPos: 0}, + musttag.Func{Name: "(example.com/custom.Struct).Method", Tag: "custom", ArgPos: 0}, + musttag.Func{Name: "(example.com/custom.Interface).Method", Tag: "custom", ArgPos: 0}, ) - analysistest.Run(t, testdata, analyzer, "tests") + analysistest.Run(t, testdata, analyzer, "testdata") }) t.Run("bad Func.ArgPos", func(t *testing.T) { - analyzer := New( - Func{Name: "encoding/json.Marshal", Tag: "json", ArgPos: 10}, + analyzer := musttag.New( + musttag.Func{Name: "encoding/json.Marshal", Tag: "json", ArgPos: 10}, ) - err := analysistest.Run(nopT{}, testdata, analyzer, "tests")[0].Err + err := analysistest.Run(nopT{}, testdata, analyzer, "testdata")[0].Err assert.Equal[E](t, err.Error(), "musttag: Func.ArgPos cannot be 10: encoding/json.Marshal accepts only 1 argument(s)") }) } func TestFlags(t *testing.T) { - analyzer := New() + analyzer := musttag.New() analyzer.Flags.Usage = func() {} analyzer.Flags.SetOutput(io.Discard) @@ -58,15 +55,3 @@ func TestFlags(t *testing.T) { type nopT struct{} func (nopT) Errorf(string, ...any) {} - -// NOTE: analysistest does not yet support modules; -// see https://github.com/golang/go/issues/37054 for details. -func setupModules(t *testing.T, testdata string) { - t.Helper() - - err := os.Chdir(filepath.Join(testdata, "src")) - assert.NoErr[F](t, err) - - err = exec.Command("go", "work", "vendor").Run() - assert.NoErr[F](t, err) -} diff --git a/testdata/src/tests/builtins.go b/testdata/builtins.go similarity index 99% rename from testdata/src/tests/builtins.go rename to testdata/builtins.go index ee94ace..c187186 100644 --- a/testdata/src/tests/builtins.go +++ b/testdata/builtins.go @@ -1,4 +1,4 @@ -package tests +package testdata import ( "encoding/json" diff --git a/testdata/src/example.com/custom/custom.go b/testdata/example.com/custom/custom.go similarity index 100% rename from testdata/src/example.com/custom/custom.go rename to testdata/example.com/custom/custom.go diff --git a/testdata/src/example.com/custom/go.mod b/testdata/example.com/custom/go.mod similarity index 100% rename from testdata/src/example.com/custom/go.mod rename to testdata/example.com/custom/go.mod diff --git a/testdata/src/go.mod b/testdata/go.mod similarity index 93% rename from testdata/src/go.mod rename to testdata/go.mod index da0181c..76548bb 100644 --- a/testdata/src/go.mod +++ b/testdata/go.mod @@ -1,4 +1,4 @@ -module tests +module testdata go 1.20 diff --git a/testdata/src/go.sum b/testdata/go.sum similarity index 100% rename from testdata/src/go.sum rename to testdata/go.sum diff --git a/testdata/src/.gitignore b/testdata/src/.gitignore deleted file mode 100644 index 22d0d82..0000000 --- a/testdata/src/.gitignore +++ /dev/null @@ -1 +0,0 @@ -vendor diff --git a/testdata/src/go.work b/testdata/src/go.work deleted file mode 100644 index 64db62f..0000000 --- a/testdata/src/go.work +++ /dev/null @@ -1,6 +0,0 @@ -go 1.20 - -use ( - . - ./example.com/custom -) diff --git a/testdata/src/tests/tests.go b/testdata/tests.go similarity index 99% rename from testdata/src/tests/tests.go rename to testdata/tests.go index 0d4e766..6ee5ead 100644 --- a/testdata/src/tests/tests.go +++ b/testdata/tests.go @@ -1,4 +1,4 @@ -package tests +package testdata import "encoding/json"