From f3e3e6509ca1d0346478c347e5ca7685cb7108f2 Mon Sep 17 00:00:00 2001 From: Fredrik Averpil Date: Sun, 21 Jul 2024 21:21:27 +0200 Subject: [PATCH] feat: windows support look for backslashes on windows, forward slashes on unix --- lua/neotest-golang/lib/find.lua | 4 +++- lua/neotest-golang/process.lua | 6 ++++-- lua/neotest-golang/runspec/namespace.lua | 3 ++- lua/neotest-golang/runspec/test.lua | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) 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 diff --git a/lua/neotest-golang/runspec/test.lua b/lua/neotest-golang/runspec/test.lua index eecfd4b1..ecc78f8e 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 = {} @@ -54,6 +53,7 @@ function M.build(pos, strategy) run_spec.context.parse_test_results = false end + logger.debug({ "RunSpec:", run_spec }) return run_spec end