fredrikaverpil / neotest-golang

Reliable Neotest adapter for running Go tests in Neovim.
MIT License
102 stars 9 forks source link

bug: windows not supported #147

Closed santiagorendong closed 1 month ago

santiagorendong commented 1 month ago

Did you check docs and existing issues?

Neovim version (nvim -v)

0.10.0

Operating system/version

Windows 10 Pro 22H2

Output from :checkhealth neotest-golang

neotest-golang: require("neotest-golang.health").check()

- OK Go binary found on PATH: C:\Program Files\Go\bin\go.EXE
- OK Found go.mod file for C:\Users\santiago.rendong\dev\rendxn\leetcode\arraystring\length_of_last_word_test.go in C:\Users\santiago.rendong\dev\rendxn\leetcode/go.mod
- OK neotest is available
- OK nvim-treesitter is available
- OK nio is available
- WARNING dap-go is not available
- OK plenary is available

Describe the bug

When running the nearest test with neotest.run.run() and the cursor is under the definition of the last test in that file, it errors with the following output:

neotest-golang: ...-data/lazy/neotest-golang/lua/neotest-golang/lib/cmd.lua:20: attempt to concatenate local 'cwd' (a nil value)
                            stack traceback:                                                                                                                                                     
...Local/nvim-data/lazy/neotest/lua/neotest/client/init.lua:89: in function '__concat'                                                                        ...-
data/lazy/neotest-golang/lua/neotest-golang/lib/cmd.lua:20: in function 'golist_data'                                                                     
.../lazy/neotest-golang/lua/neotest-golang/runspec/test.lua:17: in function 'build_spec'                                                                      
...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:76: in function '_run_tree'                                                                       
...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:65: in function <...cal/nvim-data/lazy/neotest/lua/neotest/client/runner.lua:22>                  
[C]: in function 'xpcall'                                                                                                                                     ...Local/nvim-data/lazy/
neotest/lua/neotest/client/init.lua:84: in function 'run_tree'                                                                        ...cal/nvim-data/lazy/
neotest/lua/neotest/consumers/run.lua:85: in function 'func'                                                                            .../AppData/Local/
nvim-data/lazy/nvim-nio/lua/nio/tasks.lua:173: in function <.../AppData/Local/nvim-data/lazy/nvim-nio/lua/nio/tasks.lua:172>        

Steps To Reproduce

  1. Open a test file
  2. Place your cursor under the last func TestXxx
  3. Run neotest.run.run()

Expected Behavior

Run the nearest test, no matter if it's under or above cursor.

Your Lua setup

{
  {
    "nvim-neotest/neotest",
    dependencies = {
      "nvim-neotest/nvim-nio",
      "nvim-lua/plenary.nvim",
      "antoinemadec/FixCursorHold.nvim",
      "nvim-treesitter/nvim-treesitter",
      "fredrikaverpil/neotest-golang",
    },
    config = function()
      local neotest = require("neotest")

      neotest.setup({
        adapters = {
          require("neotest-golang"),
        }
      })
    end,
  },
}
santiagorendong commented 1 month ago

I'm actually not sure if it should run the nearest or the next one. According to neotest docs, neotest.run.run() should run the nearest. In any case, I believe the concatenate should check for nil values.

fredrikaverpil commented 1 month ago

Hey @santiagorendong and thanks for the bug report.

I don't really have any control over what gets executed in terms of being "nearest". That's the responsibility of Neotest (the framework).

But, like you say, a nil-check is definitively something we can do here. However, there should never be a nil-value for the cwd which means this is likely an issue on Windows with this regex:

https://github.com/fredrikaverpil/neotest-golang/blob/main/lua/neotest-golang/runspec/test.lua#L16

I don't have easy access to Windows and I'm currently also on vacation (no laptop) but I suspect more issues on that OS, as I haven't tested the adapter on it at all. But if you have the time, you can try editing that regex so that it works with backslashes and see if you can get a value for cwd so you can at least run the test.

fredrikaverpil commented 1 month ago

You could try something like this:

string.match(pos.path, "(.+)[/\\]")

Or perhaps better:

local sep = package.config:sub(1,1)
string.match(pos.path, "(.+)" .. sep)
santiagorendong commented 1 month ago

I'll try and take a look. Don't worry about it for now, enjoy your vacations šŸ–ļø

fredrikaverpil commented 1 month ago

I haven't tested this myself on Windows yet, but if you like, you can give #149 a go by setting the branch and updating the plugin:

{
  "fredrikaverpil/neotest-golang",
  branch = "windows",
},

It would also be super helpful if you could enable logging (see the README for details) and filter the log to only show neotest-golang entries and then post the log here.

fredrikaverpil commented 1 month ago

@santiagorendong I had a quick look at this today, and I've fixed some issues for running individual tests. For me on Windows 11 with Powershell, there's a bunch of weird ANSI codes and whatnot that gets printed and garbled into the command execution output. This does not happen on macOS (or Linux as far as I know).

I've tried to mitigate some common ANSI codes by detecting them and stripping them out, but it's not perfect. Have a look at this to see what I mean:

{ '\27[?25l\27[2J\27[m\27[H{"Time":"2024-07
22T17:04:04.2598864+02:00","Action":"start","Package":"github.com/fredrikaverpil/neotest-golang"}', '{"Time":"2024-07-22T17:04:04.2605315+02:00","Action":"run","Package":"github.com/fredrikaverpil/neotest-golang","Test":"TestTopLevelWithSubTest"}', '{"Time":"2024-07-22T17:04:04.2606674+02:00","Action":"output","Package":"github.com/fredrikaverpil/neotest-golang","Test":"TestTopLevelWithSubTest","Output":"=== RUN TestTopLevelWithSubTest\\n"}', '{"Time":"2024-07-22T17:04:04.2606674+02:00","Action":"run","Package":"github.com/fredrikaverpil/neotest-golang","Test":"TestTopLevelWithSubTest/SubTest"}', '{"Time":"2024-07-22T17:04:04.2606674+02:00","Action":"output","Package":"github.com/fredrikaverpil/neotest-golang","Test":"TestTopLevelWithSubTest/SubTest","Output":"=== RUN TestTopLevelWithSubTest/SubTest\\n"}', '{"Time":"2024-07-22T17:04:04.2616854+02:00","Action":"output","Package":"github.com/fredrikaverpil/neotest-golang","Test":"TestTopLevelWithSubTest","Output":"--- PASS: TestTopLevelWithSubTest (0.01s)\\n"}', '{"Time":"2024-07-22T17:04:04.2623877+02:00","Action":"output","Package":"github.com/fredrikaverpil/neotest-golang","Test":"TestTopLevelWithSubTest/SubTest","Output":" --- PASS: TestTopLevelWithSubTest/SubTest (0.00s)\\n"}', '{"Time":"2024-07-22T17:04:04.2626941+02:00","Action":"pass","Package":"github.com/fredrikaverpil/neotest-golang","Test":"TestTopLevelWithSubTest/SubTest","Elapsed":0}', '{"Time":"2024-07-22T17:04:04.264017+02:00","Action":"pass","Package":"github.com/fredrikaverpil/neotest-golang","Test":"TestTopLevelWithSubTest","Elapsed":0.01}', '{"Time":"2024-07-22T17:04:04.2645792+02:00","Action":"output","Package":"github.com/fredrikaverpil/neotest-golang","Output":"PASS\\n"}', '{"Time":"2024-07-22T17:04:04.2651107+02:00","Action":"output","Package":"github.com/fredrikaverpil/neotest-golang","Output":"ok \\tgithub.com/fredrikaverpil/neotest-golang\\t(cached)\\n"}', '{"Time":"2024-07-22T17:04:04.2657592+02:00","Action":"pass","Package":"github.com/fredrikaverpil/neotest-golang","Elapsed":0.006}', "\27]0;C:\\Program Files\\Go\\bin\\go.EXE\a\27[?25h" }

Next, I'll have a look at running a directory of files, and a file of tests, as there's some issue there still remaining, preventing the test output to be parsed correctly... perhaps related to this ANSI code bonanza.

santiagorendong commented 1 month ago

Hi there, I didn't expect to you to get a draft going this quickly. Thanks for the overall effort and attitude šŸš€

I'll take a look now šŸ˜„

santiagorendong commented 1 month ago

I ran some tests from a table (the one in the discussion related to this issue) and it still gave me the same error. Here are the logs after filtering... It does look like some ANSI codes are getting through as well as some weird stuff going on with the TestFunc name i.e. "TestLengthOfLastW', 'ord/single_word"`

DEBUG | 2024-07-22T10:40:59Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] Searching for go.mod in C:\Users\santiago.rendong\dev\rendxn\leetcode\arraystring
DEBUG | 2024-07-22T10:40:59Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] Searching for go.mod in C:\Users\santiago.rendong\dev\rendxn\leetcode
DEBUG | 2024-07-22T10:40:59Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] Found go.mod at C:\Users\santiago.rendong\dev\rendxn\leetcode\go.mod
DEBUG | 2024-07-22T10:40:59Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] Go mod filepath C:\Users\santiago.rendong\dev\rendxn\leetcode\go.mod
DEBUG | 2024-07-22T10:40:59Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] Running Go list: go list -json ./... in C:\Users\santiago.rendong\dev\rendxn\leetcode
INFO | 2024-07-22T10:41:00Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:64 | [neotest-golang] Go list output:  { "Dir": "C:\\Users\\santiago.rendong\\dev\\rendxn\\leetcode\\arraystring", "ImportPath": "leetcode/arraystring", "Name": "arraystring", "Root": "C:\\Users\\santiago.rendong\\dev\\rendxn\\leetcode", "Module": { "Path": "leetcode", "Main": true, "Dir": "C:\\Users\\santiago.rendong\\dev\\rendxn\\leetcode", "GoMod": "C:\\Users\\santiago.rendong\\dev\\rendxn\\leetcode\\go.mod", "GoVersion": "1.22.1" }, "Match": [ "./..." ], "Stale": true, "StaleReason": "build ID mismatch", "GoFiles": [ "length_of_last_word.go" ], "Imports": [ "strings" ], "Deps": [ "errors", "internal/abi", "internal/bytealg", "internal/chacha8rand", "internal/coverage/rtcov", "internal/cpu", "internal/goarch", "internal/godebugs", "internal/goexperiment", "internal/goos", "internal/race", "internal/reflectlite", "internal/unsafeheader", "io", "runtime", "runtime/internal/atomic", "runtime/internal/math", "runtime/internal/sys", "strings", "sync", "sync/atomic", "unicode", "unicode/utf8", "unsafe" ], "TestGoFiles": [ "length_of_last_word_test.go" ], "TestImports": [ "testing" ] } 
INFO | 2024-07-22T10:41:00Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:64 | [neotest-golang] Test command: go test -json -v -race -count=1 leetcode/arraystring -run ^(^TestLengthOfLastWord$)$
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] Raw output from readfile { '\27[2J\27[m\27[H{"Time":"2024-07-22T10:41:03.6282708-05:00","Action":"start","Package":"leetcode/arraystring"}', '\27]0;C:\\Program Files\\Go\\bin\\go.EXE\a\27[?25h{"Time":"2024-07-22T10:41:03.9288903-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord', '"}\27[K', '{"Time":"2024-07-22T10:41:03.9295549-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord","Output":"=== RUN TestLengthOfLastWord\\n"}\27[K', '{"Time":"2024-07-22T10:41:03.9298879-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord', '/single_word"}\27[K', '{"Time":"2024-07-22T10:41:03.9298879-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/single_word","Output":"=== RUN TestLengthOfLastWord/single_word\\n"}\27[K', '{"Time":"2024-07-22T10:41:03.9304063-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord', '/multiple_words"}\27[K', '{"Time":"2024-07-22T10:41:03.9308903-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/multiple_words","Output":"=== RUN TestLengthOfLastWord/multiple_words\\n"}\27[K', '{"Time":"2024-07-22T10:41:03.9314066-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord', '/excess_whitespace"}\27[K', '{"Time":"2024-07-22T10:41:03.9314066-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/excess_whitespace","Output":"=== RUN TestLengthOfLastWord/excess_whitespace\\n"}\27[K', '{"Time":"2024-07-22T10:41:03.9319078-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord","Output":"--- PASS: TestLengthOfLastWord (0.00s)\\n"}\27[K', '{"Time":"2024-07-22T10:41:03.9324032-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/single_word","Output":" --- PASS: TestLengthOfLastWord/single_word (0.00s)\\n"}\27[K', '{"Time":"2024-07-22T10:41:03.9329074-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor', 'd/single_word","Elapsed":0}\27[K', '{"Time":"2024-07-22T10:41:03.9329074-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/multiple_words","Output":" --- PASS: TestLengthOfLastWord/multiple_words (0.00s)\\n"}\27[K', '{"Time":"2024-07-22T10:41:03.9333968-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor', 'd/multiple_words","Elapsed":0}\27[K', '{"Time":"2024-07-22T10:41:03.9333968-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/excess_whitespace","Output":" --- PASS: TestLengthOfLastWord/excess_whitespace (0.00s)\\n"}\27[K', '{"Time":"2024-07-22T10:41:03.9339009-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor', 'd/excess_whitespace","Elapsed":0}\27[K', '{"Time":"2024-07-22T10:41:03.9348982-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor', 'd","Elapsed":0}\27[K', '{"Time":"2024-07-22T10:41:03.9353473-05:00","Action":"output","Package":"leetcode/arraystring","Output":"PASS\\n"} ', '{"Time":"2024-07-22T10:41:04.9386529-05:00","Action":"output","Package":"leetcode/arraystring","Output":"ok \\tleetcode/', 'arraystring\\t1.310s\\n"}\27[K', '{"Time":"2024-07-22T10:41:04.9386529-05:00","Action":"pass","Package":"leetcode/arraystring","Elapsed":1.31}' }
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] Table should be stripped from ansi codes { { Action = "start", Package = "leetcode/arraystring", Time = "2024-07-22T10:41:03.6282708-05:00" }, '\27]0;C:\\Program Files\\Go\\bin\\go.EXE?25h{"Time":"2024-07-22T10:41:03.9288903-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord', '"}', '{"Time":"2024-07-22T10:41:03.9295549-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord","Output":"=== RUN TestLengthOfLastWord\\n"}', '{"Time":"2024-07-22T10:41:03.9298879-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord', '/single_word"}', '{"Time":"2024-07-22T10:41:03.9298879-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/single_word","Output":"=== RUN TestLengthOfLastWord/single_word\\n"}', '{"Time":"2024-07-22T10:41:03.9304063-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord', '/multiple_words"}', '{"Time":"2024-07-22T10:41:03.9308903-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/multiple_words","Output":"=== RUN TestLengthOfLastWord/multiple_words\\n"}', '{"Time":"2024-07-22T10:41:03.9314066-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord', '/excess_whitespace"}', '{"Time":"2024-07-22T10:41:03.9314066-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/excess_whitespace","Output":"=== RUN TestLengthOfLastWord/excess_whitespace\\n"}', '{"Time":"2024-07-22T10:41:03.9319078-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord","Output":"--- PASS: TestLengthOfLastWord (0.00s)\\n"}', '{"Time":"2024-07-22T10:41:03.9324032-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/single_word","Output":" --- PASS: TestLengthOfLastWord/single_word (0.00s)\\n"}', '{"Time":"2024-07-22T10:41:03.9329074-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor', 'd/single_word","Elapsed":0}', '{"Time":"2024-07-22T10:41:03.9329074-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/multiple_words","Output":" --- PASS: TestLengthOfLastWord/multiple_words (0.00s)\\n"}', '{"Time":"2024-07-22T10:41:03.9333968-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor', 'd/multiple_words","Elapsed":0}', '{"Time":"2024-07-22T10:41:03.9333968-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW', 'ord/excess_whitespace","Output":" --- PASS: TestLengthOfLastWord/excess_whitespace (0.00s)\\n"}', '{"Time":"2024-07-22T10:41:03.9339009-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor', 'd/excess_whitespace","Elapsed":0}', '{"Time":"2024-07-22T10:41:03.9348982-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor', 'd","Elapsed":0}', { Action = "output", Output = "PASS\n", Package = "leetcode/arraystring", Time = "2024-07-22T10:41:03.9353473-05:00" }, '{"Time":"2024-07-22T10:41:04.9386529-05:00","Action":"output","Package":"leetcode/arraystring","Output":"ok \\tleetcode/', 'arraystring\\t1.310s\\n"}', { Action = "pass", Elapsed = 1.31, Package = "leetcode/arraystring", Time = "2024-07-22T10:41:04.9386529-05:00" } }
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9295549-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9298879-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9298879-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9304063-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9308903-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9314066-05:00","Action":"run","Package":"leetcode/arraystring","Test":"TestLengthOfLastWord
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9314066-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9319078-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9324032-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9329074-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9329074-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9333968-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9333968-05:00","Action":"output","Package":"leetcode/arraystring","Test":"TestLengthOfLastW
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9339009-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:03.9348982-05:00","Action":"pass","Package":"leetcode/arraystring","Test":"TestLengthOfLastWor
WARN | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Failed to decode JSON line: {"Time":"2024-07-22T10:41:04.9386529-05:00","Action":"output","Package":"leetcode/arraystring","Output":"ok  \tleetcode/
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] Table JSON-decoded { { Action = "output", Output = "PASS\n", Package = "leetcode/arraystring", Time = "2024-07-22T10:41:03.9353473-05:00" }, { Action = "pass", Elapsed = 1.31, Package = "leetcode/arraystring", Time = "2024-07-22T10:41:04.9386529-05:00" } }
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] INVALID TEST DATA
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] {
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] INVALID TEST DATA
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] {
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] INVALID TEST DATA
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] {
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] INVALID TEST DATA
DEBUG | 2024-07-22T10:41:05Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] {
WARN | 2024-07-22T10:41:07Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:74 | [neotest-golang] Test(s) not associated (not found/executed):  { 'C:\\Users\\santiago.rendong\\dev\\rendxn\\leetcode\\arraystring\\length_of_last_word_test.go::TestLengthOfLastWord::"single word"', 'C:\\Users\\santiago.rendong\\dev\\rendxn\\leetcode\\arraystring\\length_of_last_word_test.go::TestLengthOfLastWord::"excess whitespace"', 'C:\\Users\\santiago.rendong\\dev\\rendxn\\leetcode\\arraystring\\length_of_last_word_test.go::TestLengthOfLastWord::"multiple words"', "C:\\Users\\santiago.rendong\\dev\\rendxn\\leetcode\\arraystring\\length_of_last_word_test.go::TestLengthOfLastWord" }
DEBUG | 2024-07-22T10:41:07Z-0500 | ...-data/lazy/neotest-golang/lua/neotest-golang/logging.lua:52 | [neotest-golang] {
santiagorendong commented 1 month ago

Oh, I misread. I see you only worked on a single test as of right now, my bad.

santiagorendong commented 1 month ago

I'm not familiar with Lua nor building and using local packages in Neovim, but I'll try my best.

fredrikaverpil commented 1 month ago

I just fixed the remaining stuff. But there's a huge problem with this "Failed to decode JSON" as weird codes are injected at some point and garbles up the JSON output. I'll have a more thorough look a bit later.

fredrikaverpil commented 1 month ago

Here's a workaround for you, which on my end passes all my tests...

First install gotestsum:

# make gotestsum available on $PATH by installing it
go install gotest.tools/gotestsum@latest

Then set the runner option, and instruct it to use gotestsum instead of go test:

  {
    "nvim-neotest/neotest",
    dependencies = {
      "nvim-neotest/nvim-nio",
      "nvim-lua/plenary.nvim",
      "antoinemadec/FixCursorHold.nvim",
      "nvim-treesitter/nvim-treesitter",
      {
        "fredrikaverpil/neotest-golang",
        branch = "windows", -- set PR branch
      },
    },
    config = function()
      require("neotest").setup({
        adapters = {
          require("neotest-golang")({ runner = "gotestsum" }), -- Registration with config
        },
      })
    end,
  },

Instead of relying on the Neotest-provided mechanism of capturing output from stdout, gotestsum is instead (already implemented) writing to JSON file. This doesn't introduce the ANSI codes which seems to come from the console somehow. Does it work on your end too?

Rendxn commented 1 month ago

gotestsum does work in Windows šŸ‘

On the other hand with the default test runner, I tried setting NO_COLOR in my $PROFILE and even though pwsh -c '$PSStyle.OutputRendering' printed PlainText, the temporary output file neotest prints to contained both ANSI chars and weird unexpected line breaks, which cause the json decoder to break. Not sure if it's pwsh or nio the one introducing the linebreaks, and running go test in pwsh does not show any line breaks.

I think I'll stick with your suggestion of using gotestsum, since supporting the default runner for Windows would be a lot of work that gotestsum does already.

fredrikaverpil commented 1 month ago

gotestsum does work in Windows šŸ‘

That's great to hear! šŸŽ‰

the temporary output file neotest prints to contained both ANSI chars and weird unexpected line breaks

Yes, I don't fully understand what is going on there either. I suspect that Windows terminals in general delegates processing to its "Console host". If this is true, this means different programs can behave differently. Did you ever try the Windows Terminal instead? It might behave differently. EDIT: see this: https://stackoverflow.com/a/33188523

Either way, I am going to merge this PR in, more or less as-is, since it enables the rudimental Windows support. But I'm going to hold off on adding docs to gotestsum and how to enable it, as I'm not entirely sure yet on what I want the config/parameters to look like. My plan was to not expose this until I had time to look into output streaming, where gotestsum could play an central part. But you can keep on setting runner = "gotestsum" and just keep an eye open for a potential change in how you configure it. Feel free to subscribe to #150 for this.