Improve test speed on error.

This commit is contained in:
Volker Berlin 2021-08-29 15:11:17 +02:00
parent 1bfe16b17b
commit fec40f1d40

View File

@ -71,14 +71,12 @@ public class WasmRule extends TemporaryFolder {
private final JWebAssembly compiler; private final JWebAssembly compiler;
private Map<ScriptEngine, File> compiledFiles = new HashMap<>(); private Map<ScriptEngine, Object> compiledFiles = new HashMap<>(); // File or Throwable
private Map<ScriptEngine, File> scriptFiles = new HashMap<>(); private Map<ScriptEngine, File> scriptFiles = new HashMap<>();
private boolean failed; private boolean failed;
private String textCompiled;
private Map<String, Object[]> testData; private Map<String, Object[]> testData;
private Map<ScriptEngine, Map<String, String>> testResults; private Map<ScriptEngine, Map<String, String>> testResults;
@ -200,27 +198,49 @@ public class WasmRule extends TemporaryFolder {
@Override @Override
protected void after() { protected void after() {
if( failed || JWebAssembly.LOGGER.isLoggable( Level.FINE )) { if( failed || JWebAssembly.LOGGER.isLoggable( Level.FINE )) {
for( File wasmFile : compiledFiles.values() ) { File watFile = null;
boolean wasJsFile = false;
boolean wasFiles = false;
for( Object fileOrException : compiledFiles.values() ) {
if( !(fileOrException instanceof File) ) {
continue;
}
wasFiles = true;
File wasmFile = (File)fileOrException;
File jsFile; File jsFile;
if( wasmFile.getName().endsWith( ".wasm" ) ) { if( wasmFile.getName().endsWith( ".wasm" ) ) {
jsFile = new File( wasmFile.toString() + ".js" ); jsFile = new File( wasmFile.toString() + ".js" );
} else if( wasmFile.getName().endsWith( ".wat" ) ) { } else if( wasmFile.getName().endsWith( ".wat" ) ) {
if( wasmFile.isFile() ) {
watFile = wasmFile;
}
String name = wasmFile.toString(); String name = wasmFile.toString();
jsFile = new File( name.substring( 0, name.length() - 4 ) + ".wasm.js" ); jsFile = new File( name.substring( 0, name.length() - 4 ) + ".wasm.js" );
} else { } else {
continue; continue;
} }
if( jsFile.isFile() ) { if( !wasJsFile && jsFile.isFile() ) {
try { try {
wasJsFile = true;
System.out.println( new String( Files.readAllBytes( jsFile.toPath() ), StandardCharsets.UTF_8 ) ); System.out.println( new String( Files.readAllBytes( jsFile.toPath() ), StandardCharsets.UTF_8 ) );
System.out.println(); System.out.println();
} catch( IOException e ) { } catch( IOException e ) {
e.printStackTrace(); e.printStackTrace();
} }
break;
} }
} }
System.out.println( textCompiled ); try {
String textCompiled;
if( watFile != null ) {
textCompiled = new String( Files.readAllBytes( watFile.toPath() ), StandardCharsets.UTF_8 );
} else {
textCompiled = compiler.compileToText();
}
System.out.println( textCompiled );
System.out.println();
} catch( IOException e ) {
e.printStackTrace();
}
} }
super.after(); super.after();
} }
@ -250,19 +270,20 @@ public class WasmRule extends TemporaryFolder {
* if the compiling is failing * if the compiling is failing
*/ */
public File compile( ScriptEngine script ) throws WasmException { public File compile( ScriptEngine script ) throws WasmException {
File file = compiledFiles.get( script ); Object fileOrException = compiledFiles.get( script );
if( file != null ) { if( fileOrException instanceof File ) {
// compile only once // compile only once
return file; return (File)fileOrException;
}
if( fileOrException instanceof Throwable ) {
throwException( (Throwable)fileOrException );
} }
compiler.setProperty( JWebAssembly.DEBUG_NAMES, "true" ); compiler.setProperty( JWebAssembly.DEBUG_NAMES, "true" );
assertEquals( "true", compiler.getProperty( JWebAssembly.DEBUG_NAMES ) ); assertEquals( "true", compiler.getProperty( JWebAssembly.DEBUG_NAMES ) );
compiler.setProperty( JWebAssembly.WASM_USE_GC, script.useGC ); compiler.setProperty( JWebAssembly.WASM_USE_GC, script.useGC );
if( textCompiled == null ) { File file = null;
textCompiled = compiler.compileToText();
}
try { try {
String name = script.name(); String name = script.name();
if( name.contains( "Wat" ) ) { if( name.contains( "Wat" ) ) {
@ -274,7 +295,7 @@ public class WasmRule extends TemporaryFolder {
} }
compiledFiles.put( script, file ); compiledFiles.put( script, file );
} catch( Throwable ex ) { } catch( Throwable ex ) {
System.out.println( textCompiled ); compiledFiles.put( script, ex );
throwException( ex ); throwException( ex );
} }
return file; return file;