diff --git a/lua/neotest-golang/lib/find.lua b/lua/neotest-golang/lib/find.lua index bd2339cd..5b310902 100644 --- a/lua/neotest-golang/lib/find.lua +++ b/lua/neotest-golang/lib/find.lua @@ -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 @@ -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 diff --git a/lua/neotest-golang/process.lua b/lua/neotest-golang/process.lua index 964c4a4e..07464676 100644 --- a/lua/neotest-golang/process.lua +++ b/lua/neotest-golang/process.lua @@ -216,7 +216,7 @@ 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 @@ -224,7 +224,9 @@ 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.find.os_path_sep .. lib.convert.to_lua_pattern(gotestline.Test) .. "$" match = tweaked_pos_id:find(pattern, 1, false) diff --git a/lua/neotest-golang/runspec/namespace.lua b/lua/neotest-golang/runspec/namespace.lua index 3e3efe68..80b9c521 100644 --- a/lua/neotest-golang/runspec/namespace.lua +++ b/lua/neotest-golang/runspec/namespace.lua @@ -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