Skip to content

Commit

Permalink
feat: windows support
Browse files Browse the repository at this point in the history
look for backslashes on windows, forward slashes on unix
  • Loading branch information
fredrikaverpil committed Jul 21, 2024
1 parent f6657d8 commit d403b20
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
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
6 changes: 4 additions & 2 deletions lua/neotest-golang/process.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,17 @@ function M.decorate_with_go_package_and_test_name(
local folderpath = vim.fn.fnamemodify(test_data.neotest_data.path, ":h")
local tweaked_pos_id = pos_id:gsub(" ", "_")
tweaked_pos_id = tweaked_pos_id:gsub('"', "")
tweaked_pos_id = tweaked_pos_id:gsub("::", "/")
tweaked_pos_id = tweaked_pos_id:gsub("::", lib.find.os_path_sep)

for _, golistline in ipairs(golist_output) do
if folderpath == golistline.Dir then
for _, gotestline in ipairs(gotest_output) do
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.find.os_path_sep
.. lib.convert.to_lua_pattern(gotestline.Test)
.. "$"
match = tweaked_pos_id:find(pattern, 1, false)
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

0 comments on commit d403b20

Please sign in to comment.