Skip to content

Commit

Permalink
fix(dotnet-test): Fixes discover_positions tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Figgins committed Feb 22, 2024
1 parent ed70202 commit afdd1d4
Show file tree
Hide file tree
Showing 5 changed files with 186 additions and 49 deletions.
3 changes: 3 additions & 0 deletions lua/neotest-dotnet/xunit/ts-queries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ function M.get_queries(custom_attributes)
name: (identifier) @attribute_name (#any-of? @attribute_name "Fact" "ClassData" ]] .. custom_fact_attributes .. [[)
(attribute_argument_list
(attribute_argument
(name_equals
(identifier) @property_name (#match? @property_name "DisplayName$")
)
(string_literal
(string_literal_fragment) @display_name
)
Expand Down
84 changes: 74 additions & 10 deletions tests/xunit/discover_positions/classdata_attribute_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local async = require("nio").tests
local plugin = require("neotest-dotnet")
local DotnetUtils = require("neotest-dotnet.utils.dotnet-utils")
local stub = require("luassert.stub")

A = function(...)
print(vim.inspect(...))
Expand All @@ -12,6 +14,28 @@ describe("discover_positions", function()
},
})

before_each(function()
stub(DotnetUtils, "get_test_full_names", function()
return {
is_complete = true,
result = function()
return {
output = {
"XUnitSamples.ClassDataTests.Theory_With_Class_Data_Test(v1: 1, v2: 2)",
"XUnitSamples.ClassDataTests.Theory_With_Class_Data_Test(v1: -4, v2: 6)",
"XUnitSamples.ClassDataTests.Theory_With_Class_Data_Test(v1: -2, v2: 2)",
},
result_code = 0,
}
end,
}
end)
end)

after_each(function()
DotnetUtils.get_test_full_names:revert()
end)

async.it(
"should discover tests with classdata attribute without creating nested parameterized tests",
function()
Expand All @@ -22,39 +46,79 @@ describe("discover_positions", function()
local function get_expected_output(file_path, file_name)
return {
{
id = file_path,
name = file_name,
path = file_path,
id = "./tests/xunit/specs/classdata.cs",
name = "classdata.cs",
path = "./tests/xunit/specs/classdata.cs",
range = { 0, 0, 28, 0 },
type = "file",
},
{
{
id = file_path .. "::XUnitSamples",
framework = "xunit",
id = "./tests/xunit/specs/classdata.cs::XUnitSamples",
is_class = false,
name = "XUnitSamples",
path = file_path,
path = "./tests/xunit/specs/classdata.cs",
range = { 4, 0, 27, 1 },
type = "namespace",
},
{
{
id = file_path .. "::XUnitSamples::ClassDataTests",
framework = "xunit",
id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests",
is_class = true,
name = "ClassDataTests",
path = file_path,
path = "./tests/xunit/specs/classdata.cs",
range = { 6, 0, 15, 1 },
type = "namespace",
},
{
{
id = file_path .. "::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test",
framework = "xunit",
id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test",
is_class = false,
name = "Theory_With_Class_Data_Test",
path = file_path,
name = "XUnitSamples.ClassDataTests.Theory_With_Class_Data_Test",
path = "./tests/xunit/specs/classdata.cs",
range = { 8, 1, 14, 2 },
running_id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test",
type = "test",
},
{
{
framework = "xunit",
id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test(v1: 1, v2: 2)",
is_class = false,
name = "XUnitSamples.ClassDataTests.Theory_With_Class_Data_Test(v1: 1, v2: 2)",
path = "./tests/xunit/specs/classdata.cs",
range = { 9, 1, 9, 2 },
running_id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test",
type = "test",
},
},
{
{
framework = "xunit",
id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test(v1: -4, v2: 6)",
is_class = false,
name = "XUnitSamples.ClassDataTests.Theory_With_Class_Data_Test(v1: -4, v2: 6)",
path = "./tests/xunit/specs/classdata.cs",
range = { 10, 1, 10, 2 },
running_id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test",
type = "test",
},
},
{
{
framework = "xunit",
id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test(v1: -2, v2: 2)",
is_class = false,
name = "XUnitSamples.ClassDataTests.Theory_With_Class_Data_Test(v1: -2, v2: 2)",
path = "./tests/xunit/specs/classdata.cs",
range = { 11, 1, 11, 2 },
running_id = "./tests/xunit/specs/classdata.cs::XUnitSamples::ClassDataTests::Theory_With_Class_Data_Test",
type = "test",
},
},
},
},
},
Expand Down
26 changes: 26 additions & 0 deletions tests/xunit/discover_positions/custom_attribute_spec.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
local async = require("nio").tests
local plugin = require("neotest-dotnet")
local DotnetUtils = require("neotest-dotnet.utils.dotnet-utils")
local stub = require("luassert.stub")

A = function(...)
print(vim.inspect(...))
Expand All @@ -16,6 +18,26 @@ describe("discover_positions", function()
},
})

before_each(function()
stub(DotnetUtils, "get_test_full_names", function()
return {
is_complete = true,
result = function()
return {
output = {
"XUnitSamples.CosmosConnectorTest.Custom_Attribute_Tests",
},
result_code = 0,
}
end,
}
end)
end)

after_each(function()
DotnetUtils.get_test_full_names:revert()
end)

async.it(
"should discover tests with custom attribute when no other xUnit tests are present",
function()
Expand All @@ -34,6 +56,7 @@ describe("discover_positions", function()
},
{
{
framework = "xunit",
id = "./tests/xunit/specs/custom_attribute.cs::XUnitSamples",
is_class = false,
name = "XUnitSamples",
Expand All @@ -43,6 +66,7 @@ describe("discover_positions", function()
},
{
{
framework = "xunit",
id = "./tests/xunit/specs/custom_attribute.cs::XUnitSamples::CosmosConnectorTest",
is_class = true,
name = "CosmosConnectorTest",
Expand All @@ -52,6 +76,8 @@ describe("discover_positions", function()
},
{
{
display_name = "Custom attribute works ok",
framework = "xunit",
id = "./tests/xunit/specs/custom_attribute.cs::XUnitSamples::CosmosConnectorTest::Custom_Attribute_Tests",
is_class = false,
name = "Custom_Attribute_Tests",
Expand Down
34 changes: 20 additions & 14 deletions tests/xunit/discover_positions/fact_attribute_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,26 @@ describe("discover_positions", function()
},
})

stub(DotnetUtils, "get_test_full_names", function()
return {
is_complete = true,
result = function()
return {
output = {
"XUnitSamples.UnitTest1.Test1",
"XUnitSamples.UnitTest1+NestedClass.Test1",
"XUnitSamples.UnitTest1+NestedClass.Test2",
},
result_code = 0,
}
end,
}
before_each(function()
stub(DotnetUtils, "get_test_full_names", function()
return {
is_complete = true,
result = function()
return {
output = {
"XUnitSamples.UnitTest1.Test1",
"XUnitSamples.UnitTest1+NestedClass.Test1",
"XUnitSamples.UnitTest1+NestedClass.Test2",
},
result_code = 0,
}
end,
}
end)
end)

after_each(function()
DotnetUtils.get_test_full_names:revert()
end)

async.it("should discover single tests in sub-class", function()
Expand Down
Loading

0 comments on commit afdd1d4

Please sign in to comment.