8028708: TEST_BUG, Tests should pass through VM options, langtools tests

Reviewed-by: jjg, vromero
This commit is contained in:
Andrey Nazarov 2013-12-16 15:07:13 +00:00 committed by Vicente Romero
parent 4d99383951
commit 213b16163b
4 changed files with 72 additions and 82 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -25,10 +25,14 @@
* @test
* @bug 6604599
* @summary ToolProvider should be less compiler-specific
* @library /tools/javac/lib
* @build ToolBox
* @run main HelloWorldTest
*/
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
// verify that running a simple program, such as this one, does not trigger
// the loading of ToolProvider or any com.sun.tools.javac class
@ -43,32 +47,28 @@ public class HelloWorldTest {
}
void run() throws Exception {
File javaHome = new File(System.getProperty("java.home"));
if (javaHome.getName().equals("jre"))
javaHome = javaHome.getParentFile();
File javaExe = new File(new File(javaHome, "bin"), "java");
String classpath = System.getProperty("java.class.path");
String[] cmd = {
javaExe.getPath(),
"-verbose:class",
"-classpath", classpath,
HelloWorldTest.class.getName(),
"Hello", "World"
};
List<String> output = new ArrayList<>();
ToolBox.AnyToolArgs javaParams =
new ToolBox.AnyToolArgs()
.appendArgs(ToolBox.javaBinary)
.appendArgs(ToolBox.testVMOpts)
.appendArgs(ToolBox.testJavaOpts)
.appendArgs("-verbose:class",
"-classpath", classpath,
HelloWorldTest.class.getName(),
"Hello", "World")
.setErrOutput(output)
.setStdOutput(output);
ProcessBuilder pb = new ProcessBuilder(cmd).redirectErrorStream(true);
Process p = pb.start();
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = r.readLine()) != null) {
ToolBox.executeCommand(javaParams);
for (String line : output) {
System.err.println(line);
if (line.contains("javax.tools.ToolProvider") || line.contains("com.sun.tools.javac."))
error(">>> " + line);
}
int rc = p.waitFor();
if (rc != 0)
error("Unexpected exit code: " + rc);
if (errors > 0)
throw new Exception(errors + " errors occurred");