Skip to content

Commit 8c3e971

Browse files
authored
Merge pull request #219 from Cysharp/tunit
use TUnit as Unit test framework
2 parents 5210041 + 61bd249 commit 8c3e971

26 files changed

+774
-771
lines changed

global.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"test": {
3+
"runner": "Microsoft.Testing.Platform"
4+
}
5+
}

sandbox/GeneratorSandbox/Program.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212

1313
app.Add("", ([FromServices] MyService service) => { service.Hello(); });
1414

15+
16+
// Environment
17+
1518
app.Run(args);
1619

1720
public class MyService
1821
{
19-
public void Hello() => Console.WriteLine("Hello from MyService");
22+
public void Hello() => throw new Exception();
2023
}
24+
25+

tests/ConsoleAppFramework.GeneratorTests/ArgumentParserTest.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
using System.Diagnostics.CodeAnalysis;
22

3+
34
namespace ConsoleAppFramework.GeneratorTests;
45

5-
public class ArgumentParserTest(ITestOutputHelper output)
6+
public class ArgumentParserTest
67
{
7-
readonly VerifyHelper verifier = new(output, "CAF");
8+
readonly VerifyHelper verifier = new("CAF");
89

9-
[Fact]
10-
public void Lamda()
10+
[Test]
11+
public async Task Lamda()
1112
{
12-
verifier.Execute(HEAD + Body("""
13+
await verifier.Execute(HEAD + Body("""
1314
ConsoleApp.Run(args, ([Vector3Parser] Vector3 v) => Console.Write(v));
1415
""") + TAIL, args: "--v 1,2,3", expected: "<1, 2, 3>");
15-
verifier.Execute(HEAD + Body("""
16+
await verifier.Execute(HEAD + Body("""
1617
var app = ConsoleApp.Create();
1718
app.Add("", ([Vector3Parser] Vector3 v) => Console.Write(v));
1819
app.Run(args);
1920
""") + TAIL, args: "--v 1,2,3", expected: "<1, 2, 3>");
2021
}
2122

22-
[Fact]
23-
public void Method()
23+
[Test]
24+
public async Task Method()
2425
{
25-
verifier.Execute(HEAD + Body("""
26+
await verifier.Execute(HEAD + Body("""
2627
ConsoleApp.Run(args, MyCommands.Static);
2728
""") + TAIL, args: "--v 1,2,3", expected: "<1, 2, 3>");
28-
verifier.Execute(HEAD + Body("""
29+
await verifier.Execute(HEAD + Body("""
2930
var app = ConsoleApp.Create();
3031
app.Add("", MyCommands.Static);
3132
app.Run(args);
3233
""") + TAIL, args: "--v 1,2,3", expected: "<1, 2, 3>");
3334
}
3435

35-
[Fact]
36-
public void Class()
36+
[Test]
37+
public async Task Class()
3738
{
38-
verifier.Execute(HEAD + Body("""
39+
await verifier.Execute(HEAD + Body("""
3940
var app = ConsoleApp.Create();
4041
app.Add<MyCommands>();
4142
app.Run(args);
Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,65 @@
1-
namespace ConsoleAppFramework.GeneratorTests
1+
namespace ConsoleAppFramework.GeneratorTests;
2+
3+
public class ArrayParseTest
24
{
3-
public class ArrayParseTest(ITestOutputHelper output)
4-
{
5-
VerifyHelper verifier = new VerifyHelper(output, "CAF");
5+
VerifyHelper verifier = new VerifyHelper("CAF");
66

7-
[Fact]
8-
public void Params()
9-
{
10-
var code = """
7+
[Test]
8+
public async Task Params()
9+
{
10+
var code = """
1111
ConsoleApp.Run(args, (params int[] foo) =>
1212
{
1313
Console.Write("[" + string.Join(", ", foo) + "]");
1414
});
1515
""";
16-
verifier.Execute(code, args: "--foo", expected: "[]");
17-
verifier.Execute(code, args: "--foo 10", expected: "[10]");
18-
verifier.Execute(code, args: "--foo 10 20 30", expected: "[10, 20, 30]");
19-
}
16+
await verifier.Execute(code, args: "--foo", expected: "[]");
17+
await verifier.Execute(code, args: "--foo 10", expected: "[10]");
18+
await verifier.Execute(code, args: "--foo 10 20 30", expected: "[10, 20, 30]");
19+
}
2020

21-
[Fact]
22-
public void ArgumentParams()
23-
{
24-
var code = """
21+
[Test]
22+
public async Task ArgumentParams()
23+
{
24+
var code = """
2525
ConsoleApp.Run(args, ([Argument]string title, [Argument]params int[] foo) =>
2626
{
2727
Console.Write(title + "[" + string.Join(", ", foo) + "]");
2828
});
2929
""";
30-
verifier.Execute(code, args: "aiueo", expected: "aiueo[]");
31-
verifier.Execute(code, args: "aiueo 10", expected: "aiueo[10]");
32-
verifier.Execute(code, args: "aiueo 10 20 30", expected: "aiueo[10, 20, 30]");
33-
}
30+
await verifier.Execute(code, args: "aiueo", expected: "aiueo[]");
31+
await verifier.Execute(code, args: "aiueo 10", expected: "aiueo[10]");
32+
await verifier.Execute(code, args: "aiueo 10 20 30", expected: "aiueo[10, 20, 30]");
33+
}
3434

35-
[Fact]
36-
public void ParseArray()
37-
{
38-
var code = """
35+
[Test]
36+
public async Task ParseArray()
37+
{
38+
var code = """
3939
ConsoleApp.Run(args, (int[] ix, string[] sx) =>
4040
{
4141
Console.Write("[" + string.Join(", ", ix) + "]");
4242
Console.Write("[" + string.Join(", ", sx) + "]");
4343
});
4444
""";
45-
verifier.Execute(code, args: "--ix 1,2,3,4,5 --sx a,b,c,d,e", expected: "[1, 2, 3, 4, 5][a, b, c, d, e]");
45+
await verifier.Execute(code, args: "--ix 1,2,3,4,5 --sx a,b,c,d,e", expected: "[1, 2, 3, 4, 5][a, b, c, d, e]");
4646

47-
var largeIntArray = string.Join(",", Enumerable.Range(0, 1000));
48-
var expectedIntArray = string.Join(", ", Enumerable.Range(0, 1000));
49-
verifier.Execute(code, args: $"--ix {largeIntArray} --sx a,b,c,d,e", expected: $"[{expectedIntArray}][a, b, c, d, e]");
50-
}
47+
var largeIntArray = string.Join(",", Enumerable.Range(0, 1000));
48+
var expectedIntArray = string.Join(", ", Enumerable.Range(0, 1000));
49+
await verifier.Execute(code, args: $"--ix {largeIntArray} --sx a,b,c,d,e", expected: $"[{expectedIntArray}][a, b, c, d, e]");
50+
}
5151

52-
[Fact]
53-
public void JsonArray()
54-
{
55-
var code = """
52+
[Test]
53+
public async Task JsonArray()
54+
{
55+
var code = """
5656
ConsoleApp.Run(args, (int[] ix, string[] sx) =>
5757
{
5858
Console.Write("[" + string.Join(", ", ix) + "]");
5959
Console.Write("[" + string.Join(", ", sx) + "]");
6060
});
6161
""";
62-
verifier.Execute(code, args: "--ix [] --sx []", expected: "[][]");
63-
verifier.Execute(code, args: "--ix [1,2,3,4,5] --sx [\"a\",\"b\",\"c\",\"d\",\"e\"]", expected: "[1, 2, 3, 4, 5][a, b, c, d, e]");
64-
}
62+
await verifier.Execute(code, args: "--ix [] --sx []", expected: "[][]");
63+
await verifier.Execute(code, args: "--ix [1,2,3,4,5] --sx [\"a\",\"b\",\"c\",\"d\",\"e\"]", expected: "[1, 2, 3, 4, 5][a, b, c, d, e]");
6564
}
6665
}

tests/ConsoleAppFramework.GeneratorTests/BuildCustomDelegateTest.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66

77
namespace ConsoleAppFramework.GeneratorTests;
88

9-
public class BuildCustomDelegateTest(ITestOutputHelper output)
9+
public class BuildCustomDelegateTest
1010
{
11-
VerifyHelper verifier = new VerifyHelper(output, "CAF");
11+
VerifyHelper verifier = new VerifyHelper("CAF");
1212

13-
[Fact]
14-
public void Run()
13+
[Test]
14+
public async Task Run()
1515
{
1616
var code = """
1717
ConsoleApp.Run(args, (
@@ -34,7 +34,7 @@ bool a16 // ok it is Action
3434
) => { Console.Write("ok"); });
3535
""";
3636

37-
verifier.Execute(code, "", "ok");
37+
await verifier.Execute(code, "", "ok");
3838

3939
var code2 = """
4040
ConsoleApp.Run(args, (
@@ -58,10 +58,10 @@ bool a17 // custom delegate
5858
) => { Console.Write("ok"); });
5959
""";
6060

61-
verifier.Execute(code2, "", "ok");
61+
await verifier.Execute(code2, "", "ok");
6262

6363

64-
verifier.Execute("""
64+
await verifier.Execute("""
6565
var t = new Test();
6666
ConsoleApp.Run(args, t.Handle);
6767
@@ -96,7 +96,7 @@ bool a19
9696

9797

9898

99-
verifier.Execute("""
99+
await verifier.Execute("""
100100
unsafe
101101
{
102102
ConsoleApp.Run(args, &Test.Handle);
@@ -132,10 +132,10 @@ bool a19
132132
""", "", "ok");
133133
}
134134

135-
[Fact]
136-
public void Builder()
135+
[Test]
136+
public async Task Builder()
137137
{
138-
verifier.Execute("""
138+
await verifier.Execute("""
139139
var t = new Test();
140140
141141
var app = ConsoleApp.Create();

0 commit comments

Comments
 (0)