Skip to content

Commit a27ee8a

Browse files
authored
Introduce Test System based on Traits (#944)
1 parent b51d721 commit a27ee8a

29 files changed

+483
-50
lines changed

Silk.NET.sln

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Silk.NET.SilkTouch.Scraper.
8080
EndProject
8181
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}"
8282
EndProject
83+
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}"
84+
EndProject
8385
Global
8486
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8587
Debug|Any CPU = Debug|Any CPU
@@ -330,6 +332,18 @@ Global
330332
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x64.Build.0 = Release|Any CPU
331333
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x86.ActiveCfg = Release|Any CPU
332334
{66FE736C-C407-44C3-A94E-4345E22AA95E}.Release|x86.Build.0 = Release|Any CPU
335+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
336+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|Any CPU.Build.0 = Debug|Any CPU
337+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|x64.ActiveCfg = Debug|Any CPU
338+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|x64.Build.0 = Debug|Any CPU
339+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|x86.ActiveCfg = Debug|Any CPU
340+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Debug|x86.Build.0 = Debug|Any CPU
341+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Release|Any CPU.ActiveCfg = Release|Any CPU
342+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Release|Any CPU.Build.0 = Release|Any CPU
343+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Release|x64.ActiveCfg = Release|Any CPU
344+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Release|x64.Build.0 = Release|Any CPU
345+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Release|x86.ActiveCfg = Release|Any CPU
346+
{381D1039-3259-488F-BB25-D90EE63A3E82}.Release|x86.Build.0 = Release|Any CPU
333347
EndGlobalSection
334348
GlobalSection(SolutionProperties) = preSolution
335349
HideSolutionNode = FALSE
@@ -361,6 +375,7 @@ Global
361375
{795A93A6-9578-439F-BB08-07B148B1D4CE} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
362376
{5329AC43-7177-4953-AFAB-A9FA7B9A4C7C} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
363377
{66FE736C-C407-44C3-A94E-4345E22AA95E} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
378+
{381D1039-3259-488F-BB25-D90EE63A3E82} = {94D5D1E1-B998-4CB1-9D04-DA138A2B0F3C}
364379
EndGlobalSection
365380
GlobalSection(ExtensibilityGlobals) = postSolution
366381
SolutionGuid = {F5273D7F-3334-48DF-94E3-41AE6816CD4D}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Testing
2+
3+
SilkTouch Generators should be extensively Tested.
4+
5+
## Unit Tests
6+
7+
### Traits
8+
9+
All Unit & Integration tests should be flagged with the appropriate Category (Emitter, Scraper, Symbols, Integration) using `Trait("Category", "MyCategory")`.
10+
Additionally the following Traits should be applied where appropriate:
11+
12+
- `Target Language` this should be applied wherever a specific target language is tested (valid Values: `C#`)
13+
- `Source Language` this should be applied wherever a specific source language is tested (valid Values: `C++`)
14+
- `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`)
15+
16+
### Symbol Layer
17+
18+
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
19+
20+
### Scraper
21+
22+
Tests should be written covering XML -> Symbol conversion. No C(++) -> XML tests are needed as this is the job of clang (sharp).
23+
24+
### Emitter
25+
26+
Tests should be written covering Symbol -> C# conversion.
27+
28+
### Integration
29+
30+
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.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Xunit;
5+
6+
[assembly: TestFramework("Silk.NET.SilkTouch.TestFramework.SilkTouchTestFramework", "Silk.NET.SilkTouch.TestFramework")]

tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterFieldTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ namespace Silk.NET.SilkTouch.Emitter.Tests;
1313

1414
public sealed class EmitterFieldIntegrationTests : EmitterTest
1515
{
16-
[Fact]
16+
[Fact,
17+
Trait("Category", "Emitter"),
18+
Trait("Feature", "Fields"),
19+
Trait("Target Language", "C#")]
1720
public void FieldIntegration()
1821
{
1922
var syntax = Transform(new FieldSymbol(new StructSymbol(new IdentifierSymbol("int"),ImmutableArray<FieldSymbol>.Empty), new IdentifierSymbol("Test")));
@@ -22,7 +25,10 @@ public void FieldIntegration()
2225
Assert.Equal("public int Test;", result);
2326
}
2427

25-
[Fact]
28+
[Fact,
29+
Trait("Category", "Emitter"),
30+
Trait("Feature", "Fields"),
31+
Trait("Target Language", "C#")]
2632
public void FieldIsPublic()
2733
{
2834
var syntax = Transform
@@ -38,7 +44,10 @@ public void FieldIsPublic()
3844
Assert.Single(syntax!.Modifiers, x => x.IsKind(SyntaxKind.PublicKeyword));
3945
}
4046

41-
[Fact]
47+
[Fact,
48+
Trait("Category", "Emitter"),
49+
Trait("Feature", "Fields"),
50+
Trait("Target Language", "C#")]
4251
public void CorrectTypeIdentifier()
4352
{
4453
var syntax = Transform
@@ -56,7 +65,10 @@ public void CorrectTypeIdentifier()
5665
Assert.Equal("int", type!.Identifier.Text);
5766
}
5867

59-
[Fact]
68+
[Fact,
69+
Trait("Category", "Emitter"),
70+
Trait("Feature", "Fields"),
71+
Trait("Target Language", "C#")]
6072
public void CorrectIdentifier()
6173
{
6274
var syntax = Transform

tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceMemberTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ namespace Silk.NET.SilkTouch.Emitter.Tests;
1010

1111
public class EmitterNamespaceMemberTests : EmitterTest
1212
{
13-
[Fact]
13+
[Fact,
14+
Trait("Category", "Emitter"),
15+
Trait("Feature", "Namespaces"),
16+
Trait("Target Language", "C#")]
1417
public void SingleMemberIntegration()
1518
{
1619
var syntax = Transform(new NamespaceSymbol(new IdentifierSymbol("Test"), new []
@@ -22,7 +25,10 @@ public void SingleMemberIntegration()
2225
Assert.Equal("namespace Test\n{\npublic struct Test2\n{\n}\n}\n", result);
2326
}
2427

25-
[Fact]
28+
[Fact,
29+
Trait("Category", "Emitter"),
30+
Trait("Feature", "Namespaces"),
31+
Trait("Target Language", "C#")]
2632
public void MultipleMembersIntegration()
2733
{
2834
var syntax = Transform(new NamespaceSymbol(new IdentifierSymbol("Test"), new []

tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterNamespaceTests.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ namespace Silk.NET.SilkTouch.Emitter.Tests;
1212

1313
public class EmitterNamespaceTests : EmitterTest
1414
{
15-
[Fact]
15+
[Fact,
16+
Trait("Category", "Emitter"),
17+
Trait("Feature", "Namespaces"),
18+
Trait("Target Language", "C#")]
1619
public void NamespaceIntegration()
1720
{
1821
var syntax = Transform(new NamespaceSymbol(new IdentifierSymbol("Test"), ImmutableArray<TypeSymbol>.Empty));
@@ -21,7 +24,10 @@ public void NamespaceIntegration()
2124
Assert.Equal("namespace Test\n{\n}\n", result);
2225
}
2326

24-
[Fact]
27+
[Fact,
28+
Trait("Category", "Emitter"),
29+
Trait("Feature", "Namespaces"),
30+
Trait("Target Language", "C#")]
2531
public void CorrectIdentifier()
2632
{
2733
var syntax = Transform

tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructMemberFieldsTests.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ namespace Silk.NET.SilkTouch.Emitter.Tests;
99

1010
public class EmitterStructMemberFieldsTests : EmitterTest
1111
{
12-
[Fact]
12+
13+
[Fact,
14+
Trait("Category", "Emitter"),
15+
Trait("Feature", "Structs"),
16+
Trait("Feature", "Fields"),
17+
Trait("Target Language", "C#")]
1318
public void SingleFieldIntegration()
1419
{
1520
var node = Transform
@@ -37,7 +42,11 @@ public void SingleFieldIntegration()
3742
);
3843
}
3944

40-
[Fact]
45+
[Fact,
46+
Trait("Category", "Emitter"),
47+
Trait("Feature", "Structs"),
48+
Trait("Feature", "Fields"),
49+
Trait("Target Language", "C#")]
4150
public void MultipleFieldsIntegration()
4251
{
4352
var node = Transform

tests/Silk.NET.SilkTouch.Emitter.Tests/EmitterStructTests.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,52 @@ namespace Silk.NET.SilkTouch.Emitter.Tests;
1010

1111
public sealed class EmitterStructTests : EmitterTest
1212
{
13-
[Fact]
13+
14+
[Fact,
15+
Trait("Category", "Emitter"),
16+
Trait("Feature", "Structs"),
17+
Trait("Target Language", "C#")]
1418
public void StructSyntax()
1519
{
1620
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"), ImmutableArray<FieldSymbol>.Empty));
1721
Assert.IsType<StructDeclarationSyntax>(syntax);
1822
}
1923

20-
[Fact]
24+
[Fact,
25+
Trait("Category", "Emitter"),
26+
Trait("Feature", "Structs"),
27+
Trait("Target Language", "C#")]
2128
public void StructKeyword()
2229
{
2330
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"), ImmutableArray<FieldSymbol>.Empty)) as StructDeclarationSyntax;
2431
Assert.Equal("struct", syntax!.Keyword.Text);
2532
}
2633

27-
[Fact]
34+
[Fact,
35+
Trait("Category", "Emitter"),
36+
Trait("Feature", "Structs"),
37+
Trait("Target Language", "C#")]
2838
public void CorrectIdentifier()
2939
{
3040
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"), ImmutableArray<FieldSymbol>.Empty)) as StructDeclarationSyntax;
3141
Assert.Equal("Test", syntax!.Identifier.Text);
3242
}
3343

34-
[Fact]
44+
[Fact,
45+
Trait("Category", "Emitter"),
46+
Trait("Feature", "Structs"),
47+
Trait("Target Language", "C#")]
3548
public void IsOnlyPublic()
3649
{
3750
var syntax = Transform(new StructSymbol(new IdentifierSymbol("Test"), ImmutableArray<FieldSymbol>.Empty)) as StructDeclarationSyntax;
3851
var @public = Assert.Single(syntax!.Modifiers);
3952
Assert.Equal("public", @public.Text);
4053
}
4154

42-
[Fact]
55+
[Fact,
56+
Trait("Category", "Emitter"),
57+
Trait("Feature", "Structs"),
58+
Trait("Target Language", "C#")]
4359
public void IntegrationEmptyStruct()
4460
{
4561
// Note that this test also covers trivia, which is not checked otherwise.

tests/Silk.NET.SilkTouch.Emitter.Tests/IdentifierTests.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ namespace Silk.NET.SilkTouch.Emitter.Tests;
88

99
public sealed class IdentifierTests : EmitterTest
1010
{
11-
[Fact]
11+
[Fact,
12+
Trait("Category", "Emitter"),
13+
Trait("Target Language", "C#")]
1214
public void IdentifierHasNoLeadingTrivia()
1315
{
1416
var node = Transform(new IdentifierSymbol("Test"));
@@ -17,7 +19,9 @@ public void IdentifierHasNoLeadingTrivia()
1719
Assert.False(node.HasLeadingTrivia);
1820
}
1921

20-
[Fact]
22+
[Fact,
23+
Trait("Category", "Emitter"),
24+
Trait("Target Language", "C#")]
2125
public void IdentifierHasNoTrailingTrivia()
2226
{
2327
var node = Transform(new IdentifierSymbol("Test"));
@@ -26,7 +30,9 @@ public void IdentifierHasNoTrailingTrivia()
2630
Assert.False(node.HasTrailingTrivia);
2731
}
2832

29-
[Fact]
33+
[Fact,
34+
Trait("Category", "Emitter"),
35+
Trait("Target Language", "C#")]
3036
public void IdentifierIntegration()
3137
{
3238
var node = Transform(new IdentifierSymbol("Test"));

tests/Silk.NET.SilkTouch.Emitter.Tests/Silk.NET.SilkTouch.Emitter.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
<ItemGroup>
2020
<ProjectReference Include="..\..\src\generators\Silk.NET.SilkTouch.Emitter\Silk.NET.SilkTouch.Emitter.csproj" />
21+
<ProjectReference Include="..\Silk.NET.SilkTouch.TestFramework\Silk.NET.SilkTouch.TestFramework.csproj" />
2122
</ItemGroup>
2223

2324
</Project>

0 commit comments

Comments
 (0)