11using System . Diagnostics ;
22using System . Text ;
33using DiffEngine ;
4+ using Draco . ProjectSystem ;
45
56namespace Draco . Examples . Tests ;
67
8+ // NOTE: Unnfortunately the tooling seemms to have a race condition if we attempt a design-time build here
9+ // So we order to first run the examples, and then the design-time build
10+ [ TestCaseOrderer ( "Draco.Examples.Tests.PriorityOrderer" , "Draco.Examples.Tests" ) ]
711public sealed class ExamplesTests
812{
9- public static IEnumerable < object [ ] > TestData
10- {
11- get
13+ // Each directory contains a projectfile, and a verification file, return each pair
14+ public static IEnumerable < object [ ] > TestData => TestUtils . ExampleDirectories
15+ . Select ( directory => new object [ ]
1216 {
13- // Get all example projects
14- // We exclude the "Toolchain" folder, in case the user has installed it in the examples directory
15- var exampleProjectDirectories = Directory
16- . GetDirectories ( "examples" , "*" , SearchOption . TopDirectoryOnly )
17- . Where ( d => Path . GetFileName ( d ) != "Toolchain" ) ;
18- // Each directory contains a projectfile, and a verification file, return each pair
19- return exampleProjectDirectories
20- . Select ( directory => new object [ ]
21- {
22- // Search for the dracoproj file
23- Directory . GetFiles ( directory , "*.dracoproj" ) . Single ( ) ,
24- // The verification file is always named "verify.txt"
25- Path . Combine ( directory , "verify.txt" ) ,
26- } ) ;
27- }
28- }
29-
30- private const string DescriptionForNotInstalledToolchain = """
31- Note, that you need to have the toolchain installed in the examples directory, in order to run these tests.
32- You can do that by running the install_toolchain.ps1 script in the scripts directory and passing in the path to the examples directory.
33- """ ;
17+ // Search for the dracoproj file
18+ Directory . GetFiles ( directory , "*.dracoproj" ) . Single ( ) ,
19+ // The verification file is always named "verify.txt"
20+ Path . Combine ( directory , "verify.txt" ) ,
21+ } ) ;
3422
3523 public ExamplesTests ( )
3624 {
3725 DiffTools . UseOrder ( DiffTool . VisualStudioCode , DiffTool . VisualStudio , DiffTool . Rider ) ;
3826 }
3927
40- [ Theory ]
28+ [ Theory , TestPriority ( 1 ) ]
4129 [ MemberData ( nameof ( TestData ) ) ]
4230 public async Task RunExample ( string projectFile , string verifiedFile )
4331 {
@@ -67,13 +55,22 @@ public async Task RunExample(string projectFile, string verifiedFile)
6755 }
6856 var gotOutput = standardOutput . ToString ( ) ;
6957
58+ var standardError = new StringBuilder ( ) ;
59+ while ( ! process . StandardError . EndOfStream )
60+ {
61+ var line = process . StandardError . ReadLine ( ) ;
62+ standardError . AppendLine ( line ) ;
63+ }
64+ var gotError = standardError . ToString ( ) ;
65+
7066 // Wait for the process to exit
7167 process . WaitForExit ( ) ;
7268
7369 // Verify that the process exited successfully
7470 Assert . True ( process . ExitCode == 0 , $ """
7571 The process exited with a non-zero exit code ({ process . ExitCode } ).
76- { DescriptionForNotInstalledToolchain }
72+ Message: { gotError }
73+ { TestUtils . DescriptionForNotInstalledToolchain }
7774 """ ) ;
7875
7976 // Configure verifier
@@ -84,4 +81,22 @@ public async Task RunExample(string projectFile, string verifiedFile)
8481 // Compare output to the verified file
8582 await Verify ( gotOutput , settings ) ;
8683 }
84+
85+ [ Fact , TestPriority ( 2 ) ]
86+ public void DesignTimeBuild ( )
87+ {
88+ // Iniitialize the workspace
89+ var workspace = Workspace . Initialize ( TestUtils . ExamplesDirectory ) ;
90+
91+ // Assert we have projects in there
92+ var projects = workspace . Projects . ToList ( ) ;
93+ Assert . NotEmpty ( projects ) ;
94+
95+ // Run the design time build for each
96+ foreach ( var project in projects )
97+ {
98+ var buildResult = project . BuildDesignTime ( ) ;
99+ Assert . True ( buildResult . Success , buildResult . Log ) ;
100+ }
101+ }
87102}
0 commit comments