File tree Expand file tree Collapse file tree 5 files changed +46
-7
lines changed Expand file tree Collapse file tree 5 files changed +46
-7
lines changed Original file line number Diff line number Diff line change @@ -84,4 +84,6 @@ public class ExampleMetadata
84
84
85
85
[ JsonIgnore ]
86
86
public string Source => $ "{ MarkdownFile } :{ StartLine } -{ EndLine } ";
87
+
88
+ public override string ToString ( ) => Name ;
87
89
}
Original file line number Diff line number Diff line change 1
- <Project Sdk =" Microsoft.NET.Sdk" >
1
+ <Project Sdk =" Microsoft.NET.Sdk" >
2
2
3
3
<PropertyGroup >
4
4
<OutputType >Exe</OutputType >
11
11
<PackageReference Include =" Microsoft.Build.Locator" Version =" 1.9.1" />
12
12
<PackageReference Include =" Microsoft.CodeAnalysis.CSharp.Workspaces" Version =" 4.14.0" />
13
13
<PackageReference Include =" Microsoft.CodeAnalysis.Workspaces.MSBuild" Version =" 4.14.0" />
14
+ <PackageReference Include =" Microsoft.NET.Test.Sdk" Version =" 17.14.0" />
15
+ <PackageReference Include =" NUnit" Version =" 4.3.2" />
16
+ <PackageReference Include =" NUnit3TestAdapter" Version =" 5.0.0" />
14
17
<PackageReference Include =" System.CommandLine" Version =" 2.0.0-beta4.22272.1" />
15
18
</ItemGroup >
16
19
Original file line number Diff line number Diff line change
1
+ using NUnit . Framework ;
2
+ using Utilities ;
3
+
4
+ [ assembly: Parallelizable ( ParallelScope . Children ) ]
5
+
6
+ namespace ExampleTester ;
7
+
8
+ public static class ExampleTests
9
+ {
10
+ private static TesterConfiguration TesterConfiguration { get ; } = new ( FindTmpDirectory ( ) ) ;
11
+ private static StatusCheckLogger StatusCheckLogger { get ; } = new ( ".." , "Example tester" ) ;
12
+
13
+ public static IEnumerable < object [ ] > LoadExamples ( ) =>
14
+ from example in GeneratedExample . LoadAllExamples ( TesterConfiguration . ExtractedOutputDirectory )
15
+ select new object [ ] { example } ;
16
+
17
+ [ TestCaseSource ( nameof ( LoadExamples ) ) ]
18
+ public static async Task ExamplePasses ( GeneratedExample example )
19
+ {
20
+ if ( ! await example . Test ( TesterConfiguration , StatusCheckLogger ) )
21
+ Assert . Fail ( "There were one or more failures. See the logged output for details." ) ;
22
+ }
23
+
24
+ private static string FindTmpDirectory ( )
25
+ {
26
+ for ( string ? current = AppDomain . CurrentDomain . BaseDirectory ; current != null ; current = Path . GetDirectoryName ( current ) )
27
+ {
28
+ string testPath = Path . Join ( current , "tmp" ) ;
29
+ if ( Directory . Exists ( testPath ) )
30
+ return testPath ;
31
+ }
32
+
33
+ throw new InvalidOperationException ( $ "Can't find 'tmp' directory in { AppDomain . CurrentDomain . BaseDirectory } or any parent directories.") ;
34
+ }
35
+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,8 @@ private GeneratedExample(string directory)
26
26
Metadata = JsonConvert . DeserializeObject < ExampleMetadata > ( metadataJson ) ?? throw new ArgumentException ( $ "Invalid (null) metadata in { directory } ") ;
27
27
}
28
28
29
+ public override string ? ToString ( ) => Metadata . ToString ( ) ;
30
+
29
31
internal static List < GeneratedExample > LoadAllExamples ( string parentDirectory ) =>
30
32
Directory . GetDirectories ( parentDirectory ) . Select ( Load ) . ToList ( ) ;
31
33
Original file line number Diff line number Diff line change @@ -5,12 +5,9 @@ namespace ExampleTester;
5
5
6
6
public record TesterConfiguration (
7
7
string ExtractedOutputDirectory ,
8
- bool Quiet ,
9
- string ? SourceFile ,
10
- string ? ExampleName )
11
- {
12
-
13
- }
8
+ bool Quiet = false ,
9
+ string ? SourceFile = null ,
10
+ string ? ExampleName = null ) ;
14
11
15
12
public class TesterConfigurationBinder : BinderBase < TesterConfiguration >
16
13
{
You can’t perform that action at this time.
0 commit comments