Skip to content

Commit

Permalink
feat: windows support (#149)
Browse files Browse the repository at this point in the history
Note that this might also require setting runner="gotestsum"
  • Loading branch information
fredrikaverpil authored Jul 23, 2024
1 parent f6657d8 commit 956ba1b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions lua/neotest-golang/lib/convert.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ function M.to_lua_pattern(str)
"=",
"<",
">",
"\\",
}
for _, character in ipairs(special_characters) do
str = str:gsub("%" .. character, "%%%" .. character)
Expand Down
4 changes: 3 additions & 1 deletion lua/neotest-golang/lib/find.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local logger = require("neotest-golang.logging")

local M = {}

M.os_path_sep = package.config:sub(1, 1) -- "/" on Unix, "\" on Windows

--- Find a file upwards in the directory tree and return its path, if found.
--- @param filename string
--- @param start_path string
Expand All @@ -19,7 +21,7 @@ function M.file_upwards(filename, start_path)
while start_dir ~= home_dir do
logger.debug("Searching for " .. filename .. " in " .. start_dir)

local try_path = start_dir .. "/" .. filename
local try_path = start_dir .. M.os_path_sep .. filename
if vim.fn.filereadable(try_path) == 1 then
logger.debug("Found " .. filename .. " at " .. try_path)
return try_path
Expand Down
5 changes: 4 additions & 1 deletion lua/neotest-golang/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,13 @@ function M.decorate_with_go_package_and_test_name(
if gotestline.Action == "run" and gotestline.Test ~= nil then
if gotestline.Package == golistline.ImportPath then
local pattern = lib.convert.to_lua_pattern(folderpath)
.. "/(.-)/"
.. lib.find.os_path_sep
.. "(.-)"
.. "/"
.. lib.convert.to_lua_pattern(gotestline.Test)
.. "$"
match = tweaked_pos_id:find(pattern, 1, false)

if match ~= nil then
test_data.gotest_data.pkg = gotestline.Package
test_data.gotest_data.name = gotestline.Test
Expand Down
3 changes: 2 additions & 1 deletion lua/neotest-golang/runspec/namespace.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ local M = {}
--- @return neotest.RunSpec | neotest.RunSpec[] | nil
function M.build(pos)
--- @type string
local test_folder_absolute_path = string.match(pos.path, "(.+)/")
local test_folder_absolute_path =
string.match(pos.path, "(.+)" .. lib.find.os_path_sep)
local golist_data = lib.cmd.golist_data(test_folder_absolute_path)

--- @type string
Expand Down
4 changes: 2 additions & 2 deletions lua/neotest-golang/runspec/test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

local logger = require("neotest-golang.logging")
local lib = require("neotest-golang.lib")
local options = require("neotest-golang.options")
local dap = require("neotest-golang.features.dap")

local M = {}
Expand All @@ -13,7 +12,8 @@ local M = {}
--- @return neotest.RunSpec | neotest.RunSpec[] | nil
function M.build(pos, strategy)
--- @type string
local test_folder_absolute_path = string.match(pos.path, "(.+)/")
local test_folder_absolute_path =
string.match(pos.path, "(.+)" .. lib.find.os_path_sep)
local golist_data = lib.cmd.golist_data(test_folder_absolute_path)

--- @type string
Expand Down

0 comments on commit 956ba1b

Please sign in to comment.