@@ -12,33 +12,64 @@ public class R2RDumpTester : XunitBase
1212 private const string R2RDumpRelativePath = "R2RDump" ;
1313 private const string R2RDumpFile = "R2RDump.dll" ;
1414 private const string CoreRunFileName = "corerun" ;
15+
16+ public static string FindExePath ( string exe )
17+ {
18+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
19+ {
20+ exe = exe + ".exe" ;
21+ }
22+ exe = Environment . ExpandEnvironmentVariables ( exe ) ;
23+ if ( ! File . Exists ( exe ) )
24+ {
25+ if ( Path . GetDirectoryName ( exe ) == String . Empty )
26+ {
27+ foreach ( string test in ( Environment . GetEnvironmentVariable ( "PATH" ) ?? "" ) . Split ( Path . PathSeparator ) )
28+ {
29+ string path = test . Trim ( ) ;
30+ if ( ! String . IsNullOrEmpty ( path ) && File . Exists ( path = Path . Combine ( path , exe ) ) )
31+ return Path . GetFullPath ( path ) ;
32+ }
33+ }
34+ throw new FileNotFoundException ( new FileNotFoundException ( ) . Message , exe ) ;
35+ }
36+ return Path . GetFullPath ( exe ) ;
37+ }
1538
1639 [ Fact ]
1740 public void DumpCoreLib ( )
1841 {
1942 string CoreRootVar = Environment . GetEnvironmentVariable ( CoreRoot ) ;
2043 bool IsUnix = ! RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ;
21- string CoreRunFile = CoreRunFileName + ( IsUnix ? string . Empty : ".exe" ) ;
22- string CoreRunAbsolutePath = Path . Combine ( CoreRootVar , CoreRunFile ) ;
23- string R2RDumpAbsolutePath = Path . Combine ( Path . Combine ( CoreRootVar , R2RDumpRelativePath ) , R2RDumpFile ) ;
44+ string R2RDumpAbsolutePath = Path . Combine ( CoreRootVar , R2RDumpRelativePath , R2RDumpFile ) ;
2445 string CoreLibFile = "System.Private.CoreLib.dll" ;
2546 string CoreLibAbsolutePath = Path . Combine ( CoreRootVar , CoreLibFile ) ;
2647 string OutputFile = Path . GetTempFileName ( ) ;
48+ string TestDotNetCmdVar = Environment . GetEnvironmentVariable ( "__TestDotNetCmd" ) ;
49+ string DotNetAbsolutePath = string . IsNullOrEmpty ( TestDotNetCmdVar ) ? FindExePath ( "dotnet" ) : TestDotNetCmdVar ;
2750
2851 ProcessStartInfo processStartInfo = new ProcessStartInfo
2952 {
3053 UseShellExecute = false ,
31- FileName = CoreRunAbsolutePath ,
54+ FileName = DotNetAbsolutePath ,
3255 // TODO, what flags do we like to test?
33- Arguments = string . Join ( " " , new string [ ] { R2RDumpAbsolutePath , "--in" , CoreLibAbsolutePath , "--out" , OutputFile } )
56+ Arguments = string . Join ( " " , new string [ ] { "exec" , R2RDumpAbsolutePath , "--in" , CoreLibAbsolutePath , "--out" , OutputFile } )
3457 } ;
3558
3659 Process process = Process . Start ( processStartInfo ) ;
3760 process . WaitForExit ( ) ;
38- string outputFileContent = File . ReadAllText ( OutputFile ) ;
39- // TODO, validate content more carefully
40- Assert . True ( outputFileContent . Contains ( "ToString" ) ) ;
61+ int exitCode = process . ExitCode ;
62+ string outputContent = File . ReadAllText ( OutputFile ) ;
4163 File . Delete ( OutputFile ) ;
64+ // TODO, here is a point where we can add more validation to outputs
65+ // An uncaught exception (such as signature decoding error, would be caught by the error code)
66+ bool failed = exitCode != 0 ;
67+ if ( failed )
68+ {
69+ Console . WriteLine ( "The process terminated with exit code {0}" , exitCode ) ;
70+ Console . WriteLine ( outputContent ) ;
71+ Assert . True ( ! failed ) ;
72+ }
4273 }
4374
4475 public static int Main ( string [ ] args )
0 commit comments