Skip to content

Commit 9407f14

Browse files
authored
Merge pull request #158 from Cysharp/remove-fluentassertions
Remove FluentAssertions, Use Shouldly
2 parents b8e83a0 + 1dcdfd0 commit 9407f14

7 files changed

+45
-47
lines changed

tests/ConsoleAppFramework.GeneratorTests/CSharpGeneratorRunner.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void Ok([StringSyntax("C#-test")] string code, [CallerArgumentExpression(
153153
}
154154
OutputGeneratedCode(compilation);
155155

156-
diagnostics.Length.Should().Be(0);
156+
diagnostics.Length.ShouldBe(0);
157157
}
158158

159159
public void Verify(int id, [StringSyntax("C#-test")] string code, string diagnosticsCodeSpan, [CallerArgumentExpression("code")] string? codeExpr = null)
@@ -167,11 +167,11 @@ public void Verify(int id, [StringSyntax("C#-test")] string code, string diagnos
167167
}
168168
OutputGeneratedCode(compilation);
169169

170-
diagnostics.Length.Should().Be(1);
171-
diagnostics[0].Id.Should().Be(idPrefix + id.ToString("000"));
170+
diagnostics.Length.ShouldBe(1);
171+
diagnostics[0].Id.ShouldBe(idPrefix + id.ToString("000"));
172172

173173
var text = GetLocationText(diagnostics[0], compilation.SyntaxTrees);
174-
text.Should().Be(diagnosticsCodeSpan);
174+
text.ShouldBe(diagnosticsCodeSpan);
175175
}
176176

177177
public (string, string)[] Verify([StringSyntax("C#-test")] string code, [CallerArgumentExpression("code")] string? codeExpr = null)
@@ -196,7 +196,7 @@ public void Execute([StringSyntax("C#-test")]string code, string args, string ex
196196
}
197197
OutputGeneratedCode(compilation);
198198

199-
stdout.Should().Be(expected);
199+
stdout.ShouldBe(expected);
200200
}
201201

202202
public string Error([StringSyntax("C#-test")] string code, string args, [CallerArgumentExpression("code")] string? codeExpr = null)

tests/ConsoleAppFramework.GeneratorTests/ConsoleAppBuilderTest.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ public void BuilderRun()
2727
verifier.Execute(code, "foo --x 10 --y 20", "30");
2828
verifier.Execute(code, "bar --x 20 --y 30", "50");
2929
verifier.Execute(code, "bar --x 20", "30");
30-
Environment.ExitCode.Should().Be(0);
30+
Environment.ExitCode.ShouldBe(0);
3131
verifier.Execute(code, "baz --x 40 --y takoyaki", "40takoyaki");
32-
Environment.ExitCode.Should().Be(10);
32+
Environment.ExitCode.ShouldBe(10);
3333
Environment.ExitCode = 0;
3434

3535
verifier.Execute(code, "boz --x 40", "80");
@@ -50,9 +50,9 @@ public void BuilderRunAsync()
5050
verifier.Execute(code, "foo --x 10 --y 20", "30");
5151
verifier.Execute(code, "bar --x 20 --y 30", "50");
5252
verifier.Execute(code, "bar --x 20", "30");
53-
Environment.ExitCode.Should().Be(0);
53+
Environment.ExitCode.ShouldBe(0);
5454
verifier.Execute(code, "baz --x 40 --y takoyaki", "40takoyaki");
55-
Environment.ExitCode.Should().Be(10);
55+
Environment.ExitCode.ShouldBe(10);
5656
Environment.ExitCode = 0;
5757

5858
verifier.Execute(code, "boz --x 40", "80");

tests/ConsoleAppFramework.GeneratorTests/ConsoleAppFramework.GeneratorTests.csproj

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
87
<IsPackable>false</IsPackable>
98
<IsTestProject>true</IsTestProject>
109
<Configurations>Debug;Release</Configurations>
1110
</PropertyGroup>
1211

13-
1412
<ItemGroup>
15-
<PackageReference Include="FluentAssertions" Version="6.12.0" />
13+
<PackageReference Include="Shouldly" Version="4.2.1" />
1614
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.9.2" />
1715
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
1816
<PackageReference Include="xunit" Version="2.4.2" />
@@ -26,4 +24,9 @@
2624
<ProjectReference Include="..\..\src\ConsoleAppFramework\ConsoleAppFramework.csproj" />
2725
</ItemGroup>
2826

27+
<ItemGroup>
28+
<Using Include="Xunit" />
29+
<Using Include="Xunit.Abstractions" />
30+
<Using Include="Shouldly" />
31+
</ItemGroup>
2932
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
global using Xunit;
2-
global using Xunit.Abstractions;
3-
global using FluentAssertions;
4-
51
// CSharpGeneratorRunner.CompileAndExecute uses stdout hook(replace Console.Out)
62
// so can not work in parallel test
73
[assembly: CollectionBehavior(DisableTestParallelization = true)]

tests/ConsoleAppFramework.GeneratorTests/IncrementalGeneratorTest.cs

+11-11
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public class IncrementalGeneratorTest
1313
void VerifySourceOutputReasonIsCached((string Key, string Reasons)[] reasons)
1414
{
1515
var reason = reasons.FirstOrDefault(x => x.Key == "SourceOutput").Reasons;
16-
reason.Should().Be("Cached");
16+
reason.ShouldBe("Cached");
1717
}
1818

1919
void VerifySourceOutputReasonIsNotCached((string Key, string Reasons)[] reasons)
2020
{
2121
var reason = reasons.FirstOrDefault(x => x.Key == "SourceOutput").Reasons;
22-
reason.Should().NotBe("Cached");
22+
reason.ShouldNotBe("Cached");
2323
}
2424

2525
[Fact]
@@ -49,9 +49,9 @@ public void RunLambda()
4949

5050
var reasons = CSharpGeneratorRunner.GetIncrementalGeneratorTrackedStepsReasons("ConsoleApp.Run.", step1, step2, step3);
5151

52-
reasons[0][0].Reasons.Should().Be("New");
53-
reasons[1][0].Reasons.Should().Be("Unchanged");
54-
reasons[2][0].Reasons.Should().Be("Modified");
52+
reasons[0][0].Reasons.ShouldBe("New");
53+
reasons[1][0].Reasons.ShouldBe("Unchanged");
54+
reasons[2][0].Reasons.ShouldBe("Modified");
5555

5656
VerifySourceOutputReasonIsCached(reasons[1]);
5757
VerifySourceOutputReasonIsNotCached(reasons[2]);
@@ -116,9 +116,9 @@ public void DoHello(int x, int y) // signature change
116116

117117
var reasons = CSharpGeneratorRunner.GetIncrementalGeneratorTrackedStepsReasons("ConsoleApp.Run.", step1, step2, step3);
118118

119-
reasons[0][0].Reasons.Should().Be("New");
120-
reasons[1][0].Reasons.Should().Be("Unchanged");
121-
reasons[2][0].Reasons.Should().Be("Modified");
119+
reasons[0][0].Reasons.ShouldBe("New");
120+
reasons[1][0].Reasons.ShouldBe("Unchanged");
121+
reasons[2][0].Reasons.ShouldBe("Modified");
122122

123123
VerifySourceOutputReasonIsCached(reasons[1]);
124124
}
@@ -171,9 +171,9 @@ static void DoHello(int x, int y) // change signature
171171

172172
var reasons = CSharpGeneratorRunner.GetIncrementalGeneratorTrackedStepsReasons("ConsoleApp.Run.", step1, step2, step3);
173173

174-
reasons[0][0].Reasons.Should().Be("New");
175-
reasons[1][0].Reasons.Should().Be("Unchanged");
176-
reasons[2][0].Reasons.Should().Be("Modified");
174+
reasons[0][0].Reasons.ShouldBe("New");
175+
reasons[1][0].Reasons.ShouldBe("Unchanged");
176+
reasons[2][0].Reasons.ShouldBe("Modified");
177177

178178
VerifySourceOutputReasonIsCached(reasons[1]);
179179
}

tests/ConsoleAppFramework.GeneratorTests/NameConverterTest.cs

+13-13
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ public class NameConverterTest(ITestOutputHelper output)
1414
[Fact]
1515
public void KebabCase()
1616
{
17-
NameConverter.ToKebabCase("").Should().Be("");
18-
NameConverter.ToKebabCase("HelloWorld").Should().Be("hello-world");
19-
NameConverter.ToKebabCase("HelloWorldMyHome").Should().Be("hello-world-my-home");
20-
NameConverter.ToKebabCase("helloWorld").Should().Be("hello-world");
21-
NameConverter.ToKebabCase("hello-world").Should().Be("hello-world");
22-
NameConverter.ToKebabCase("A").Should().Be("a");
23-
NameConverter.ToKebabCase("AB").Should().Be("ab");
24-
NameConverter.ToKebabCase("ABC").Should().Be("abc");
25-
NameConverter.ToKebabCase("ABCD").Should().Be("abcd");
26-
NameConverter.ToKebabCase("ABCDeF").Should().Be("abc-def");
27-
NameConverter.ToKebabCase("XmlReader").Should().Be("xml-reader");
28-
NameConverter.ToKebabCase("XMLReader").Should().Be("xml-reader");
29-
NameConverter.ToKebabCase("MLLibrary").Should().Be("ml-library");
17+
NameConverter.ToKebabCase("").ShouldBe("");
18+
NameConverter.ToKebabCase("HelloWorld").ShouldBe("hello-world");
19+
NameConverter.ToKebabCase("HelloWorldMyHome").ShouldBe("hello-world-my-home");
20+
NameConverter.ToKebabCase("helloWorld").ShouldBe("hello-world");
21+
NameConverter.ToKebabCase("hello-world").ShouldBe("hello-world");
22+
NameConverter.ToKebabCase("A").ShouldBe("a");
23+
NameConverter.ToKebabCase("AB").ShouldBe("ab");
24+
NameConverter.ToKebabCase("ABC").ShouldBe("abc");
25+
NameConverter.ToKebabCase("ABCD").ShouldBe("abcd");
26+
NameConverter.ToKebabCase("ABCDeF").ShouldBe("abc-def");
27+
NameConverter.ToKebabCase("XmlReader").ShouldBe("xml-reader");
28+
NameConverter.ToKebabCase("XMLReader").ShouldBe("xml-reader");
29+
NameConverter.ToKebabCase("MLLibrary").ShouldBe("ml-library");
3030
}
3131

3232
[Fact]

tests/ConsoleAppFramework.GeneratorTests/RunTest.cs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using FluentAssertions;
2-
using Microsoft.CodeAnalysis;
1+
using Microsoft.CodeAnalysis;
32
using System;
43
using System.Collections.Generic;
54
using System.ComponentModel.DataAnnotations;
@@ -23,15 +22,15 @@ public void SyncRun()
2322
[Fact]
2423
public void SyncRunShouldFailed()
2524
{
26-
verifier.Error("ConsoleApp.Run(args, (int x) => { Console.Write((x)); });", "--x").Should().Contain("Argument 'x' failed to parse");
25+
verifier.Error("ConsoleApp.Run(args, (int x) => { Console.Write((x)); });", "--x").ShouldContain("Argument 'x' failed to parse");
2726
}
2827

2928
[Fact]
3029
public void MissingArgument()
3130
{
32-
verifier.Error("ConsoleApp.Run(args, (int x, int y) => { Console.Write((x + y)); });", "--x 10 y 20").Should().Contain("Argument 'y' is not recognized.");
31+
verifier.Error("ConsoleApp.Run(args, (int x, int y) => { Console.Write((x + y)); });", "--x 10 y 20").ShouldContain("Argument 'y' is not recognized.");
3332

34-
Environment.ExitCode.Should().Be(1);
33+
Environment.ExitCode.ShouldBe(1);
3534
Environment.ExitCode = 0;
3635
}
3736

@@ -48,7 +47,7 @@ The field x must be between 1 and 10.
4847
ConsoleApp.Run(args, ([Range(1, 10)]int x, [Range(100, 200)]int y) => { Console.Write((x + y)); });
4948
""", "--x 100 --y 140", expected);
5049

51-
Environment.ExitCode.Should().Be(1);
50+
Environment.ExitCode.ShouldBe(1);
5251
Environment.ExitCode = 0;
5352
}
5453

@@ -66,7 +65,7 @@ The field y must be between 100 and 200.
6665
ConsoleApp.Run(args, ([Range(1, 10)]int x, [Range(100, 200)]int y) => { Console.Write((x + y)); });
6766
""", "--x 100 --y 240", expected);
6867

69-
Environment.ExitCode.Should().Be(1);
68+
Environment.ExitCode.ShouldBe(1);
7069
Environment.ExitCode = 0;
7170
}
7271
[Fact]

0 commit comments

Comments
 (0)