From d88e5222d361fbdf755eb4626ce4f4c84a8e3430 Mon Sep 17 00:00:00 2001 From: Kai Jellinghaus Date: Fri, 3 Jun 2022 23:50:21 +0200 Subject: [PATCH 1/5] Add Traits to Integration Tests --- .../StructIntegrationTests.cs | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/tests/Silk.NET.SilkTouch.IntegrationTests/StructIntegrationTests.cs b/tests/Silk.NET.SilkTouch.IntegrationTests/StructIntegrationTests.cs index cbd62345cc..4b572e485a 100644 --- a/tests/Silk.NET.SilkTouch.IntegrationTests/StructIntegrationTests.cs +++ b/tests/Silk.NET.SilkTouch.IntegrationTests/StructIntegrationTests.cs @@ -10,7 +10,10 @@ namespace Silk.NET.SilkTouch.IntegrationTests; [UsesVerify] public class StructIntegrationTests { - [Fact] + [Fact, + Trait("Category", "Integration"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields")] public Task Test1() { var result = TestHelper.GetCSharpOutputFromCpp(@" @@ -23,7 +26,11 @@ public Task Test1() return Verifier.Verify(result); } - [Fact] + [Fact, + Trait("Category", "Integration"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields"), + Trait("Feature", "Inheritance")] public Task Test2() { var result = TestHelper.GetCSharpOutputFromCpp(@" @@ -33,7 +40,12 @@ struct vec4 : vec3 { float w; };"); return Verifier.Verify(result); } - [Fact(Skip = "Union Support")] + [Fact(Skip = "Union Support"), + Trait("Category", "Integration"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields"), + Trait("Feature", "Unions"), + Trait("Feature", "Nested Types")] public Task Test3() { // from https://en.cppreference.com/w/c/language/struct @@ -48,7 +60,10 @@ struct { long k, l; } w; return Verifier.Verify(result); } - [Fact] + [Fact, + Trait("Category", "Integration"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields")] public Task Test4() { // from https://en.cppreference.com/w/c/language/struct @@ -59,7 +74,11 @@ struct y { struct x *q; /* ... */ };"); return Verifier.Verify(result); } - [Fact(Skip = "Union Support")] + [Fact(Skip = "Union Support"), + Trait("Category", "Integration"), + Trait("Feature", "Fields"), + Trait("Feature", "Unions"), + Trait("Feature", "Fixed-Size Arrays")] public Task Test5() { // from https://en.cppreference.com/w/cpp/language/union @@ -75,7 +94,10 @@ union S return Verifier.Verify(result); } - [Fact(Skip = "Union Support")] + [Fact(Skip = "Union Support"), + Trait("Category", "Integration"), + Trait("Feature", "Fields"), + Trait("Feature", "Unions")] public Task Test6() { // from https://en.cppreference.com/w/cpp/language/union @@ -93,7 +115,12 @@ union S return Verifier.Verify(result); } - [Fact(Skip = "Union Support, Enum Support")] + + [Fact(Skip = "Union Support, Enum Support"), + Trait("Category", "Integration"), + Trait("Feature", "Fields"), + Trait("Feature", "Unions"), + Trait("Feature", "Enums")] public Task Test7() { // from https://en.cppreference.com/w/cpp/language/union From 344ac29ee4c1bc6b2e305896f77312152485ce8b Mon Sep 17 00:00:00 2001 From: Kai Jellinghaus Date: Sat, 4 Jun 2022 01:55:20 +0200 Subject: [PATCH 2/5] Add Trait based Filtering --- Silk.NET.sln | 15 ++++ .../Assembly.cs | 6 ++ .../EmitterFieldTests.cs | 20 ++++- .../EmitterNamespaceMemberTests.cs | 10 ++- .../EmitterNamespaceTests.cs | 10 ++- .../EmitterStructMemberFieldsTests.cs | 13 ++- .../EmitterStructTests.cs | 26 ++++-- .../IdentifierTests.cs | 12 ++- .../Silk.NET.SilkTouch.Emitter.Tests.csproj | 1 + .../Assembly.cs | 6 ++ ...Silk.NET.SilkTouch.IntegrationTests.csproj | 1 + .../StructIntegrationTests.cs | 24 ++++-- .../Assembly.cs | 6 ++ .../BasicXMLTests.cs | 4 +- .../FieldScrapingTests.cs | 12 ++- .../IdentityScrapingTests.cs | 6 +- .../NamespaceScrapingTests.cs | 12 ++- .../Silk.NET.SilkTouch.Scraper.Tests.csproj | 1 + .../StructMemberScrapingTests.cs | 10 ++- .../StructScrapingTests.cs | 8 +- .../Assembly.cs | 6 ++ .../Silk.NET.SilkTouch.Symbols.Tests.csproj | 1 + .../SymbolVisitorTests/FieldTests.cs | 16 +++- .../SymbolVisitorTests/IdentifierTests.cs | 4 +- .../SymbolVisitorTests/NamespaceTests.cs | 9 ++- .../SymbolVisitorTests/StructTests.cs | 23 ++++-- .../Silk.NET.SilkTouch.TestFramework.csproj | 20 +++++ .../SilkTouchTestFramework.cs | 81 +++++++++++++++++++ 28 files changed, 315 insertions(+), 48 deletions(-) create mode 100644 tests/Silk.NET.SilkTouch.Emitter.Tests/Assembly.cs create mode 100644 tests/Silk.NET.SilkTouch.IntegrationTests/Assembly.cs create mode 100644 tests/Silk.NET.SilkTouch.Scraper.Tests/Assembly.cs create mode 100644 tests/Silk.NET.SilkTouch.Symbols.Tests/Assembly.cs create mode 100644 tests/Silk.NET.SilkTouch.TestFramework/Silk.NET.SilkTouch.TestFramework.csproj create mode 100644 tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs diff --git a/Silk.NET.sln b/Silk.NET.sln index fc2e02a920..6bef765f62 100644 --- a/Silk.NET.sln +++ b/Silk.NET.sln @@ -80,6 +80,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.Scraper. EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.IntegrationTests", "tests\Silk.NET.SilkTouch.IntegrationTests\Silk.NET.SilkTouch.IntegrationTests.csproj", "{66FE736C-C407-44C3-A94E-4345E22AA95E}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.TestFramework", "tests\Silk.NET.SilkTouch.TestFramework\Silk.NET.SilkTouch.TestFramework.csproj", "{381D1039-3259-488F-BB25-D90EE63A3E82}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -330,6 +332,18 @@ Global {66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x64.Build.0 = Release|Any CPU {66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x86.ActiveCfg = Release|Any CPU {66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x86.Build.0 = Release|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|Any CPU.Build.0 = Debug|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|x64.ActiveCfg = Debug|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|x64.Build.0 = Debug|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|x86.ActiveCfg = Debug|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|x86.Build.0 = Debug|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Release|Any CPU.ActiveCfg = Release|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Release|Any CPU.Build.0 = Release|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Release|x64.ActiveCfg = Release|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Release|x64.Build.0 = Release|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Release|x86.ActiveCfg = Release|Any CPU + {381D1039-3259-488F-BB25-D90EE63A3E82}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -361,6 +375,7 @@ Global {795A93A6-9578-439F-BB08-07B148B1D4CE} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C} {5329AC43-7177-4953-AFAB-A9FA7B9A4C7C} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C} {66FE736C-C407-44C3-A94E-4345E22AA95E} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C} + {381D1039-3259-488F-BB25-D90EE63A3E82} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D} diff --git a/tests/Silk.NET.SilkTouch.Emitter.Tests/Assembly.cs b/tests/Silk.NET.SilkTouch.Emitter.Tests/Assembly.cs new file mode 100644 index 0000000000..80e6e1ddfb --- /dev/null +++ b/tests/Silk.NET.SilkTouch.Emitter.Tests/Assembly.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +[assembly: TestFramework("Silk.NET.SilkTouch.TestFramework.SilkTouchTestFramework", "Silk.NET.SilkTouch.TestFramework")] diff --git a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterFieldTests.cs b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterFieldTests.cs index 9720d68a7e..e3529ec522 100644 --- a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterFieldTests.cs +++ b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterFieldTests.cs @@ -13,7 +13,10 @@ namespace Silk.NET.SilkTouch.Emitter.Tests; public sealed class EmitterFieldIntegrationTests : EmitterTest { - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Fields"), + Trait("Target Language", "C#")] public void FieldIntegration() { var syntax = Transform(new FieldSymbol(new StructSymbol(new IdentifierSymbol("int"),ImmutableArray.Empty), new IdentifierSymbol("Test"))); @@ -22,7 +25,10 @@ public void FieldIntegration() Assert.Equal("public int Test;", result); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Fields"), + Trait("Target Language", "C#")] public void FieldIsPublic() { var syntax = Transform @@ -38,7 +44,10 @@ public void FieldIsPublic() Assert.Single(syntax!.Modifiers, x => x.IsKind(SyntaxKind.PublicKeyword)); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Fields"), + Trait("Target Language", "C#")] public void CorrectTypeIdentifier() { var syntax = Transform @@ -56,7 +65,10 @@ public void CorrectTypeIdentifier() Assert.Equal("int", type!.Identifier.Text); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Fields"), + Trait("Target Language", "C#")] public void CorrectIdentifier() { var syntax = Transform diff --git a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceMemberTests.cs b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceMemberTests.cs index dc239549aa..6d9acff5d2 100644 --- a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceMemberTests.cs +++ b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceMemberTests.cs @@ -10,7 +10,10 @@ namespace Silk.NET.SilkTouch.Emitter.Tests; public class EmitterNamespaceMemberTests : EmitterTest { - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Namespaces"), + Trait("Target Language", "C#")] public void SingleMemberIntegration() { var syntax = Transform(new NamespaceSymbol(new IdentifierSymbol("Test"), new [] @@ -22,7 +25,10 @@ public void SingleMemberIntegration() Assert.Equal("namespace Test\n{\npublic struct Test2\n{\n}\n}\n", result); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Namespaces"), + Trait("Target Language", "C#")] public void MultipleMembersIntegration() { var syntax = Transform(new NamespaceSymbol(new IdentifierSymbol("Test"), new [] diff --git a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceTests.cs b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceTests.cs index 80c39bc87c..7b479f1ce9 100644 --- a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceTests.cs +++ b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceTests.cs @@ -12,7 +12,10 @@ namespace Silk.NET.SilkTouch.Emitter.Tests; public class EmitterNamespaceTests : EmitterTest { - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Namespaces"), + Trait("Target Language", "C#")] public void NamespaceIntegration() { var syntax = Transform(new NamespaceSymbol(new IdentifierSymbol("Test"), ImmutableArray.Empty)); @@ -21,7 +24,10 @@ public void NamespaceIntegration() Assert.Equal("namespace Test\n{\n}\n", result); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Namespaces"), + Trait("Target Language", "C#")] public void CorrectIdentifier() { var syntax = Transform diff --git a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructMemberFieldsTests.cs b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructMemberFieldsTests.cs index 49d8a10f7b..31e2e8e775 100644 --- a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructMemberFieldsTests.cs +++ b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructMemberFieldsTests.cs @@ -9,7 +9,12 @@ namespace Silk.NET.SilkTouch.Emitter.Tests; public class EmitterStructMemberFieldsTests : EmitterTest { - [Fact] + + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields"), + Trait("Target Language", "C#")] public void SingleFieldIntegration() { var node = Transform @@ -37,7 +42,11 @@ public void SingleFieldIntegration() ); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields"), + Trait("Target Language", "C#")] public void MultipleFieldsIntegration() { var node = Transform diff --git a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructTests.cs b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructTests.cs index b04cff4f30..a1ac95439a 100644 --- a/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructTests.cs +++ b/tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructTests.cs @@ -10,28 +10,41 @@ namespace Silk.NET.SilkTouch.Emitter.Tests; public sealed class EmitterStructTests : EmitterTest { - [Fact] + + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Structs"), + Trait("Target Language", "C#")] public void StructSyntax() { var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"), ImmutableArray.Empty)); Assert.IsType(syntax); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Structs"), + Trait("Target Language", "C#")] public void StructKeyword() { var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"), ImmutableArray.Empty)) as StructDeclarationSyntax; Assert.Equal("struct", syntax!.Keyword.Text); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Structs"), + Trait("Target Language", "C#")] public void CorrectIdentifier() { var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"), ImmutableArray.Empty)) as StructDeclarationSyntax; Assert.Equal("Test", syntax!.Identifier.Text); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Structs"), + Trait("Target Language", "C#")] public void IsOnlyPublic() { var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"), ImmutableArray.Empty)) as StructDeclarationSyntax; @@ -39,7 +52,10 @@ public void IsOnlyPublic() Assert.Equal("public", @public.Text); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Feature", "Structs"), + Trait("Target Language", "C#")] public void IntegrationEmptyStruct() { // Note that this test also covers trivia, which is not checked otherwise. diff --git a/tests/Silk.NET.SilkTouch.Emitter.Tests/IdentifierTests.cs b/tests/Silk.NET.SilkTouch.Emitter.Tests/IdentifierTests.cs index 743f763bed..d66038ac48 100644 --- a/tests/Silk.NET.SilkTouch.Emitter.Tests/IdentifierTests.cs +++ b/tests/Silk.NET.SilkTouch.Emitter.Tests/IdentifierTests.cs @@ -8,7 +8,9 @@ namespace Silk.NET.SilkTouch.Emitter.Tests; public sealed class IdentifierTests : EmitterTest { - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Target Language", "C#")] public void IdentifierHasNoLeadingTrivia() { var node = Transform(new IdentifierSymbol("Test")); @@ -17,7 +19,9 @@ public void IdentifierHasNoLeadingTrivia() Assert.False(node.HasLeadingTrivia); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Target Language", "C#")] public void IdentifierHasNoTrailingTrivia() { var node = Transform(new IdentifierSymbol("Test")); @@ -26,7 +30,9 @@ public void IdentifierHasNoTrailingTrivia() Assert.False(node.HasTrailingTrivia); } - [Fact] + [Fact, + Trait("Category", "Emitter"), + Trait("Target Language", "C#")] public void IdentifierIntegration() { var node = Transform(new IdentifierSymbol("Test")); diff --git a/tests/Silk.NET.SilkTouch.Emitter.Tests/Silk.NET.SilkTouch.Emitter.Tests.csproj b/tests/Silk.NET.SilkTouch.Emitter.Tests/Silk.NET.SilkTouch.Emitter.Tests.csproj index b742995d2b..b8353a9609 100644 --- a/tests/Silk.NET.SilkTouch.Emitter.Tests/Silk.NET.SilkTouch.Emitter.Tests.csproj +++ b/tests/Silk.NET.SilkTouch.Emitter.Tests/Silk.NET.SilkTouch.Emitter.Tests.csproj @@ -18,6 +18,7 @@ + diff --git a/tests/Silk.NET.SilkTouch.IntegrationTests/Assembly.cs b/tests/Silk.NET.SilkTouch.IntegrationTests/Assembly.cs new file mode 100644 index 0000000000..80e6e1ddfb --- /dev/null +++ b/tests/Silk.NET.SilkTouch.IntegrationTests/Assembly.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +[assembly: TestFramework("Silk.NET.SilkTouch.TestFramework.SilkTouchTestFramework", "Silk.NET.SilkTouch.TestFramework")] diff --git a/tests/Silk.NET.SilkTouch.IntegrationTests/Silk.NET.SilkTouch.IntegrationTests.csproj b/tests/Silk.NET.SilkTouch.IntegrationTests/Silk.NET.SilkTouch.IntegrationTests.csproj index 888b7cd953..a6d8c8d43e 100644 --- a/tests/Silk.NET.SilkTouch.IntegrationTests/Silk.NET.SilkTouch.IntegrationTests.csproj +++ b/tests/Silk.NET.SilkTouch.IntegrationTests/Silk.NET.SilkTouch.IntegrationTests.csproj @@ -26,6 +26,7 @@ + diff --git a/tests/Silk.NET.SilkTouch.IntegrationTests/StructIntegrationTests.cs b/tests/Silk.NET.SilkTouch.IntegrationTests/StructIntegrationTests.cs index 4b572e485a..ce9cfcb13d 100644 --- a/tests/Silk.NET.SilkTouch.IntegrationTests/StructIntegrationTests.cs +++ b/tests/Silk.NET.SilkTouch.IntegrationTests/StructIntegrationTests.cs @@ -12,6 +12,8 @@ public class StructIntegrationTests { [Fact, Trait("Category", "Integration"), + Trait("Source Language", "C++"), + Trait("Target Language", "C#"), Trait("Feature", "Structs"), Trait("Feature", "Fields")] public Task Test1() @@ -27,7 +29,9 @@ public Task Test1() } [Fact, - Trait("Category", "Integration"), + Trait("Category", "Integration"), + Trait("Source Language", "C++"), + Trait("Target Language", "C#"), Trait("Feature", "Structs"), Trait("Feature", "Fields"), Trait("Feature", "Inheritance")] @@ -40,8 +44,10 @@ struct vec4 : vec3 { float w; };"); return Verifier.Verify(result); } - [Fact(Skip = "Union Support"), + [Fact, Trait("Category", "Integration"), + Trait("Source Language", "C++"), + Trait("Target Language", "C#"), Trait("Feature", "Structs"), Trait("Feature", "Fields"), Trait("Feature", "Unions"), @@ -62,6 +68,8 @@ struct { long k, l; } w; [Fact, Trait("Category", "Integration"), + Trait("Source Language", "C++"), + Trait("Target Language", "C#"), Trait("Feature", "Structs"), Trait("Feature", "Fields")] public Task Test4() @@ -74,8 +82,10 @@ struct y { struct x *q; /* ... */ };"); return Verifier.Verify(result); } - [Fact(Skip = "Union Support"), + [Fact, Trait("Category", "Integration"), + Trait("Source Language", "C++"), + Trait("Target Language", "C#"), Trait("Feature", "Fields"), Trait("Feature", "Unions"), Trait("Feature", "Fixed-Size Arrays")] @@ -94,8 +104,10 @@ union S return Verifier.Verify(result); } - [Fact(Skip = "Union Support"), + [Fact, Trait("Category", "Integration"), + Trait("Source Language", "C++"), + Trait("Target Language", "C#"), Trait("Feature", "Fields"), Trait("Feature", "Unions")] public Task Test6() @@ -116,8 +128,10 @@ union S } - [Fact(Skip = "Union Support, Enum Support"), + [Fact, Trait("Category", "Integration"), + Trait("Source Language", "C++"), + Trait("Target Language", "C#"), Trait("Feature", "Fields"), Trait("Feature", "Unions"), Trait("Feature", "Enums")] diff --git a/tests/Silk.NET.SilkTouch.Scraper.Tests/Assembly.cs b/tests/Silk.NET.SilkTouch.Scraper.Tests/Assembly.cs new file mode 100644 index 0000000000..80e6e1ddfb --- /dev/null +++ b/tests/Silk.NET.SilkTouch.Scraper.Tests/Assembly.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +[assembly: TestFramework("Silk.NET.SilkTouch.TestFramework.SilkTouchTestFramework", "Silk.NET.SilkTouch.TestFramework")] diff --git a/tests/Silk.NET.SilkTouch.Scraper.Tests/BasicXMLTests.cs b/tests/Silk.NET.SilkTouch.Scraper.Tests/BasicXMLTests.cs index 679d3e5cc9..ee46bb7ace 100644 --- a/tests/Silk.NET.SilkTouch.Scraper.Tests/BasicXMLTests.cs +++ b/tests/Silk.NET.SilkTouch.Scraper.Tests/BasicXMLTests.cs @@ -29,7 +29,9 @@ public class BasicXMLTests private const string TempFileHeader = @"/* This file is temporarily created for use by Silk.NET tests. If you don't intend to run such a test, feel free to delete this file. */"; - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Source Language", "C++")] public void BasicStructScrapingTest() { var tempFile = Path.GetTempFileName(); diff --git a/tests/Silk.NET.SilkTouch.Scraper.Tests/FieldScrapingTests.cs b/tests/Silk.NET.SilkTouch.Scraper.Tests/FieldScrapingTests.cs index 0944e0bf0d..03f0ac7a74 100644 --- a/tests/Silk.NET.SilkTouch.Scraper.Tests/FieldScrapingTests.cs +++ b/tests/Silk.NET.SilkTouch.Scraper.Tests/FieldScrapingTests.cs @@ -9,7 +9,9 @@ namespace Silk.NET.SilkTouch.Scraper.Tests; public class FieldScrapingTests { - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Fields")] public void FieldSymbol() { var doc = new XmlDocument(); @@ -21,7 +23,9 @@ public void FieldSymbol() var field = Assert.IsType(symbol); } - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Fields")] public void CorrectIdentifier() { var doc = new XmlDocument(); @@ -34,7 +38,9 @@ public void CorrectIdentifier() Assert.Equal("f2", field.Identifier.Value); } - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Fields")] public void CorrectType() { var doc = new XmlDocument(); diff --git a/tests/Silk.NET.SilkTouch.Scraper.Tests/IdentityScrapingTests.cs b/tests/Silk.NET.SilkTouch.Scraper.Tests/IdentityScrapingTests.cs index b87f69d2ae..8e4307c8f7 100644 --- a/tests/Silk.NET.SilkTouch.Scraper.Tests/IdentityScrapingTests.cs +++ b/tests/Silk.NET.SilkTouch.Scraper.Tests/IdentityScrapingTests.cs @@ -9,7 +9,8 @@ namespace Silk.NET.SilkTouch.Scraper.Tests; public class IdentityScrapingTests { - [Fact] + [Fact, + Trait("Category", "Scraper")] public void GeneratesNoSymbols() { var doc = new XmlDocument(); @@ -19,7 +20,8 @@ public void GeneratesNoSymbols() Assert.Empty(symbols); } - [Fact] + [Fact, + Trait("Category", "Scraper")] public void BindingsGeneratesNoSymbols() { var doc = new XmlDocument(); diff --git a/tests/Silk.NET.SilkTouch.Scraper.Tests/NamespaceScrapingTests.cs b/tests/Silk.NET.SilkTouch.Scraper.Tests/NamespaceScrapingTests.cs index 3d2082d313..8272af6382 100644 --- a/tests/Silk.NET.SilkTouch.Scraper.Tests/NamespaceScrapingTests.cs +++ b/tests/Silk.NET.SilkTouch.Scraper.Tests/NamespaceScrapingTests.cs @@ -9,7 +9,9 @@ namespace Silk.NET.SilkTouch.Scraper.Tests; public class NamespaceScrapingTests { - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Namespaces")] public void NamespaceSymbol() { var doc = new XmlDocument(); @@ -26,7 +28,9 @@ public void NamespaceSymbol() Assert.Equal(ClangScraper.LibraryNamespacePlaceholder, @namespace.Identifier.Value); } - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Namespaces")] public void NamespaceMember() { var doc = new XmlDocument(); @@ -48,7 +52,9 @@ public void NamespaceMember() } - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Namespaces")] public void MultipleNamespaceMembers() { var doc = new XmlDocument(); diff --git a/tests/Silk.NET.SilkTouch.Scraper.Tests/Silk.NET.SilkTouch.Scraper.Tests.csproj b/tests/Silk.NET.SilkTouch.Scraper.Tests/Silk.NET.SilkTouch.Scraper.Tests.csproj index bfed196b82..2dc0e93a11 100644 --- a/tests/Silk.NET.SilkTouch.Scraper.Tests/Silk.NET.SilkTouch.Scraper.Tests.csproj +++ b/tests/Silk.NET.SilkTouch.Scraper.Tests/Silk.NET.SilkTouch.Scraper.Tests.csproj @@ -23,6 +23,7 @@ + diff --git a/tests/Silk.NET.SilkTouch.Scraper.Tests/StructMemberScrapingTests.cs b/tests/Silk.NET.SilkTouch.Scraper.Tests/StructMemberScrapingTests.cs index 8b10f52886..0179dd2840 100644 --- a/tests/Silk.NET.SilkTouch.Scraper.Tests/StructMemberScrapingTests.cs +++ b/tests/Silk.NET.SilkTouch.Scraper.Tests/StructMemberScrapingTests.cs @@ -9,7 +9,10 @@ namespace Silk.NET.SilkTouch.Scraper.Tests; public class StructMemberScrapingTests { - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields")] public void SingleMember() { var doc = new XmlDocument(); @@ -28,7 +31,10 @@ public void SingleMember() ); } - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields")] public void MultipleMembers() { var doc = new XmlDocument(); diff --git a/tests/Silk.NET.SilkTouch.Scraper.Tests/StructScrapingTests.cs b/tests/Silk.NET.SilkTouch.Scraper.Tests/StructScrapingTests.cs index 11cdfc845a..94dcaef881 100644 --- a/tests/Silk.NET.SilkTouch.Scraper.Tests/StructScrapingTests.cs +++ b/tests/Silk.NET.SilkTouch.Scraper.Tests/StructScrapingTests.cs @@ -9,7 +9,9 @@ namespace Silk.NET.SilkTouch.Scraper.Tests; public class StructScrapingTests { - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Structs")] public void StructSymbol() { var doc = new XmlDocument(); @@ -21,7 +23,9 @@ public void StructSymbol() var @struct = Assert.IsType(symbol); } - [Fact] + [Fact, + Trait("Category", "Scraper"), + Trait("Feature", "Structs")] public void CorrectIdentifier() { var doc = new XmlDocument(); diff --git a/tests/Silk.NET.SilkTouch.Symbols.Tests/Assembly.cs b/tests/Silk.NET.SilkTouch.Symbols.Tests/Assembly.cs new file mode 100644 index 0000000000..80e6e1ddfb --- /dev/null +++ b/tests/Silk.NET.SilkTouch.Symbols.Tests/Assembly.cs @@ -0,0 +1,6 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Xunit; + +[assembly: TestFramework("Silk.NET.SilkTouch.TestFramework.SilkTouchTestFramework", "Silk.NET.SilkTouch.TestFramework")] diff --git a/tests/Silk.NET.SilkTouch.Symbols.Tests/Silk.NET.SilkTouch.Symbols.Tests.csproj b/tests/Silk.NET.SilkTouch.Symbols.Tests/Silk.NET.SilkTouch.Symbols.Tests.csproj index 7f22121823..f479c3e678 100644 --- a/tests/Silk.NET.SilkTouch.Symbols.Tests/Silk.NET.SilkTouch.Symbols.Tests.csproj +++ b/tests/Silk.NET.SilkTouch.Symbols.Tests/Silk.NET.SilkTouch.Symbols.Tests.csproj @@ -19,6 +19,7 @@ + diff --git a/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/FieldTests.cs b/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/FieldTests.cs index 169ebfa76c..d4b5ed5239 100644 --- a/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/FieldTests.cs +++ b/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/FieldTests.cs @@ -10,7 +10,9 @@ namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests; public class FieldTests { - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Fields")] public void FieldIsVisitedAsField() { var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol(""), ImmutableArray.Empty), new IdentifierSymbol("")); @@ -25,7 +27,9 @@ public void FieldIsVisitedAsField() .Verify("VisitField", Times.Once(), ItExpr.IsAny()); } - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Fields")] public void FieldIsVisitedAsMember() { var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol(""), ImmutableArray.Empty), new IdentifierSymbol("")); @@ -40,7 +44,9 @@ public void FieldIsVisitedAsMember() .Verify("VisitMember", Times.Once(), ItExpr.IsAny()); } - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Fields")] public void FieldTypeIsVisited() { var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol(""), ImmutableArray.Empty), new IdentifierSymbol("")); @@ -55,7 +61,9 @@ public void FieldTypeIsVisited() .Verify("VisitType", Times.Once(), ItExpr.IsAny()); } - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Fields")] public void FieldIdentifierIsVisited() { var symbol = new FieldSymbol(new StructSymbol(new IdentifierSymbol(""), ImmutableArray.Empty), new IdentifierSymbol("")); diff --git a/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/IdentifierTests.cs b/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/IdentifierTests.cs index f904c0880b..4b966473ef 100644 --- a/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/IdentifierTests.cs +++ b/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/IdentifierTests.cs @@ -9,7 +9,9 @@ namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests; public class IdentifierTests { - [Fact] + + [Fact, + Trait("Category", "Symbols")] public void IdentifierIsVisitedAsIdentifier() { var symbol = new IdentifierSymbol(""); diff --git a/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/NamespaceTests.cs b/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/NamespaceTests.cs index 5e0ddd7ad6..0cf502f7a1 100644 --- a/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/NamespaceTests.cs +++ b/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/NamespaceTests.cs @@ -10,7 +10,9 @@ namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests; public class NamespaceTests { - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Namespaces")] public void NamespaceIdentifierIsVisited() { var symbol = new NamespaceSymbol(new IdentifierSymbol(""), ImmutableArray.Empty); @@ -26,7 +28,10 @@ public void NamespaceIdentifierIsVisited() .Verify("VisitIdentifier", Times.Once(), ItExpr.IsAny()); } - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Namespaces"), + Trait("Feature", "Structs")] public void NamespaceMemberIsVisited() { var symbol = new NamespaceSymbol(new IdentifierSymbol(""), new [] diff --git a/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/StructTests.cs b/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/StructTests.cs index 7e902b0fb0..e303ee9a9a 100644 --- a/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/StructTests.cs +++ b/tests/Silk.NET.SilkTouch.Symbols.Tests/SymbolVisitorTests/StructTests.cs @@ -10,7 +10,9 @@ namespace Silk.NET.SilkTouch.Symbols.Tests.SymbolVisitorTests; public class StructTests { - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Structs")] public void StructSymbolIsVisitedAsType() { var symbol = new StructSymbol(new IdentifierSymbol(""), ImmutableArray.Empty); @@ -25,7 +27,9 @@ public void StructSymbolIsVisitedAsType() .Verify("VisitType", Times.Once(), ItExpr.IsAny()); } - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Structs")] public void StructSymbolIsVisitedAsStruct() { var symbol = new StructSymbol(new IdentifierSymbol(""), ImmutableArray.Empty); @@ -40,7 +44,9 @@ public void StructSymbolIsVisitedAsStruct() .Verify("VisitStruct", Times.Once(), ItExpr.IsAny()); } - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Structs")] public void StructIdentifierIsVisitedAsIdentifier() { var symbol = new StructSymbol(new IdentifierSymbol(""), ImmutableArray.Empty); @@ -55,7 +61,10 @@ public void StructIdentifierIsVisitedAsIdentifier() .Verify("VisitIdentifier", Times.Once(), ItExpr.IsAny()); } - [Fact] + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields")] public void StructFieldIsVisited() { var member = new FieldSymbol(new StructSymbol(new IdentifierSymbol("int"), ImmutableArray.Empty), new IdentifierSymbol("Test1")); @@ -74,7 +83,11 @@ public void StructFieldIsVisited() .Verify("VisitField", Times.Once(), ItExpr.Is(x => x == member)); } - [Fact] + + [Fact, + Trait("Category", "Symbols"), + Trait("Feature", "Structs"), + Trait("Feature", "Fields")] public void StructFieldsAreVisited() { var member1 = new FieldSymbol(new StructSymbol(new IdentifierSymbol("int"), ImmutableArray.Empty), new IdentifierSymbol("Test1")); diff --git a/tests/Silk.NET.SilkTouch.TestFramework/Silk.NET.SilkTouch.TestFramework.csproj b/tests/Silk.NET.SilkTouch.TestFramework/Silk.NET.SilkTouch.TestFramework.csproj new file mode 100644 index 0000000000..1d9cc064ce --- /dev/null +++ b/tests/Silk.NET.SilkTouch.TestFramework/Silk.NET.SilkTouch.TestFramework.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + + false + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + + + + diff --git a/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs b/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs new file mode 100644 index 0000000000..97c92a9b6b --- /dev/null +++ b/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Xunit; +using Xunit.Abstractions; +using Xunit.Sdk; + +namespace Silk.NET.SilkTouch.TestFramework +{ + public class SilkTouchTestFramework : XunitTestFramework + { + public static readonly Dictionary> TraitVerifiers = new() + { + ["Category"] = s => s is "Integration" or "Scraper" or "Symbols" or "Emitter", + ["Feature"] = s => s is "Enums" or "Fields" or "Fixed-Size Arrays" or "Inheritance" or "Namespaces" or "Nested Types" or "Structs" or "Unions", + ["Source Language"] = s => s is "C++", + ["Target Language"] = s => s is "C#", + }; + + public SilkTouchTestFramework(IMessageSink messageSink) + : base(messageSink) + { + } + + protected override ITestFrameworkDiscoverer CreateDiscoverer( + IAssemblyInfo assemblyInfo) + => new SilkTouchFrameworkDiscoverer( + assemblyInfo, + SourceInformationProvider, + DiagnosticMessageSink); + } + + public class SilkTouchFrameworkDiscoverer : XunitTestFrameworkDiscoverer + { + public SilkTouchFrameworkDiscoverer( + IAssemblyInfo assemblyInfo, + ISourceInformationProvider sourceProvider, + IMessageSink diagnosticMessageSink, + IXunitTestCollectionFactory? collectionFactory = null) + : base( + assemblyInfo, + sourceProvider, + diagnosticMessageSink, + collectionFactory) + { + } + + protected override bool FindTestsForMethod + ( + ITestMethod testMethod, + bool includeSourceInformation, + IMessageBus messageBus, + ITestFrameworkDiscoveryOptions discoveryOptions + ) + { + return base.FindTestsForMethod + (testMethod, includeSourceInformation, messageBus, discoveryOptions) && testMethod.Method + .GetCustomAttributes(typeof(TraitAttribute)) + .Select + ( + x => + { + var args = x.GetConstructorArguments().ToArray(); + var name = (string) args[0]; + var value = (string) args[1]; + return (name, value); + } + ) + .ToLookup(x => x.name, x => x.value) + .All + ( + x => + { + if (!SilkTouchTestFramework.TraitVerifiers.TryGetValue(x.Key, out var func)) return true; + + return x.All(func); + } + ); + } + } +} From 61be6e16c980b5eedd5e55564ac4d5382b842a71 Mon Sep 17 00:00:00 2001 From: Kai Jellinghaus Date: Sat, 4 Jun 2022 02:20:11 +0200 Subject: [PATCH 3/5] Change Test Framework to return Errror Tasks instead of skipping them --- .../for-contributors/generators/testing.md | 0 .../SilkTouchTestFramework.cs | 104 +++++++++++++++--- 2 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 documentation/for-contributors/generators/testing.md diff --git a/documentation/for-contributors/generators/testing.md b/documentation/for-contributors/generators/testing.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs b/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs index 97c92a9b6b..91fb7c3fc1 100644 --- a/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs +++ b/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Xml; using Xunit; using Xunit.Abstractions; using Xunit.Sdk; @@ -9,14 +10,18 @@ namespace Silk.NET.SilkTouch.TestFramework { public class SilkTouchTestFramework : XunitTestFramework { - public static readonly Dictionary> TraitVerifiers = new() + public static readonly Dictionary Features = new() { - ["Category"] = s => s is "Integration" or "Scraper" or "Symbols" or "Emitter", - ["Feature"] = s => s is "Enums" or "Fields" or "Fixed-Size Arrays" or "Inheritance" or "Namespaces" or "Nested Types" or "Structs" or "Unions", - ["Source Language"] = s => s is "C++", - ["Target Language"] = s => s is "C#", + ["Enums"] = false, + ["Fields"] = true, + ["Fixed-Size Arrays"] = true, + ["Inheritance"] = true, + ["Namespaces"] = true, + ["Nested Types"] = true, + ["Structs"] = true, + ["Unions"] = false, }; - + public SilkTouchTestFramework(IMessageSink messageSink) : base(messageSink) { @@ -53,9 +58,7 @@ protected override bool FindTestsForMethod ITestFrameworkDiscoveryOptions discoveryOptions ) { - return base.FindTestsForMethod - (testMethod, includeSourceInformation, messageBus, discoveryOptions) && testMethod.Method - .GetCustomAttributes(typeof(TraitAttribute)) + var traits = testMethod.Method.GetCustomAttributes(typeof(TraitAttribute)) .Select ( x => @@ -65,17 +68,84 @@ ITestFrameworkDiscoveryOptions discoveryOptions var value = (string) args[1]; return (name, value); } - ) - .ToLookup(x => x.name, x => x.value) - .All - ( - x => + ); + foreach (var (name, value) in traits) + { + if (name is "Category" && + value is not "Integration" and not "Scraper" and not "Symbols" and not "Emitter") + { + return this.ReportDiscoveredTestCase + ( + (ITestCase) new ExecutionErrorTestCase + ( + this.DiagnosticMessageSink, TestMethodDisplay.ClassAndMethod, TestMethodDisplayOptions.None, + testMethod, + "Category " + value + + " is not a valid category. Allowed values are \"Integration\", \"Scraper\", \"Symbols\", \"Emitter\"." + ), includeSourceInformation, messageBus + ); + } + + if (name is "Source Language" && + value is not "C++") + { + return this.ReportDiscoveredTestCase + ( + (ITestCase) new ExecutionErrorTestCase + ( + this.DiagnosticMessageSink, TestMethodDisplay.ClassAndMethod, TestMethodDisplayOptions.None, + testMethod, + "Source Language " + value + + " is not a valid language. Allowed values are \"C++\"." + ), includeSourceInformation, messageBus + ); + } + + if (name is "Target Language" && + value is not "C#") + { + return this.ReportDiscoveredTestCase + ( + (ITestCase) new ExecutionErrorTestCase + ( + this.DiagnosticMessageSink, TestMethodDisplay.ClassAndMethod, TestMethodDisplayOptions.None, + testMethod, + "Target Language " + value + + " is not a valid language. Allowed values are \"C#\"." + ), includeSourceInformation, messageBus + ); + } + + if (name is "Feature") + { + if (!SilkTouchTestFramework.Features.TryGetValue(value, out var flag)) { - if (!SilkTouchTestFramework.TraitVerifiers.TryGetValue(x.Key, out var func)) return true; + return this.ReportDiscoveredTestCase + ( + (ITestCase) new ExecutionErrorTestCase + ( + this.DiagnosticMessageSink, TestMethodDisplay.ClassAndMethod, + TestMethodDisplayOptions.None, testMethod, + "Feature Flag " + value + " is not a valid flag. Allowed values are " + String.Join + (", ", SilkTouchTestFramework.Features.Keys.Select(x => "\"" + x + "\"")) + "." + ), includeSourceInformation, messageBus + ); + } - return x.All(func); + if (!flag) + { + return this.ReportDiscoveredTestCase + ( + (ITestCase) new ExecutionErrorTestCase + ( + this.DiagnosticMessageSink, TestMethodDisplay.ClassAndMethod, + TestMethodDisplayOptions.None, testMethod, "Feature Flag " + value + " is not enabled." + ), includeSourceInformation, messageBus + ); } - ); + } + } + return base.FindTestsForMethod(testMethod, includeSourceInformation, messageBus, discoveryOptions); } } } From d8b51a7235a43e29c70c50b1f9d306febb29d9e5 Mon Sep 17 00:00:00 2001 From: Kai Jellinghaus Date: Sat, 4 Jun 2022 02:30:29 +0200 Subject: [PATCH 4/5] Change Test Framework to return Skipped Tasks when feature flags are disabled --- .../SilkTouchTestFramework.cs | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs b/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs index 91fb7c3fc1..99a0be6b83 100644 --- a/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs +++ b/tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using System.Xml; using Xunit; @@ -136,10 +137,10 @@ ITestFrameworkDiscoveryOptions discoveryOptions { return this.ReportDiscoveredTestCase ( - (ITestCase) new ExecutionErrorTestCase + (ITestCase) new DisabledTestCase ( - this.DiagnosticMessageSink, TestMethodDisplay.ClassAndMethod, - TestMethodDisplayOptions.None, testMethod, "Feature Flag " + value + " is not enabled." + "Flag " + value + " is not enabled", this.DiagnosticMessageSink, TestMethodDisplay.ClassAndMethod, + TestMethodDisplayOptions.None, testMethod ), includeSourceInformation, messageBus ); } @@ -147,5 +148,43 @@ ITestFrameworkDiscoveryOptions discoveryOptions } return base.FindTestsForMethod(testMethod, includeSourceInformation, messageBus, discoveryOptions); } + + private sealed class DisabledTestCase : XunitTestCase + { + private readonly string _skipReason; + + /// + [EditorBrowsable(EditorBrowsableState.Never)] + [Obsolete + ( + "Called by the de-serializer; should only be called by deriving classes for de-serialization purposes" + )] + public DisabledTestCase() : base() + { + _skipReason = "Generic Skip"; + } + + public DisabledTestCase + ( + string skipReason, + IMessageSink diagnosticMessageSink, + TestMethodDisplay defaultMethodDisplay, + TestMethodDisplayOptions defaultMethodDisplayOptions, + ITestMethod testMethod, + object[]? testMethodArguments = null + ) : base + ( + diagnosticMessageSink, defaultMethodDisplay, defaultMethodDisplayOptions, testMethod, + testMethodArguments + ) + { + _skipReason = skipReason; + } + + protected override string GetSkipReason(IAttributeInfo factAttribute) + { + return _skipReason; + } + } } } From 34861f338795b261997e8fefb061a53aeb6a5ec7 Mon Sep 17 00:00:00 2001 From: Kai Jellinghaus Date: Sat, 4 Jun 2022 02:38:35 +0200 Subject: [PATCH 5/5] Add Testing documentation --- .../for-contributors/generators/testing.md | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/documentation/for-contributors/generators/testing.md b/documentation/for-contributors/generators/testing.md index e69de29bb2..740e0b2c7c 100644 --- a/documentation/for-contributors/generators/testing.md +++ b/documentation/for-contributors/generators/testing.md @@ -0,0 +1,30 @@ +# Testing + +SilkTouch Generators should be extensively Tested. + +## Unit Tests + +### Traits + +All Unit & Integration tests should be flagged with the appropriate Category (Emitter, Scraper, Symbols, Integration) using `Trait("Category", "MyCategory")`. +Additionally the following Traits should be applied where appropriate: + +- `Target Language` this should be applied wherever a specific target language is tested (valid Values: `C#`) +- `Source Language` this should be applied wherever a specific source language is tested (valid Values: `C++`) +- `Feature` this should be applied wherever a specific feature is covered, ie `Structs`, `Fields`, `Namespaces`, etc. These at the same time are used as Feature Flags (toggled in Silk.NET.SilkTouch.TestFramework). Tests with features that are not yet implemeneted may be created and simply turned off via these feature flags. (valid Values: not tracked. check `tests/Silk.NET.SilkTouch.TestFramework/SilkTouchTestFramework.cs`) + +### Symbol Layer + +Unit Tests need to be written for all symbols AND the Symbol Visitor. They should cover that the symbol visitor visits these symbols and their children correctly and any functionality the symbols themselves might implement + +### Scraper + +Tests should be written covering XML -> Symbol conversion. No C(++) -> XML tests are needed as this is the job of clang (sharp). + +### Emitter + +Tests should be written covering Symbol -> C# conversion. + +### Integration + +Integration Tests should exist to cover most if not all areas of the generator. These are simply a sanity check & samples of what the generator can do. Unit Tests are still required.