8240970: Some tests fail when run with JCov

Reviewed-by: jjg
This commit is contained in:
Vicente Romero 2020-03-18 14:33:05 -04:00
parent 700f50f287
commit bf54c47471
7 changed files with 83 additions and 61 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2020, 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
@ -62,8 +62,11 @@ public class EarlyAssertWrapper {
String line;
DataInputStream in = new DataInputStream(p.getInputStream());
try {
while ((line = in.readLine()) != null)
pw.println(line);
while ((line = in.readLine()) != null) {
if (!line.matches("^Picked up .*JAVA.*OPTIONS:.*")) {
pw.println(line);
}
}
} finally {
in.close();
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, 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
@ -37,6 +37,9 @@ import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.stream.Collectors;
import com.sun.tools.javac.util.Assert;
import toolbox.TestRunner;
import toolbox.JarTask;
@ -53,24 +56,27 @@ public class ClassPathWithDoubleQuotesTest extends TestRunner {
private static final String JarSrc = "public class J {}";
private static final String[] jarArgs = {"cf", "test/jarOut/J.jar", "-C", "test/jarSrc", "J.java"};
public static final String NEW_LINE = System.getProperty("line.separator");
private static final String expectedFailureOutput1 =
"A.java:1:18: compiler.err.cant.resolve.location: kindname.class, J, , , (compiler.misc.location: kindname.class, A, null)" + NEW_LINE +
"A.java:1:23: compiler.err.cant.resolve.location: kindname.class, B, , , (compiler.misc.location: kindname.class, A, null)" + NEW_LINE +
"2 errors" + NEW_LINE;
private static final String expectedFailureOutput2A =
"- compiler.warn.invalid.path: \"test/jarOut/J.jar" + NEW_LINE +
"- compiler.warn.invalid.path: test/src\"" + NEW_LINE +
"A.java:1:18: compiler.err.cant.resolve.location: kindname.class, J, , , (compiler.misc.location: kindname.class, A, null)" + NEW_LINE +
"A.java:1:23: compiler.err.cant.resolve.location: kindname.class, B, , , (compiler.misc.location: kindname.class, A, null)" + NEW_LINE +
"2 errors" + NEW_LINE +
"2 warnings" + NEW_LINE;
private static final String expectedFailureOutput2B =
"- compiler.warn.path.element.not.found: \"test/jarOut/J.jar" + NEW_LINE +
"- compiler.warn.path.element.not.found: test/src\"" + NEW_LINE +
"A.java:1:18: compiler.err.cant.resolve.location: kindname.class, J, , , (compiler.misc.location: kindname.class, A, null)" + NEW_LINE +
"A.java:1:23: compiler.err.cant.resolve.location: kindname.class, B, , , (compiler.misc.location: kindname.class, A, null)" + NEW_LINE +
"2 errors" + NEW_LINE +
"2 warnings" + NEW_LINE;
private static final List<String> expectedFailureOutput1 = List.of(
"A.java:1:18: compiler.err.cant.resolve.location: kindname.class, J, , , (compiler.misc.location: kindname.class, A, null)",
"A.java:1:23: compiler.err.cant.resolve.location: kindname.class, B, , , (compiler.misc.location: kindname.class, A, null)",
"2 errors"
);
private static final List<String> expectedFailureOutput2A = List.of(
"- compiler.warn.invalid.path: \"test/jarOut/J.jar",
"- compiler.warn.invalid.path: test/src\"",
"A.java:1:18: compiler.err.cant.resolve.location: kindname.class, J, , , (compiler.misc.location: kindname.class, A, null)",
"A.java:1:23: compiler.err.cant.resolve.location: kindname.class, B, , , (compiler.misc.location: kindname.class, A, null)",
"2 errors",
"2 warnings"
);
private static final List<String> expectedFailureOutput2B = List.of(
"- compiler.warn.path.element.not.found: \"test/jarOut/J.jar",
"- compiler.warn.path.element.not.found: test/src\"",
"A.java:1:18: compiler.err.cant.resolve.location: kindname.class, J, , , (compiler.misc.location: kindname.class, A, null)",
"A.java:1:23: compiler.err.cant.resolve.location: kindname.class, B, , , (compiler.misc.location: kindname.class, A, null)",
"2 errors",
"2 warnings"
);
public static void main(String... args) throws Exception {
new ClassPathWithDoubleQuotesTest().runTests();
@ -117,26 +123,26 @@ public class ClassPathWithDoubleQuotesTest extends TestRunner {
// testing scenario 2
System.err.println("Simulate a system in which double quotes are preserved in the environment variable," +
"and for which they are a legal filename character");
String log = new JavacTask(tb, Task.Mode.EXEC)
List<String> log = new JavacTask(tb, Task.Mode.EXEC)
.envVar("CLASSPATH", "Ztest/jarOut/J.jar" + File.pathSeparator + "test/srcZ")
.options("-XDrawDiagnostics")
.files("test/src/A.java").run(Task.Expect.FAIL)
.writeAll()
.getOutput(Task.OutputKind.STDERR);
Assert.check(log.equals(expectedFailureOutput1), "unexpected output");
.getOutputLines(Task.OutputKind.STDERR);
log = log.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
tb.checkEqual(log, expectedFailureOutput1);
System.err.println("compilation is expected to fail");
System.err.println();
// testing scenario 3
System.err.println("invoking javac EXEC mode with double quotes in the CLASSPATH env variable");
String log2 = new JavacTask(tb, Task.Mode.EXEC)
List<String> log2 = new JavacTask(tb, Task.Mode.EXEC)
.envVar("CLASSPATH", "\"test/jarOut/J.jar" + File.pathSeparator + "test/src\"")
.options("-Xlint:path", "-XDrawDiagnostics")
.files("test/src/A.java").run(Task.Expect.FAIL)
.writeAll()
.getOutput(Task.OutputKind.STDERR);
System.err.println();
System.err.println("the log:" + log2);
.getOutputLines(Task.OutputKind.STDERR);
log2 = log2.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
Assert.check(log2.equals(expectedFailureOutput2A) || log2.equals(expectedFailureOutput2B),
"unexpected output");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, 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
@ -48,6 +48,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import com.sun.tools.javac.launcher.Main;
@ -537,13 +538,13 @@ public class SourceLauncherTest extends TestRunner {
" }\n" +
"}");
String log = new JavaTask(tb)
List<String> log = new JavaTask(tb)
.vmOptions("--enable-preview")
.className(base.resolve("HelloWorld.java").toString())
.run(Task.Expect.FAIL)
.getOutput(Task.OutputKind.STDERR);
checkEqual("stderr", log.trim(),
"error: --enable-preview must be used with --source");
.getOutputLines(Task.OutputKind.STDERR);
log = log.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
checkEqual("stderr", log, List.of("error: --enable-preview must be used with --source"));
}
@Test
@ -663,6 +664,11 @@ public class SourceLauncherTest extends TestRunner {
}
}
void checkEqual(String name, List<String> found, List<String> expect) {
out.println(name + ": " + found);
tb.checkEqual(expect, found);
}
void checkMatch(String name, String found, Pattern expect) {
out.println(name + ": " + found);
if (!expect.matcher(found).matches()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, 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
@ -37,6 +37,9 @@ import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.stream.Collectors;
import toolbox.JavaTask;
import toolbox.JavacTask;
import toolbox.Task;
@ -257,18 +260,15 @@ public class RequiresStaticTest extends ModuleTestBase {
.run()
.writeAll();
String log = new JavaTask(tb)
List<String> log = new JavaTask(tb)
.vmOptions("--module-path", m3Classes.toString(), "--add-modules", "m3x")
.className("m3x.Test")
.run()
.writeAll()
.getOutput(OutputKind.STDERR);
.getOutputLines(OutputKind.STDERR);
log = log.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
String expected = "ok" + System.getProperty("line.separator");
if (!expected.equals(log)) {
throw new AssertionError("Unexpected output: " + log);
}
tb.checkEqual(log, List.of("ok"));
}
@Test
@ -332,19 +332,16 @@ public class RequiresStaticTest extends ModuleTestBase {
.run()
.writeAll();
String log = new JavaTask(tb)
List<String> log = new JavaTask(tb)
.vmOptions("--module-path", m2Classes.toString() + File.pathSeparator + m3Classes.toString(),
"--add-modules", "m3x")
.className("m3x.Test")
.run()
.writeAll()
.getOutput(OutputKind.STDERR);
.getOutputLines(OutputKind.STDERR);
log = log.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
String expected = "ok" + System.getProperty("line.separator");
if (!expected.equals(log)) {
throw new AssertionError("Unexpected output: " + log);
}
tb.checkEqual(log, List.of("ok"));
}
@Test

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2020, 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
@ -37,6 +37,9 @@
import java.util.Locale;
import java.util.List;
import java.util.stream.Collectors;
import java.nio.file.Path;
import java.nio.file.Paths;
@ -200,14 +203,20 @@ public class OptionSmokeTest extends TestRunner {
public void unmatchedQuoteInEnvVar(Path base) throws Exception {
Path src = base.resolve("src");
tb.writeJavaFiles(src, "class Dummy {}");
String log = new JavacTask(tb, Task.Mode.EXEC)
List<String> log = new JavacTask(tb, Task.Mode.EXEC)
.envVar("JDK_JAVAC_OPTIONS",
String.format("--add-exports jdk.compiler%scom.sun.tools.javac.jvm=\"ALL-UNNAMED", fileSeparator))
.files(findJavaFiles(src))
.run(Task.Expect.FAIL)
.writeAll()
.getOutput(Task.OutputKind.STDERR);
Assert.check(log.startsWith("error: unmatched quote in environment variable JDK_JAVAC_OPTIONS"));
.getOutputLines(Task.OutputKind.STDERR);
log = log.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
List<String> expected = List.of(
"error: unmatched quote in environment variable JDK_JAVAC_OPTIONS",
"Usage: javac <options> <source files>",
"use --help for a list of possible options"
);
tb.checkEqual(log, expected);
}
@Test

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, 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
@ -46,6 +46,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Processor;
@ -117,7 +118,7 @@ public class PlatformProviderTest implements PlatformProvider {
"compiler.misc.count.warn",
"close");
List<String> actualOutput = result.getOutputLines(Task.OutputKind.STDERR);
result.writeAll();
actualOutput = actualOutput.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
if (!expectedOutput.equals(actualOutput)) {
throw new AssertionError( "Expected output: " + expectedOutput +
"; actual output: " + actualOutput);
@ -144,12 +145,8 @@ public class PlatformProviderTest implements PlatformProvider {
"error: release version fail not supported",
"javac.msg.usage");
List<String> actualOutput = result.getOutputLines(Task.OutputKind.STDERR);
result.writeAll();
if (!expectedOutput.equals(actualOutput)) {
throw new AssertionError( "Expected output: " + expectedOutput +
"; actual output: " + actualOutput);
}
result.writeAll();
actualOutput = actualOutput.stream().filter(s->!s.matches("^Picked up .*JAVA.*OPTIONS:.*")).collect(Collectors.toList());
tb.checkEqual(expectedOutput, actualOutput);
}
@Override

View File

@ -92,6 +92,10 @@ public class CheckModuleTest {
ModuleDescriptor[] descriptors = analyzer.descriptors(name);
for (int i = 0; i < 3; i++) {
descriptors[i].requires().stream()
/* jcov has a dependency on java.logging, just ignore it in case this test is being executed with jcov
* this dependency from jcov should be fixed once bug: CODETOOLS-7902642 gets fixed
*/
.filter(req -> !req.toString().equals("java.logging"))
.forEach(req -> data.checkRequires(req));
}
}