mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-25 15:37:52 +01:00
extract the method evalWasm()
This commit is contained in:
parent
1b6d1b7ecc
commit
e69fe9c073
@ -104,10 +104,10 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
* Run a test single test. It run the method in Java and call it via node in the WenAssembly. If the result are
|
* Run a test single test. It run the method in Java and call it via node in the WenAssembly. If the result are
|
||||||
* different it fire an error.
|
* different it fire an error.
|
||||||
*
|
*
|
||||||
* @param methodName
|
|
||||||
* the method name of the test.
|
|
||||||
* @param script
|
* @param script
|
||||||
* The script engine
|
* The script engine
|
||||||
|
* @param methodName
|
||||||
|
* the method name of the test.
|
||||||
* @param params
|
* @param params
|
||||||
* the parameters for the method
|
* the parameters for the method
|
||||||
*/
|
*/
|
||||||
@ -138,6 +138,27 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
method.setAccessible( true );
|
method.setAccessible( true );
|
||||||
expected = method.invoke( null, params );
|
expected = method.invoke( null, params );
|
||||||
|
|
||||||
|
String actual = evalWasm( script, methodName, params );
|
||||||
|
assertEquals( String.valueOf( expected ), actual );
|
||||||
|
} catch( Exception ex ) {
|
||||||
|
throwException( ex );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluate the wasm exported function.
|
||||||
|
*
|
||||||
|
* @param script
|
||||||
|
* The script engine
|
||||||
|
* @param methodName
|
||||||
|
* the method name of the test.
|
||||||
|
* @param params
|
||||||
|
* the parameters for the method
|
||||||
|
* @return the output of the script
|
||||||
|
*/
|
||||||
|
public String evalWasm( ScriptEngine script, String methodName, Object... params ) {
|
||||||
|
try {
|
||||||
ProcessBuilder processBuilder;
|
ProcessBuilder processBuilder;
|
||||||
switch( script ) {
|
switch( script ) {
|
||||||
case SpiderMonkey:
|
case SpiderMonkey:
|
||||||
@ -156,15 +177,15 @@ public class WasmRule extends TemporaryFolder {
|
|||||||
processBuilder.directory( getRoot() );
|
processBuilder.directory( getRoot() );
|
||||||
Process process = processBuilder.start();
|
Process process = processBuilder.start();
|
||||||
int exitCode = process.waitFor();
|
int exitCode = process.waitFor();
|
||||||
String actual = readStream( process.getInputStream() ).trim();
|
String result = readStream( process.getInputStream() ).trim();
|
||||||
if( exitCode != 0 ) {
|
if( exitCode != 0 ) {
|
||||||
String errorMessage = readStream( process.getErrorStream() );
|
String errorMessage = readStream( process.getErrorStream() );
|
||||||
assertEquals( errorMessage, 0, exitCode );
|
assertEquals( errorMessage, 0, exitCode );
|
||||||
}
|
}
|
||||||
assertEquals( String.valueOf( expected ), actual );
|
return result;
|
||||||
} catch( Exception ex ) {
|
} catch( Exception ex ) {
|
||||||
throwException( ex );
|
throwException( ex );
|
||||||
return;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user