Skip to content

Commit

Permalink
remove unused test case fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Nsidorenco committed Nov 13, 2024
1 parent db99a2c commit 643e37d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 35 deletions.
36 changes: 11 additions & 25 deletions lua/neotest-dotnet/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,8 @@ DotnetNeotestAdapter.root = function(path)
end

DotnetNeotestAdapter.is_test_file = function(file_path)
if not (vim.endswith(file_path, ".cs") or vim.endswith(file_path, ".fs")) then
return false
else
for _, test in pairs(vstest.discover_tests(file_path)) do
if test.CodeFilePath == file_path then
return true
end
end
end

return false
return (vim.endswith(file_path, ".cs") or vim.endswith(file_path, ".fs"))
and vstest.discover_tests(file_path)
end

DotnetNeotestAdapter.filter_dir = function(name)
Expand All @@ -40,6 +31,10 @@ local function get_match_type(captured_nodes)
end
end

---@param source string
---@param captured_nodes any
---@param tests_in_file table<string, TestCase>
---@param path string
---@return nil | neotest.Position | neotest.Position[]
local function build_position(source, captured_nodes, tests_in_file, path)
local match_type = get_match_type(captured_nodes)
Expand All @@ -49,12 +44,12 @@ local function build_position(source, captured_nodes, tests_in_file, path)
local positions = {}

if match_type == "test" then
for _, test in ipairs(tests_in_file) do
for id, test in pairs(tests_in_file) do
if
definition:start() <= test.LineNumber - 1 and test.LineNumber - 1 <= definition:end_()
then
table.insert(positions, {
id = test.Id,
id = id,
type = match_type,
path = path,
name = test.DisplayName,
Expand Down Expand Up @@ -84,20 +79,11 @@ DotnetNeotestAdapter.discover_positions = function(path)

local filetype = (vim.endswith(path, ".fs") and "fsharp") or "c_sharp"

local tests_in_file = vim
.iter(vstest.discover_tests(path))
:map(function(_, v)
return v
end)
:filter(function(test)
return test.CodeFilePath == path
end)
:totable()

---@type neotest.Tree?
local tests_in_file = vstest.discover_tests(path)

local tree

if #tests_in_file > 0 then
if tests_in_file then
local content = lib.files.read(path)
local lang = vim.treesitter.language.get_lang(filetype) or filetype
nio.scheduler()
Expand Down
15 changes: 7 additions & 8 deletions lua/neotest-dotnet/vstest_wrapper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,15 @@ local discovery_cache = {}
local build_semaphore = nio.control.semaphore(1)

---@class TestCase
---@field Id string
---@field CodeFilePath string
---@field DisplayName string
---@field FullyQualifiedName string
---@field Source string
---@field LineNumber integer

---@param path string
---@return table<string, TestCase> test_cases
---@return table<string, TestCase> | nil test_cases map from id -> test case
function M.discover_tests(path)
local json = {}
local json
local proj_info = M.get_proj_info(path)

if not proj_info.dll_file then
Expand All @@ -185,7 +184,7 @@ function M.discover_tests(path)
and modified_time
and modified_time <= cached.last_modified
then
return cached.content
return cached.content and cached.content[path]
end

local wait_file = nio.fn.tempname()
Expand Down Expand Up @@ -214,17 +213,17 @@ function M.discover_tests(path)
if done then
local content = M.spin_lock_wait_file(output_file, max_wait)

json = (content and vim.json.decode(content, { luanil = { object = true } })) or {}

logger.debug("file has been populated. Extracting test cases")

json = (content and vim.json.decode(content, { luanil = { object = true } }))

discovery_cache[proj_info.dll_file] = {
last_modified = modified_time,
content = json,
}
end

return json
return json and json[path]
end

---runs tests identified by ids.
Expand Down
18 changes: 16 additions & 2 deletions run_tests.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ module TestDiscovery =
else
ValueOption.None

type TestCaseDto =
{ CodeFilePath: string
DisplayName: string
LineNumber: int
FullyQualifiedName: string }

let discoveredTests = ConcurrentDictionary<string, TestCase seq>()

type PlaygroundTestDiscoveryHandler(resultFilePath, waitFilePath) =
Expand All @@ -76,8 +82,16 @@ module TestDiscovery =
use testsWriter = new StreamWriter(resultFilePath, append = false)

discoveredTests
|> _.Values
|> Seq.collect (Seq.map (fun testCase -> testCase.Id, testCase))
|> Seq.map (fun x ->
(x.Key,
x.Value
|> Seq.map (fun testCase ->
testCase.Id,
{ CodeFilePath = testCase.CodeFilePath
DisplayName = testCase.DisplayName
LineNumber = testCase.LineNumber
FullyQualifiedName = testCase.FullyQualifiedName })
|> Map))
|> Map
|> JsonConvert.SerializeObject
|> testsWriter.WriteLine
Expand Down

0 comments on commit 643e37d

Please sign in to comment.