@@ -41,7 +41,10 @@ public void CanBuildComponentWithWitPackage()
4141 public void CanComposeImportWithExport ( )
4242 {
4343 var composed = FindModulePath ( "../testapps/SimpleConsumer" , "composed.wasm" ) ;
44- var stdout = ExecuteCommandComponent ( composed ) ;
44+ var ( stdout , stderr , code ) = ExecuteCommandComponent ( composed ) ;
45+ if ( code != 0 ) {
46+ Assert . Fail ( stderr ) ;
47+ }
4548 Assert . StartsWith ( "Hello, world on Wasm" , stdout ) ;
4649 Assert . Contains ( "123 + 456 = 579" , stdout ) ;
4750 }
@@ -50,15 +53,28 @@ public void CanComposeImportWithExport()
5053 public void CanBuildAppFromOci ( )
5154 {
5255 var composed = FindModulePath ( $ "../testapps/OciWit/bin/{ Config } ", "ociwit.wasm" ) ;
53- var stdout = ExecuteCommandComponent ( composed ) ;
56+ var ( stdout , stderr , code ) = ExecuteCommandComponent ( composed , "-S http" ) ;
57+ if ( code != 0 ) {
58+ Assert . Fail ( stderr ) ;
59+ }
5460 Assert . StartsWith ( "Oci is awesome!" , stdout ) ;
5561 }
5662
57- private static string ExecuteCommandComponent ( string componentFilePath )
63+ private static ( string , string , int ) ExecuteCommandComponent ( string componentFilePath )
64+ {
65+ return ExecuteCommandComponent ( componentFilePath , string . Empty ) ;
66+ }
67+
68+ private static ( string , string , int ) ExecuteCommandComponent ( string componentFilePath , string wasmtime_args )
5869 {
59- var startInfo = new ProcessStartInfo ( WasmtimeExePath , $ "-W component-model { componentFilePath } ") { RedirectStandardOutput = true } ;
60- var stdout = Process . Start ( startInfo ) ! . StandardOutput . ReadToEnd ( ) ;
61- return stdout ;
70+ var startInfo = new ProcessStartInfo ( WasmtimeExePath , $ " { wasmtime_args } { componentFilePath } ") { RedirectStandardOutput = true , RedirectStandardError = true } ;
71+ var process = Process . Start ( startInfo ) ?? throw new InvalidOperationException ( "Failed to start process." ) ;
72+ process . WaitForExit ( ) ;
73+ int code = process . ExitCode ;
74+ var stdout = process . StandardOutput . ReadToEnd ( ) ;
75+ var stderr = process . StandardError . ReadToEnd ( ) ;
76+
77+ return ( stdout , stderr , code ) ;
6278 }
6379
6480 private static string GetWitInfo ( string componentFilePath )
@@ -92,14 +108,17 @@ private static string FindModulePath(string searchDir, string filename)
92108 if ( matches . Count ( ) == 1 )
93109 {
94110 return Path . GetFullPath ( matches . Single ( ) ) ;
95- }
96- else if ( matches . Count ( ) == 2 && matches . Any ( x => Path . GetFullPath ( x ) . Contains ( $ "wasi-wasm\\ native") ) ) {
97- return Path . GetFullPath ( matches . First ( x => Path . GetFullPath ( x ) . Contains ( $ "wasi-wasm\\ native") ) ) ;
98111 }
99- else if ( matches . Count ( ) == 2 && matches . Any ( x => Path . GetFullPath ( x ) . Contains ( $ "wasi-wasm/native") ) ) {
100- return Path . GetFullPath ( matches . First ( x => Path . GetFullPath ( x ) . Contains ( $ "wasi-wasm/native") ) ) ;
112+ else if ( matches . Count ( ) == 2 && matches . Any ( x => Path . GetFullPath ( x ) . Contains ( $ "wasi-wasm\\ native") ) )
113+ {
114+ return Path . GetFullPath ( matches . First ( x => Path . GetFullPath ( x ) . Contains ( $ "wasi-wasm\\ native") ) ) ;
101115 }
102- else {
116+ else if ( matches . Count ( ) == 2 && matches . Any ( x => Path . GetFullPath ( x ) . Contains ( $ "wasi-wasm/native") ) )
117+ {
118+ return Path . GetFullPath ( matches . First ( x => Path . GetFullPath ( x ) . Contains ( $ "wasi-wasm/native") ) ) ;
119+ }
120+ else
121+ {
103122 throw new Exception ( $ "Failed to get modules path, matched { matches . Count ( ) } entries for directory { resolvedSearchDir } and filename { filename } .") ;
104123 }
105124 }
0 commit comments