diff --git a/lua/neotest-dotnet/xunit/ts-queries.lua b/lua/neotest-dotnet/xunit/ts-queries.lua index 1fbbe14..5cf115d 100644 --- a/lua/neotest-dotnet/xunit/ts-queries.lua +++ b/lua/neotest-dotnet/xunit/ts-queries.lua @@ -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 ) diff --git a/tests/xunit/discover_positions/classdata_attribute_spec.lua b/tests/xunit/discover_positions/classdata_attribute_spec.lua index 5bc353b..ecbe05a 100644 --- a/tests/xunit/discover_positions/classdata_attribute_spec.lua +++ b/tests/xunit/discover_positions/classdata_attribute_spec.lua @@ -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(...)) @@ -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() @@ -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", + }, + }, }, }, }, diff --git a/tests/xunit/discover_positions/custom_attribute_spec.lua b/tests/xunit/discover_positions/custom_attribute_spec.lua index ecc51d4..aa191dd 100644 --- a/tests/xunit/discover_positions/custom_attribute_spec.lua +++ b/tests/xunit/discover_positions/custom_attribute_spec.lua @@ -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(...)) @@ -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() @@ -34,6 +56,7 @@ describe("discover_positions", function() }, { { + framework = "xunit", id = "./tests/xunit/specs/custom_attribute.cs::XUnitSamples", is_class = false, name = "XUnitSamples", @@ -43,6 +66,7 @@ describe("discover_positions", function() }, { { + framework = "xunit", id = "./tests/xunit/specs/custom_attribute.cs::XUnitSamples::CosmosConnectorTest", is_class = true, name = "CosmosConnectorTest", @@ -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", diff --git a/tests/xunit/discover_positions/fact_attribute_spec.lua b/tests/xunit/discover_positions/fact_attribute_spec.lua index e2c9c0d..1b53044 100644 --- a/tests/xunit/discover_positions/fact_attribute_spec.lua +++ b/tests/xunit/discover_positions/fact_attribute_spec.lua @@ -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() diff --git a/tests/xunit/discover_positions/theory_attribute_spec.lua b/tests/xunit/discover_positions/theory_attribute_spec.lua index 22afe71..d13136a 100644 --- a/tests/xunit/discover_positions/theory_attribute_spec.lua +++ b/tests/xunit/discover_positions/theory_attribute_spec.lua @@ -1,6 +1,7 @@ local async = require("nio").tests local plugin = require("neotest-dotnet") -local Tree = require("neotest.types").Tree +local DotnetUtils = require("neotest-dotnet.utils.dotnet-utils") +local stub = require("luassert.stub") A = function(...) print(vim.inspect(...)) @@ -13,74 +14,106 @@ describe("discover_positions", function() }, }) + before_each(function() + stub(DotnetUtils, "get_test_full_names", function() + return { + is_complete = true, + result = function() + return { + output = { + "xunit.testproj1.UnitTest1.Test1", + "xunit.testproj1.UnitTest1.Test2(a: 1)", + "xunit.testproj1.UnitTest1.Test2(a: 2)", + }, + result_code = 0, + } + end, + } + end) + end) + + after_each(function() + DotnetUtils.get_test_full_names:revert() + end) + async.it("should discover tests with inline parameters", function() local spec_file = "./tests/xunit/specs/theory_and_fact_mixed.cs" local spec_file_name = "theory_and_fact_mixed.cs" local positions = plugin.discover_positions(spec_file):to_list() - local function get_expected_output(file_path, file_name) + local function get_expected_output() return { { - id = file_path, - name = file_name, - path = file_path, + id = "./tests/xunit/specs/theory_and_fact_mixed.cs", + name = "theory_and_fact_mixed.cs", + path = "./tests/xunit/specs/theory_and_fact_mixed.cs", range = { 0, 0, 18, 0 }, type = "file", }, { { - id = file_path .. "::xunit.testproj1", + framework = "xunit", + id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit.testproj1", is_class = false, name = "xunit.testproj1", - path = file_path, + path = "./tests/xunit/specs/theory_and_fact_mixed.cs", range = { 0, 0, 17, 1 }, type = "namespace", }, { { - id = file_path .. "::xunit.testproj1::UnitTest1", + framework = "xunit", + id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit.testproj1::UnitTest1", is_class = true, name = "UnitTest1", - path = file_path, + path = "./tests/xunit/specs/theory_and_fact_mixed.cs", range = { 2, 0, 17, 1 }, type = "namespace", }, { { - id = file_path .. "::xunit.testproj1::UnitTest1::Test1", + framework = "xunit", + id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit.testproj1::UnitTest1::Test1", is_class = false, - name = "Test1", - path = file_path, + name = "xunit.testproj1.UnitTest1.Test1", + path = "./tests/xunit/specs/theory_and_fact_mixed.cs", range = { 4, 1, 8, 2 }, + running_id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit.testproj1::UnitTest1::Test1", type = "test", }, }, { { - id = file_path .. "::xunit.testproj1::UnitTest1::Test2", + framework = "xunit", + id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit.testproj1::UnitTest1::Test2", is_class = false, - name = "Test2", - path = file_path, + name = "xunit.testproj1.UnitTest1.Test2", + path = "./tests/xunit/specs/theory_and_fact_mixed.cs", range = { 10, 1, 16, 2 }, + running_id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit.testproj1::UnitTest1::Test2", type = "test", }, { { - id = file_path .. "::xunit.testproj1::UnitTest1::Test2(a: 1)", + framework = "xunit", + id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit::testproj1::UnitTest1::Test2(a: 1)", is_class = false, - name = "Test2(a: 1)", - path = file_path, - range = { 11, 12, 11, 15 }, + name = "xunit.testproj1.UnitTest1.Test2(a: 1)", + path = "./tests/xunit/specs/theory_and_fact_mixed.cs", + range = { 11, 1, 11, 2 }, + running_id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit.testproj1::UnitTest1::Test2", type = "test", }, }, { { - id = file_path .. "::xunit.testproj1::UnitTest1::Test2(a: 2)", + framework = "xunit", + id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit::testproj1::UnitTest1::Test2(a: 2)", is_class = false, - name = "Test2(a: 2)", - path = file_path, - range = { 12, 12, 12, 15 }, + name = "xunit.testproj1.UnitTest1.Test2(a: 2)", + path = "./tests/xunit/specs/theory_and_fact_mixed.cs", + range = { 12, 1, 12, 2 }, + running_id = "./tests/xunit/specs/theory_and_fact_mixed.cs::xunit.testproj1::UnitTest1::Test2", type = "test", }, }, @@ -90,7 +123,7 @@ describe("discover_positions", function() } end - assert.same(positions, get_expected_output(spec_file, spec_file_name)) + assert.same(positions, get_expected_output()) end) async.it("should discover tests in block scoped namespace", function() @@ -107,6 +140,7 @@ describe("discover_positions", function() }, { { + framework = "xunit", id = "./tests/xunit/specs/block_scoped_namespace.cs::xunit.testproj1", is_class = false, name = "xunit.testproj1", @@ -116,6 +150,7 @@ describe("discover_positions", function() }, { { + framework = "xunit", id = "./tests/xunit/specs/block_scoped_namespace.cs::xunit.testproj1::UnitTest1", is_class = true, name = "UnitTest1", @@ -125,17 +160,20 @@ describe("discover_positions", function() }, { { + framework = "xunit", id = "./tests/xunit/specs/block_scoped_namespace.cs::xunit.testproj1::UnitTest1::Test1", is_class = false, - name = "Test1", + name = "xunit.testproj1.UnitTest1.Test1", path = "./tests/xunit/specs/block_scoped_namespace.cs", range = { 4, 2, 8, 3 }, + running_id = "./tests/xunit/specs/block_scoped_namespace.cs::xunit.testproj1::UnitTest1::Test1", type = "test", }, }, }, }, } + assert.same(positions, expected_positions) end) end)