@@ -8,8 +8,8 @@ namespace AutoCtor.Tests;
88
99public class ExampleTests
1010{
11- [ Theory ]
12- [ MemberData ( nameof ( GetExamples ) ) ]
11+ [ Test ]
12+ [ MethodDataSource ( nameof ( GetExamples ) ) ]
1313 public async Task ExamplesGeneratedCode ( CodeFileTheoryData theoryData )
1414 {
1515 var builder = CreateCompilation ( theoryData ) ;
@@ -18,16 +18,16 @@ public async Task ExamplesGeneratedCode(CodeFileTheoryData theoryData)
1818 . AddGenerator ( new AutoConstructSourceGenerator ( ) )
1919 . WithAnalyzerOptions ( theoryData . Options )
2020 . Build ( builder . ParseOptions )
21- . RunGenerators ( compilation , TestContext . Current . CancellationToken ) ;
21+ . RunGenerators ( compilation , TestHelper . CancellationToken ) ;
2222
2323 await Verify ( driver )
2424 . UseDirectory ( theoryData . VerifiedDirectory )
2525 . UseTypeName ( theoryData . Name )
2626 . IgnoreParametersForVerified ( ) ;
2727 }
2828
29- [ Theory ]
30- [ MemberData ( nameof ( GetExamples ) ) ]
29+ [ Test ]
30+ [ MethodDataSource ( nameof ( GetExamples ) ) ]
3131 public async Task CodeCompilesProperly ( CodeFileTheoryData theoryData )
3232 {
3333 var builder = CreateCompilation ( theoryData ) ;
@@ -40,15 +40,16 @@ public async Task CodeCompilesProperly(CodeFileTheoryData theoryData)
4040 compilation ,
4141 out var outputCompilation ,
4242 out _ ,
43- TestContext . Current . CancellationToken ) ;
43+ TestHelper . CancellationToken ) ;
4444
45- Assert . Empty ( outputCompilation . GetDiagnostics ( TestContext . Current . CancellationToken )
46- . Where ( d => ! theoryData . IgnoredCompileDiagnostics . Contains ( d . Id ) ) ) ;
45+ await Assert . That ( outputCompilation . GetDiagnostics ( TestHelper . CancellationToken )
46+ . Where ( d => ! theoryData . IgnoredCompileDiagnostics . Contains ( d . Id ) ) )
47+ . IsEmpty ( ) ;
4748 }
4849
4950#if ROSLYN_4_4
50- [ Theory ]
51- [ MemberData ( nameof ( GetExamples ) ) ]
51+ [ Test ]
52+ [ MethodDataSource ( nameof ( GetExamples ) ) ]
5253 public async Task EnsureRunsAreCachedCorrectly ( CodeFileTheoryData theoryData )
5354 {
5455 var builder = CreateCompilation ( theoryData ) ;
@@ -59,20 +60,20 @@ public async Task EnsureRunsAreCachedCorrectly(CodeFileTheoryData theoryData)
5960 . WithAnalyzerOptions ( theoryData . Options )
6061 . Build ( builder . ParseOptions ) ;
6162
62- driver = driver . RunGenerators ( compilation , TestContext . Current . CancellationToken ) ;
63+ driver = driver . RunGenerators ( compilation , TestHelper . CancellationToken ) ;
6364 var firstResult = driver . GetRunResult ( ) ;
6465
6566 // Change the compilation
6667 compilation = compilation . AddSyntaxTrees ( CSharpSyntaxTree . ParseText ( "// dummy" ,
6768 CSharpParseOptions . Default . WithLanguageVersion ( theoryData . LangPreview
6869 ? LanguageVersion . Preview
6970 : LanguageVersion . Latest ) ,
70- cancellationToken : TestContext . Current . CancellationToken ) ) ;
71+ cancellationToken : TestHelper . CancellationToken ) ) ;
7172
72- driver = driver . RunGenerators ( compilation , TestContext . Current . CancellationToken ) ;
73+ driver = driver . RunGenerators ( compilation , TestHelper . CancellationToken ) ;
7374 var secondResult = driver . GetRunResult ( ) ;
7475
75- AssertRunsEqual ( firstResult , secondResult ,
76+ await AssertRunsEqual ( firstResult , secondResult ,
7677 AutoConstructSourceGenerator . TrackingNames . AllTrackers ) ;
7778 }
7879#endif
@@ -99,39 +100,35 @@ private static CompilationBuilder CreateCompilation(CodeFileTheoryData theoryDat
99100
100101 private static IEnumerable < string > GetExamplesFiles ( string path ) => Directory . GetFiles ( Path . Combine ( BaseDir ? . FullName ?? "" , path ) , "*.cs" ) . Where ( e => ! e . Contains ( ".g." ) ) ;
101102
102- public static TheoryData < CodeFileTheoryData > GetExamples ( )
103+ public static IEnumerable < CodeFileTheoryData > GetExamples ( )
103104 {
104105 if ( BaseDir == null )
105106 throw new Exception ( "BaseDir is null" ) ;
106107
107- var data = new TheoryData < CodeFileTheoryData > ( ) ;
108-
109108 foreach ( var example in GetExamplesFiles ( "Examples" ) )
110109 {
111- data . Add ( new CodeFileTheoryData ( example ) with
110+ yield return new CodeFileTheoryData ( example ) with
112111 {
113112 IgnoredCompileDiagnostics = [ "CS0414" , "CS0169" ] // Ignore unused fields
114- } ) ;
113+ } ;
115114 }
116115
117116 foreach ( var guardExample in GetExamplesFiles ( "GuardExamples" ) )
118117 {
119- data . Add ( new CodeFileTheoryData ( guardExample ) with
118+ yield return new CodeFileTheoryData ( guardExample ) with
120119 {
121120 Options = new ( ) { { "build_property.AutoCtorGuards" , "true" } }
122- } ) ;
121+ } ;
123122 }
124123
125124 foreach ( var langExample in GetExamplesFiles ( "LangExamples" ) )
126125 {
127126 var verifiedName = string . Concat ( "Verified_" , PreprocessorSymbols . Last ( ) . AsSpan ( 7 ) ) ;
128- data . Add ( new CodeFileTheoryData ( langExample ) with
127+ yield return new CodeFileTheoryData ( langExample ) with
129128 {
130129 VerifiedDirectory = Path . Combine ( Path . GetDirectoryName ( langExample ) ?? "" , verifiedName ) ,
131130 LangPreview = true ,
132- } ) ;
131+ } ;
133132 }
134-
135- return data ;
136133 }
137134}
0 commit comments