Skip to content

Commit 62aadba

Browse files
authored
fix: file path normalization (#16)
* fix: file path normalization * normalize project paths
1 parent 8081c73 commit 62aadba

File tree

6 files changed

+15
-9
lines changed

6 files changed

+15
-9
lines changed

lua/neotest-vstest/client.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function client_discovery.get_client_for_project(project, solution)
2525
-- If not then do not create a client.
2626
local solution_projects = solution and dotnet_utils.get_solution_projects(solution)
2727
if solution_projects and #solution_projects.projects > 0 then
28-
local project_files = vim.tbl_map(function(proj)
29-
return proj.proj_file
30-
end, solution_projects.projects)
28+
local exists_in_solution = vim.iter(solution_projects.projects):any(function(solution_project)
29+
return solution_project == project
30+
end)
3131

32-
if not vim.list_contains(project_files, project.proj_file) then
32+
if not exists_in_solution then
3333
logger.debug(
3434
"neotest-vstest: project is not part of the solution projects: "
3535
.. vim.inspect(solution_projects.projects)

lua/neotest-vstest/dotnet_utils.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ local project_semaphore = {}
116116
---@param path string
117117
---@return DotnetProjectInfo?
118118
function dotnet_utils.get_proj_info(path)
119+
path = vim.fs.normalize(path)
119120
logger.debug("neotest-vstest: getting project info for " .. path)
120121

121122
local proj_file
@@ -208,7 +209,7 @@ function dotnet_utils.get_proj_info(path)
208209

209210
---@class DotnetProjectInfo
210211
local proj_data = {
211-
proj_file = proj_file,
212+
proj_file = vim.fs.normalize(proj_file),
212213
dll_file = properties.TargetPath,
213214
proj_dir = properties.MSBuildProjectDirectory,
214215
is_test_project = properties.IsTestProject == "true",
@@ -217,7 +218,7 @@ function dotnet_utils.get_proj_info(path)
217218

218219
setmetatable(proj_data, {
219220
__eq = function(a, b)
220-
return a.proj_file == b.proj_file
221+
return vim.fs.normalize(a.proj_file or "") == vim.fs.normalize(b.proj_file or "")
221222
end,
222223
})
223224

@@ -230,7 +231,7 @@ function dotnet_utils.get_proj_info(path)
230231
proj_info_cache[proj_data.proj_file] = proj_data
231232

232233
for _, item in ipairs(output.Items.Compile) do
233-
file_to_project_map[item.FullPath] = proj_data.proj_file
234+
file_to_project_map[vim.fs.normalize(item.FullPath)] = proj_data.proj_file
234235
end
235236

236237
semaphore.release()

lua/neotest-vstest/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ function DotnetNeotestAdapter.discover_positions(path)
311311
local tests_in_file = client:discover_tests_for_path(path)
312312

313313
if not tests_in_file or next(tests_in_file) == nil then
314+
logger.debug(string.format("neotest-vstest: no tests found for file %s", path))
314315
return
315316
end
316317

lua/neotest-vstest/mtp/init.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ local function map_test_cases(project, test_nodes)
3838
local test_cases = {}
3939
for _, node in ipairs(test_nodes) do
4040
local location = node["location.file"] or project.proj_file
41+
location = location and vim.fs.normalize(location)
4142
local line_number = node["location.line-start"] or node["location.line-end"] or 0
4243
local fully_qualified_name = node["location.type"]
4344
or node["location.method"]
@@ -92,6 +93,7 @@ end
9293

9394
function Client:discover_tests_for_path(path)
9495
self:discover_tests(path)
96+
path = vim.fs.normalize(path)
9597
return self.test_cases[path]
9698
end
9799

lua/neotest-vstest/vstest/client.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ function M.discover_tests_in_project(runner, project)
4242
for _, line in ipairs(lines) do
4343
---@type { File: string, Test: table }
4444
local decoded = vim.json.decode(line, { luanil = { object = true } }) or {}
45-
local tests = tests_in_files[decoded.File] or {}
45+
local file = vim.fs.normalize(decoded.File or "")
46+
local tests = tests_in_files[file] or {}
4647

4748
local test = {
4849
[decoded.Test.Id] = {
@@ -53,7 +54,7 @@ function M.discover_tests_in_project(runner, project)
5354
},
5455
}
5556

56-
tests_in_files[decoded.File] = vim.tbl_extend("force", tests, test)
57+
tests_in_files[file] = vim.tbl_extend("force", tests, test)
5758
end
5859

5960
-- DisplayName may be almost equal to FullyQualifiedName of a test

lua/neotest-vstest/vstest/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ end
7676

7777
function Client:discover_tests_for_path(path)
7878
self:discover_tests(path)
79+
path = vim.fs.normalize(path)
7980
return self.test_cases[path]
8081
end
8182

0 commit comments

Comments
 (0)