Skip to content

"Run nearest" runs all tests #83

@fredrikaverpil

Description

@fredrikaverpil

When I "run nearest test" (require("neotest").run.run()) when positioning my cursor on the test function, I can see how neotest-go executes all tests.

Inspecting the go test command generated by neotest-go

I inspected the go test command produced by printing the command variable value in init.lua:

local command = vim.tbl_flatten({
  ...
})
print(vim.inspect(command))

...which gave me this command:

{ "cd", "/Users/fredrik/code/public/go-playground/bugs/neotest-go", "&&", "go", "test", "-v", "-json", "", "-coverprofile=/Users/fredrik/code/public/go-playground/bugs/neotest-go/coverage.out", "./" }

Note that I'm adding coverprofile myself here.

I would've expected something different, such as having added the -run flag to go test along with a regex matching the test name to the command. For example: go test -run ^Test_Level_1$ to the command.

Inspecting the tests map returned by marshal_gotest_output.tests

I then inspected the value of the tests returned from marshal_gotest_output which again shows how a bunch of tests in other files are being executed.

{
 ["neotest-go::TestAdd"] = {
   file_output = {},
   output = { "=== RUN   TestAdd\n", "\27[32m--- PASS: TestAdd (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "pass" },
   status = "passed"
 },
 ["neotest-go::TestAddSubTestLevel1"] = {
   file_output = {},
   output = { "=== RUN   TestAddSubTestLevel1\n", "=== RUN   TestAddSubTestLevel1/Add1\n", "\27[32m--- PASS: TestAddSubTestLevel1 (0.00s)\n\27[0m", "\27[32m    --- PASS: TestAddSubTestLevel1/Add1 (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "pass" },
   status = "passed"
 },
 ["neotest-go::TestAddSubTestLevel1::Add1"] = {
   file_output = {},
   output = { "=== RUN   TestAddSubTestLevel1/Add1\n", "\27[32m    --- PASS: TestAddSubTestLevel1/Add1 (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "pass" },
   status = "passed"
 },
 ["neotest-go::TestAddSubTestLevel2"] = {
   file_output = {},
   output = { "=== RUN   TestAddSubTestLevel2\n", "=== RUN   TestAddSubTestLevel2/Add1\n", "=== RUN   TestAddSubTestLevel2/Add1/Add2\n", "    marshaloutput_test.go:31: 1 + 2 did not equal 3\n", "\27[31m--- FAIL: TestAddSubTestLevel2 (0.00s)\n\27[0m", "\27[31m    --- FAIL: TestAddSubTestLevel2/Add1 (0.00s)\n\27[0m", "\27[31m        --- FAIL: TestAddSubTestLevel2/Add1/Add2 (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "fail" },
   status = "failed"
 },
 ["neotest-go::TestAddSubTestLevel2::Add1"] = {
   file_output = {},
   output = { "=== RUN   TestAddSubTestLevel2/Add1\n", "\27[31m    --- FAIL: TestAddSubTestLevel2/Add1 (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "fail" },
   status = "failed"
 },
 ["neotest-go::TestAddSubTestLevel2::Add1::Add2"] = {
   file_output = {
     ["marshaloutput_test.go"] = {
       [31] = { "1 + 2 did not equal 3\n", "--- FAIL: TestAddSubTestLevel2/Add1/Add2 (0.00s)\n" }
     }
   },
   output = { "=== RUN   TestAddSubTestLevel2/Add1/Add2\n", "    marshaloutput_test.go:31: 1 + 2 did not equal 3\n", "\27[31m        --- FAIL: TestAddSubTestLevel2/Add1/Add2 (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "output", "fail" },
   status = "failed"
 },
 ["neotest-go::Test_Level_1"] = {
   file_output = {},
   output = { "=== RUN   Test_Level_1\n", "=== RUN   Test_Level_1/Level_2\n", "=== RUN   Test_Level_1/Level_2/Level_3\n", "\27[32m--- PASS: Test_Level_1 (0.00s)\n\27[0m", "\27[32m    --- PASS: Test_Level_1/Level_2 (0.00s)\n\27[0m", "\27[32m        --- PASS: Test_Level_1/Level_2/Level_3 (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "pass" },
   status = "passed"
 },
 ["neotest-go::Test_Level_1::Level_2"] = {
   file_output = {},
   output = { "=== RUN   Test_Level_1/Level_2\n", "\27[32m    --- PASS: Test_Level_1/Level_2 (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "pass" },
   status = "passed"
 },
 ["neotest-go::Test_Level_1::Level_2::Level_3"] = {
   file_output = {},
   output = { "=== RUN   Test_Level_1/Level_2/Level_3\n", "\27[32m        --- PASS: Test_Level_1/Level_2/Level_3 (0.00s)\n\27[0m" },
   progress = { "run", "output", "output", "pass" },
   status = "passed"
 }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions