From 8ce6c1d9195fe161331c69626d5f74d6aa4550a3 Mon Sep 17 00:00:00 2001 From: Volker Berlin Date: Sat, 19 Mar 2022 20:37:20 +0100 Subject: [PATCH] Add also the result/stack if possible also if execution of the script is failing. --- .../inetsoftware/jwebassembly/WasmRule.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/test/de/inetsoftware/jwebassembly/WasmRule.java b/test/de/inetsoftware/jwebassembly/WasmRule.java index dfb608a..0527304 100644 --- a/test/de/inetsoftware/jwebassembly/WasmRule.java +++ b/test/de/inetsoftware/jwebassembly/WasmRule.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 - 2021 Volker Berlin (i-net software) + * Copyright 2017 - 2022 Volker Berlin (i-net software) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -617,21 +617,28 @@ public class WasmRule extends TemporaryFolder { stdoutMessage += readStream( process.getInputStream(), false ); errorMessage += readStream( process.getErrorStream(), false ); int exitCode = process.exitValue(); + + // read the result from file + File resultFile = new File( getRoot(), "testresult.json" ); + String result = null; + if( resultFile.exists() ) { + try( InputStreamReader jsonData = new InputStreamReader( new FileInputStream( new File( getRoot(), "testresult.json" ) ), StandardCharsets.UTF_8 ) ) { + @SuppressWarnings( "unchecked" ) + Map map = new Gson().fromJson( jsonData, Map.class ); + if( testData != null ) { + testResults.put( script, map ); + } + result = map.get( methodName ); + } + } + if( exitCode != 0 || !stdoutMessage.isEmpty() || !errorMessage.isEmpty() ) { System.err.println( stdoutMessage ); System.err.println( errorMessage ); - fail( stdoutMessage + '\n' + errorMessage + "\nExit code: " + exitCode ); + fail( stdoutMessage + '\n' + errorMessage + '\n' + result + "\nExit code: " + exitCode ); } - // read the result from file - try( InputStreamReader jsonData = new InputStreamReader( new FileInputStream( new File( getRoot(), "testresult.json" ) ), StandardCharsets.UTF_8 ) ) { - @SuppressWarnings( "unchecked" ) - Map map = new Gson().fromJson( jsonData, Map.class ); - if( testData != null ) { - testResults.put( script, map ); - } - return map.get( methodName ); - } + return result; } catch( Throwable ex ) { failed = true; ex.printStackTrace();