diff --git a/lua/neotest-golang/lib/convert.lua b/lua/neotest-golang/lib/convert.lua index 3184e428..fe6ccfb8 100644 --- a/lua/neotest-golang/lib/convert.lua +++ b/lua/neotest-golang/lib/convert.lua @@ -81,6 +81,7 @@ function M.to_lua_pattern(str) "=", "<", ">", + "\\", } for _, character in ipairs(special_characters) do str = str:gsub("%" .. character, "%%%" .. character) 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..fbf8444b 100644 --- a/lua/neotest-golang/process.lua +++ b/lua/neotest-golang/process.lua @@ -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 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 diff --git a/lua/neotest-golang/runspec/test.lua b/lua/neotest-golang/runspec/test.lua index eecfd4b1..3bcd3375 100644 --- a/lua/neotest-golang/runspec/test.lua +++ b/lua/neotest-golang/runspec/test.lua @@ -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 = {} @@ -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