Skip to content

Commit

Permalink
[GR-19527] Improve SVMJUnitRunner error reporting.
Browse files Browse the repository at this point in the history
PullRequest: graal/4880
  • Loading branch information
cstancu committed Nov 14, 2019
2 parents 06e7666 + 058d42b commit 10dac24
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 9 deletions.
2 changes: 1 addition & 1 deletion substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
suite = {
"mxversion": "5.231.0",
"mxversion": "5.247.3",
"name": "substratevm",
"version" : "20.0.0",
"release" : False,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,29 @@
*/
package com.oracle.svm.junit;

import com.oracle.mxtool.junit.MxJUnitRequest;
import com.oracle.mxtool.junit.MxJUnitWrapper;
import com.oracle.mxtool.junit.MxJUnitWrapper.MxJUnitConfig;
import com.oracle.svm.core.option.HostedOptionKey;
import com.oracle.svm.core.util.VMError;
import java.io.BufferedReader;
import java.io.FileReader;
import junit.runner.Version;
import java.util.List;

import org.graalvm.compiler.options.Option;
import org.graalvm.nativeimage.hosted.Feature.FeatureAccess;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.hosted.Feature.FeatureAccess;
import org.junit.internal.JUnitSystem;
import org.junit.internal.RealSystem;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;

import com.oracle.mxtool.junit.MxJUnitRequest;
import com.oracle.mxtool.junit.MxJUnitWrapper;
import com.oracle.mxtool.junit.MxJUnitWrapper.MxJUnitConfig;
import com.oracle.svm.core.option.HostedOptionKey;
import com.oracle.svm.core.option.SubstrateOptionsParser;
import com.oracle.svm.core.util.VMError;

import junit.runner.Version;

public class SVMJUnitRunner {

Expand All @@ -50,6 +56,7 @@ public static class Options {
}

private final MxJUnitRequest request;
private final String missingClassesStr;

@Platforms(Platform.HOSTED_ONLY.class)
SVMJUnitRunner(FeatureAccess access) {
Expand All @@ -75,6 +82,32 @@ protected Class<?> resolveClass(String name) throws ClassNotFoundException {
}

request = builder.build();

missingClassesStr = getMissingClasses();
if (missingClassesStr != null) {
String testFileOption = SubstrateOptionsParser.commandArgument(Options.TestFile, Options.TestFile.getValue());
StringBuilder msg = new StringBuilder("Warning: The test configuration file specified via ").append(testFileOption)
.append(" contains missing classes. Test execution will fail at run time. ")
.append("Missing classes in configuration file: ").append(missingClassesStr);
// Checkstyle: stop
System.out.println(msg);
// Checkstyle: resume
}
}

/* Get a comma separated list of missing classes as reported by the request object. */
private String getMissingClasses() {
List<Failure> missingClasses = request.getMissingClasses();
if (missingClasses.size() > 0) {
StringBuilder missingClassesBuilder = new StringBuilder();
String delim = "";
for (Failure missingClass : missingClasses) {
missingClassesBuilder.append(delim).append(missingClass.getDescription().getDisplayName());
delim = ", ";
}
return missingClassesBuilder.toString();
}
return null;
}

private void run(String[] args) {
Expand Down Expand Up @@ -129,7 +162,22 @@ private void run(String[] args) {
}

Result result = MxJUnitWrapper.runRequest(junitCore, system, config, request);
System.exit(result.wasSuccessful() ? 0 : 1);

if (result.wasSuccessful()) {
system.out().println("Test run PASSED. Exiting with status 0.");
System.exit(0);
} else {
StringBuilder msg = new StringBuilder("Test run FAILED!");
if (missingClassesStr != null) {
msg.append(System.lineSeparator());
msg.append("Missing classes in configuration file: ").append(missingClassesStr);
msg.append(System.lineSeparator());
}
msg.append("Exiting with status 1.");
system.out().println(msg);
System.exit(1);
}

}

public static void main(String[] args) {
Expand Down

0 comments on commit 10dac24

Please sign in to comment.