Skip to content

Commit 8edf871

Browse files
committed
Switched to snapshot testing for generated code.
1 parent b2658b8 commit 8edf871

File tree

279 files changed

+27862
-24021
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+27862
-24021
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Verify settings
2+
[*.{received,verified}.{json,txt,xml,cs}]
3+
charset = utf-8
4+
end_of_line = lf
5+
indent_size = unset
6+
indent_style = unset
7+
insert_final_newline = false
8+
tab_width = unset
9+
trim_trailing_whitespace = false

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.verified.txt text eol=lf working-tree-encoding=UTF-8
2+
*.verified.xml text eol=lf working-tree-encoding=UTF-8
3+
*.verified.json text eol=lf working-tree-encoding=UTF-8
4+
*.verified.cs text eol=lf working-tree-encoding=UTF-8

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@
77

88
*\.sln\.DotSettings\.user
99
*\.csproj\.user
10+
11+
# Verify
12+
test/**/*.received.*
13+
test/**/*.received/

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17" />
2323
<PackageVersion Include="Serilog.Extensions.Logging" Version="8.0.0" />
2424
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
25+
<PackageVersion Include="Verify.Xunit" Version="28.3.2" />
2526
<PackageVersion Include="xunit" Version="2.9.2" />
2627
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
2728
</ItemGroup>

Thinktecture.Runtime.Extensions.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{21EB22
2222
.github\workflows\codeql-analysis.yml = .github\workflows\codeql-analysis.yml
2323
global.json = global.json
2424
Directory.Packages.props = Directory.Packages.props
25+
.gitattributes = .gitattributes
26+
.editorconfig = .editorconfig
2527
EndProjectSection
2628
EndProject
2729
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{E6F200ED-86D2-4D5C-9D5F-34592908B107}"

test/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<NoWarn>$(NoWarn);CS1591;CA1707;NU1903;NETSDK1206;NU1904</NoWarn>
1414
<RootNamespace>Thinktecture.Runtime.Tests</RootNamespace>
1515
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
16+
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
1617
<TargetFramework></TargetFramework>
1718
<TargetFrameworks>net7.0;net8.0;net9.0</TargetFrameworks>
1819
</PropertyGroup>
@@ -22,6 +23,7 @@
2223
<PackageReference Include="FluentAssertions"/>
2324
<PackageReference Include="NSubstitute"/>
2425
<PackageReference Include="NSubstitute.Analyzers.CSharp"/>
26+
<PackageReference Include="Verify.Xunit" />
2527
<PackageReference Include="xunit"/>
2628
<PackageReference Include="xunit.runner.visualstudio" PrivateAssets="all"/>
2729
</ItemGroup>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Runtime.CompilerServices;
2+
using DiffEngine;
3+
4+
namespace Thinktecture.Runtime.Tests;
5+
6+
internal class TestModuleInit
7+
{
8+
[ModuleInitializer]
9+
internal static void ModuleInit()
10+
{
11+
DiffRunner.Disabled = true;
12+
}
13+
}

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/AdHocUnionSourceGeneratorTests.cs

Lines changed: 35 additions & 5346 deletions
Large diffs are not rendered by default.

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/EnumSourceGeneratorTests.cs

Lines changed: 304 additions & 10413 deletions
Large diffs are not rendered by default.

test/Thinktecture.Runtime.Extensions.SourceGenerator.Tests/SourceGeneratorTests/JsonSmartEnumSourceGeneratorTests.cs

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Threading.Tasks;
12
using Thinktecture.CodeAnalysis.SmartEnums;
23
using Xunit.Abstractions;
34

@@ -11,7 +12,7 @@ public JsonSmartEnumSourceGeneratorTests(ITestOutputHelper output)
1112
}
1213

1314
[Fact]
14-
public void Should_generate_JsonConverter_and_Attribute_if_Attribute_is_missing()
15+
public async Task Should_generate_JsonConverter_and_Attribute_if_Attribute_is_missing()
1516
{
1617
var source = """
1718
@@ -32,22 +33,11 @@ public partial class TestEnum
3233
".Json",
3334
typeof(IEnum<>).Assembly, typeof(Thinktecture.Text.Json.Serialization.ValueObjectJsonConverter<,,>).Assembly, typeof(System.Text.Json.JsonDocument).Assembly);
3435

35-
AssertOutput(output, """
36-
// <auto-generated />
37-
#nullable enable
38-
39-
namespace Thinktecture.Tests;
40-
41-
[global::System.Text.Json.Serialization.JsonConverterAttribute(typeof(global::Thinktecture.Text.Json.Serialization.ValueObjectJsonConverterFactory<global::Thinktecture.Tests.TestEnum, global::Thinktecture.ValidationError>))]
42-
partial class TestEnum
43-
{
44-
}
45-
46-
""");
36+
await VerifyAsync(output);
4737
}
4838

4939
[Fact]
50-
public void Should_generate_JsonConverter_for_enum_without_namespace()
40+
public async Task Should_generate_JsonConverter_for_enum_without_namespace()
5141
{
5242
var source = """
5343
@@ -66,20 +56,11 @@ public partial class TestEnum
6656
".Json",
6757
typeof(IEnum<>).Assembly, typeof(Thinktecture.Text.Json.Serialization.ValueObjectJsonConverter<,,>).Assembly, typeof(System.Text.Json.JsonDocument).Assembly);
6858

69-
AssertOutput(output, """
70-
// <auto-generated />
71-
#nullable enable
72-
73-
[global::System.Text.Json.Serialization.JsonConverterAttribute(typeof(global::Thinktecture.Text.Json.Serialization.ValueObjectJsonConverterFactory<global::TestEnum, global::Thinktecture.ValidationError>))]
74-
partial class TestEnum
75-
{
76-
}
77-
78-
""");
59+
await VerifyAsync(output);
7960
}
8061

8162
[Fact]
82-
public void Should_generate_JsonConverter_and_Attribute_for_struct_if_Attribute_is_missing()
63+
public async Task Should_generate_JsonConverter_and_Attribute_for_struct_if_Attribute_is_missing()
8364
{
8465
var source = """
8566
@@ -100,18 +81,7 @@ public partial struct TestEnum
10081
".Json",
10182
typeof(IEnum<>).Assembly, typeof(Thinktecture.Text.Json.Serialization.ValueObjectJsonConverter<,,>).Assembly, typeof(System.Text.Json.JsonDocument).Assembly);
10283

103-
AssertOutput(output, """
104-
// <auto-generated />
105-
#nullable enable
106-
107-
namespace Thinktecture.Tests;
108-
109-
[global::System.Text.Json.Serialization.JsonConverterAttribute(typeof(global::Thinktecture.Text.Json.Serialization.ValueObjectJsonConverterFactory<global::Thinktecture.Tests.TestEnum, global::Thinktecture.ValidationError>))]
110-
partial struct TestEnum
111-
{
112-
}
113-
114-
""");
84+
await VerifyAsync(output);
11585
}
11686

11787
[Fact]

0 commit comments

Comments
 (0)