From 7c9bcece62043f5bec889917a3a168a7ec918223 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Thu, 2 Jan 2025 23:28:19 +0100 Subject: [PATCH] test: add more --- tests/go/internal/notest/notest.go | 3 + tests/go/internal/two/one_test.go | 5 + tests/go/internal/two/two_test.go | 5 + tests/go/lookup_spec.lua | 8 + tests/unit/golist_spec.lua | 367 ++++++++++------------------- 5 files changed, 151 insertions(+), 237 deletions(-) create mode 100644 tests/go/internal/notest/notest.go create mode 100644 tests/go/internal/two/one_test.go create mode 100644 tests/go/internal/two/two_test.go diff --git a/tests/go/internal/notest/notest.go b/tests/go/internal/notest/notest.go new file mode 100644 index 00000000..9fe52202 --- /dev/null +++ b/tests/go/internal/notest/notest.go @@ -0,0 +1,3 @@ +package notest + +func nope() {} diff --git a/tests/go/internal/two/one_test.go b/tests/go/internal/two/one_test.go new file mode 100644 index 00000000..2c231424 --- /dev/null +++ b/tests/go/internal/two/one_test.go @@ -0,0 +1,5 @@ +package two + +import "testing" + +func TestOne(t *testing.T) {} diff --git a/tests/go/internal/two/two_test.go b/tests/go/internal/two/two_test.go new file mode 100644 index 00000000..1302e4ef --- /dev/null +++ b/tests/go/internal/two/two_test.go @@ -0,0 +1,5 @@ +package two + +import "testing" + +func TestTwo(t *testing.T) {} diff --git a/tests/go/lookup_spec.lua b/tests/go/lookup_spec.lua index 9e8c57e2..327d00ea 100644 --- a/tests/go/lookup_spec.lua +++ b/tests/go/lookup_spec.lua @@ -40,6 +40,14 @@ describe("Lookup", function() ExampleTestSuite2 = "TestExampleTestSuite2", }, }, + [folderpath .. "/internal/two/one_test.go"] = { + package = "two", + replacements = {}, + }, + ["/Users/fredrik/code/public/neotest-golang/tests/go/internal/two/two_test.go"] = { + package = "two", + replacements = {}, + }, [folderpath .. "/internal/x/xtest_blackbox_test.go"] = { package = "x_test", replacements = {}, diff --git a/tests/unit/golist_spec.lua b/tests/unit/golist_spec.lua index 81faaeda..7fe5a1f3 100644 --- a/tests/unit/golist_spec.lua +++ b/tests/unit/golist_spec.lua @@ -8,96 +8,16 @@ describe("go list output from root", function() local output = lib.cmd.golist_data(tests_filepath) local first_entry = output[1] local expected = { - - Deps = { - "cmp", - "errors", - "fmt", - "internal/abi", - "internal/bytealg", - "internal/chacha8rand", - "internal/coverage/rtcov", - "internal/cpu", - "internal/fmtsort", - "internal/goarch", - "internal/godebugs", - "internal/goexperiment", - "internal/goos", - "internal/itoa", - "internal/oserror", - "internal/poll", - "internal/race", - "internal/reflectlite", - "internal/safefilepath", - "internal/syscall/execenv", - "internal/syscall/unix", - "internal/testlog", - "internal/unsafeheader", - "io", - "io/fs", - "math", - "math/bits", - "os", - "path", - "reflect", - "runtime", - "runtime/internal/atomic", - "runtime/internal/math", - "runtime/internal/sys", - "slices", - "sort", - "strconv", - "sync", - "sync/atomic", - "syscall", - "time", - "unicode", - "unicode/utf8", - "unsafe", - }, Dir = tests_filepath .. "/cmd/main", - GoFiles = { "main.go" }, ImportPath = "github.com/fredrikaverpil/neotest-golang/cmd/main", - Imports = { "fmt" }, - Match = { "./..." }, Module = { - Dir = tests_filepath, GoMod = tests_filepath .. "/go.mod", - Main = true, - Path = "github.com/fredrikaverpil/neotest-golang", }, Name = "main", - Root = tests_filepath, - Stale = true, TestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command XTestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command } - -- ignored keys, as they might differ between OS/CI/platforms/too often - -- and we are also not interested in them. - expected.Deps = nil - first_entry.Deps = nil - expected.GoFiles = nil - first_entry.GoFiles = nil - expected.Imports = nil - first_entry.Imports = nil - expected.Match = nil - first_entry.Match = nil - expected.Module.Dir = nil - first_entry.Module.Dir = nil - expected.Module.GoVersion = nil - first_entry.Module.GoVersion = nil - expected.Module.Main = nil - first_entry.Module.Main = nil - expected.Module.Path = nil - first_entry.Module.Path = nil - expected.Root = nil - first_entry.Root = nil - expected.Stale = nil - first_entry.Stale = nil - expected.TestImports = nil - first_entry.TestImports = nil - assert.are_same(vim.inspect(expected), vim.inspect(first_entry)) assert.are_same(expected, first_entry) end) @@ -108,97 +28,18 @@ describe("go list output from internal", function() local tests_filepath = vim.uv.cwd() .. "/tests/go" local internal_filepath = vim.uv.cwd() .. "/tests/go/internal" local output = lib.cmd.golist_data(internal_filepath) - local first_entry = output[2] + local first_entry = output[3] local expected = { - - Deps = { - "cmp", - "errors", - "fmt", - "internal/abi", - "internal/bytealg", - "internal/chacha8rand", - "internal/coverage/rtcov", - "internal/cpu", - "internal/fmtsort", - "internal/goarch", - "internal/godebugs", - "internal/goexperiment", - "internal/goos", - "internal/itoa", - "internal/oserror", - "internal/poll", - "internal/race", - "internal/reflectlite", - "internal/safefilepath", - "internal/syscall/execenv", - "internal/syscall/unix", - "internal/testlog", - "internal/unsafeheader", - "io", - "io/fs", - "math", - "math/bits", - "os", - "path", - "reflect", - "runtime", - "runtime/internal/atomic", - "runtime/internal/math", - "runtime/internal/sys", - "slices", - "sort", - "strconv", - "sync", - "sync/atomic", - "syscall", - "time", - "unicode", - "unicode/utf8", - "unsafe", - }, Dir = internal_filepath .. "/positions", - GoFiles = { "add.go" }, ImportPath = "github.com/fredrikaverpil/neotest-golang/internal/positions", - Match = { "./..." }, Module = { - Dir = tests_filepath, GoMod = tests_filepath .. "/go.mod", - GoVersion = "1.23.1", - Main = true, - Path = "github.com/fredrikaverpil/neotest-golang", }, Name = "positions", - Root = tests_filepath, - Stale = true, TestGoFiles = { "positions_test.go" }, XTestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command - TestImports = { "os", "testing" }, } - -- ignored keys, as they might differ between OS/CI/platforms/too often - -- and we are also not interested in them. - expected.Deps = nil - first_entry.Deps = nil - expected.GoFiles = nil - first_entry.GoFiles = nil - expected.Match = nil - first_entry.Match = nil - expected.Module.Dir = nil - first_entry.Module.Dir = nil - expected.Module.GoVersion = nil - first_entry.Module.GoVersion = nil - expected.Module.Main = nil - first_entry.Module.Main = nil - expected.Module.Path = nil - first_entry.Module.Path = nil - expected.Root = nil - first_entry.Root = nil - expected.Stale = nil - first_entry.Stale = nil - expected.TestImports = nil - first_entry.TestImports = nil - assert.are_same(vim.inspect(expected), vim.inspect(first_entry)) assert.are_same(expected, first_entry) end) @@ -211,93 +52,145 @@ describe("go list output from internal/positions", function() local output = lib.cmd.golist_data(positions_filepath) local first_entry = output[1] local expected = { - Deps = { - "cmp", - "errors", - "fmt", - "internal/abi", - "internal/bytealg", - "internal/chacha8rand", - "internal/coverage/rtcov", - "internal/cpu", - "internal/fmtsort", - "internal/goarch", - "internal/godebugs", - "internal/goexperiment", - "internal/goos", - "internal/itoa", - "internal/oserror", - "internal/poll", - "internal/race", - "internal/reflectlite", - "internal/safefilepath", - "internal/syscall/execenv", - "internal/syscall/unix", - "internal/testlog", - "internal/unsafeheader", - "io", - "io/fs", - "math", - "math/bits", - "os", - "path", - "reflect", - "runtime", - "runtime/internal/atomic", - "runtime/internal/math", - "runtime/internal/sys", - "slices", - "sort", - "strconv", - "sync", - "sync/atomic", - "syscall", - "time", - "unicode", - "unicode/utf8", - "unsafe", - }, Dir = positions_filepath, - GoFiles = { "add.go" }, ImportPath = "github.com/fredrikaverpil/neotest-golang/internal/positions", - Match = { "./..." }, Module = { - Dir = tests_filepath, GoMod = tests_filepath .. "/go.mod", - GoVersion = "1.23.1", - Main = true, - Path = "github.com/fredrikaverpil/neotest-golang", }, Name = "positions", - Root = tests_filepath, - Stale = true, TestGoFiles = { "positions_test.go" }, XTestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command - TestImports = { "os", "testing" }, } - -- ignored keys, as they might differ between OS/CI/platforms/too often - -- and we are also not interested in them. - expected.Deps = nil - first_entry.Deps = nil - expected.GoFiles = nil - first_entry.GoFiles = nil - expected.Match = nil - first_entry.Match = nil - expected.Module.Dir = nil - first_entry.Module.Dir = nil - expected.Module.GoVersion = nil - first_entry.Module.GoVersion = nil - expected.Module.Main = nil - first_entry.Module.Main = nil - expected.Module.Path = nil - first_entry.Module.Path = nil - expected.Root = nil - first_entry.Root = nil - expected.Stale = nil - first_entry.Stale = nil - expected.TestImports = nil - first_entry.TestImports = nil + assert.are_same(vim.inspect(expected), vim.inspect(first_entry)) + assert.are_same(expected, first_entry) + end) +end) + +describe("go list output from internal/subpackage", function() + it("contains expected keys/values", function() + local tests_filepath = vim.uv.cwd() .. "/tests/go" + local filepath = vim.uv.cwd() .. "/tests/go/internal/subpackage" + local output = lib.cmd.golist_data(filepath) + local first_entry = output + local expected = { + { + Dir = filepath .. "/subpackage2", + ImportPath = "github.com/fredrikaverpil/neotest-golang/internal/subpackage/subpackage2", + Module = { + GoMod = tests_filepath .. "/go.mod", + }, + Name = "subpackage2", + TestGoFiles = { "subpackage2_test.go" }, + XTestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command + }, + { + Dir = filepath .. "/subpackage2/subpackage3", + ImportPath = "github.com/fredrikaverpil/neotest-golang/internal/subpackage/subpackage2/subpackage3", + Module = { + GoMod = tests_filepath .. "/go.mod", + }, + Name = "subpackage3", + TestGoFiles = { "subpackage3_test.go" }, + XTestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command + }, + } + + assert.are_same(vim.inspect(expected), vim.inspect(first_entry)) + assert.are_same(expected, first_entry) + end) +end) + +describe("go list output from internal/x", function() + it("contains expected keys/values", function() + local tests_filepath = vim.uv.cwd() .. "/tests/go" + local filepath = vim.uv.cwd() .. "/tests/go/internal/x" + local output = lib.cmd.golist_data(filepath) + local first_entry = output + local expected = { + { + Dir = filepath, + ImportPath = "github.com/fredrikaverpil/neotest-golang/internal/x", + Module = { + GoMod = tests_filepath .. "/go.mod", + }, + Name = "x", + TestGoFiles = { "xtest_whitebox_test.go" }, + XTestGoFiles = { "xtest_blackbox_test.go" }, -- NOTE: added here because of custom `go list -f` command + }, + } + + assert.are_same(vim.inspect(expected), vim.inspect(first_entry)) + assert.are_same(expected, first_entry) + end) +end) + +describe("go list output from internal/x", function() + it("contains TestGoFiles and XTestGoFiles", function() + local tests_filepath = vim.uv.cwd() .. "/tests/go" + local filepath = vim.uv.cwd() .. "/tests/go/internal/x" + local output = lib.cmd.golist_data(filepath) + local first_entry = output + local expected = { + { + Dir = filepath, + ImportPath = "github.com/fredrikaverpil/neotest-golang/internal/x", + Module = { + GoMod = tests_filepath .. "/go.mod", + }, + Name = "x", + TestGoFiles = { "xtest_whitebox_test.go" }, + XTestGoFiles = { "xtest_blackbox_test.go" }, -- NOTE: added here because of custom `go list -f` command + }, + } + + assert.are_same(vim.inspect(expected), vim.inspect(first_entry)) + assert.are_same(expected, first_entry) + end) +end) + +describe("go list output from internal/two", function() + it("contains two TestGoFiles", function() + local tests_filepath = vim.uv.cwd() .. "/tests/go" + local filepath = vim.uv.cwd() .. "/tests/go/internal/two" + local output = lib.cmd.golist_data(filepath) + local first_entry = output + local expected = { + { + Dir = filepath, + ImportPath = "github.com/fredrikaverpil/neotest-golang/internal/two", + Module = { + GoMod = tests_filepath .. "/go.mod", + }, + Name = "two", + TestGoFiles = { "one_test.go", "two_test.go" }, + XTestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command + }, + } + + assert.are_same(vim.inspect(expected), vim.inspect(first_entry)) + assert.are_same(expected, first_entry) + end) +end) + +describe("go list output from internal/notest", function() + it("contains no tests", function() + local tests_filepath = vim.uv.cwd() .. "/tests/go" + local filepath = vim.uv.cwd() .. "/tests/go/internal/notest" + local output = lib.cmd.golist_data(filepath) + local first_entry = output + local expected = { + { + Dir = filepath, + ImportPath = "github.com/fredrikaverpil/neotest-golang/internal/notest", + Module = { + GoMod = tests_filepath .. "/go.mod", + }, + Name = "notest", + TestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command + XTestGoFiles = {}, -- NOTE: added here because of custom `go list -f` command + }, + } assert.are_same(vim.inspect(expected), vim.inspect(first_entry)) assert.are_same(expected, first_entry)