Skip to content

Apache Lucene open-source search software

Move printing tests.verbose to error reporting test listener since we're already catching the output and handle it there anyway.

Dawid Weissd9e5daf01bac
diff --git a/buildSrc/src/main/java/org/apache/lucene/gradle/ErrorReportingTestListener.java b/buildSrc/src/main/java/org/apache/lucene/gradle/ErrorReportingTestListener.java
index cd149155951..44cd09b33f4 100644
--- a/buildSrc/src/main/java/org/apache/lucene/gradle/ErrorReportingTestListener.java
+++ b/buildSrc/src/main/java/org/apache/lucene/gradle/ErrorReportingTestListener.java
@@ -50,11 +50,13 @@ public class ErrorReportingTestListener implements TestOutputListener, TestListe
private final Map<TestKey, OutputHandler> outputHandlers = new ConcurrentHashMap<>();
private final Path spillDir;
private final Path outputsDir;
+ private final boolean verboseMode;
- public ErrorReportingTestListener(TestLogging testLogging, Path spillDir, Path outputsDir) {
+ public ErrorReportingTestListener(TestLogging testLogging, Path spillDir, Path outputsDir, boolean verboseMode) {
this.formatter = new FullExceptionFormatter(testLogging);
this.spillDir = spillDir;
this.outputsDir = outputsDir;
+ this.verboseMode = verboseMode;
}
@Override
@@ -91,7 +93,7 @@ public class ErrorReportingTestListener implements TestOutputListener, TestListe
}
boolean echoOutput = Objects.equals(result.getResultType(), TestResult.ResultType.FAILURE);
- boolean dumpOutput = echoOutput; // Force output dumping.
+ boolean dumpOutput = echoOutput;
// If the test suite failed, report output.
if (dumpOutput || echoOutput) {
@@ -105,7 +107,7 @@ public class ErrorReportingTestListener implements TestOutputListener, TestListe
}
}
- if (echoOutput) {
+ if (echoOutput && !verboseMode) {
synchronized (this) {
System.out.println("");
System.out.println(suite.getClassName() + " > test suite's output saved to " + outputLog + ", copied below:");
@@ -219,9 +221,14 @@ public class ErrorReportingTestListener implements TestOutputListener, TestListe
}
});
- sint = new PrefixedWriter(" > ", buffer, MAX_LINE_WIDTH);
- sout = new PrefixedWriter(" 1> ", buffer, MAX_LINE_WIDTH);
- serr = new PrefixedWriter(" 2> ", buffer, MAX_LINE_WIDTH);
+ Writer sink = buffer;
+ if (verboseMode) {
+ sink = new StdOutTeeWriter(buffer);
+ }
+
+ sint = new PrefixedWriter(" > ", sink, MAX_LINE_WIDTH);
+ sout = new PrefixedWriter(" 1> ", sink, MAX_LINE_WIDTH);
+ serr = new PrefixedWriter(" 2> ", sink, MAX_LINE_WIDTH);
last = sint;
}
diff --git a/buildSrc/src/main/java/org/apache/lucene/gradle/StdOutTeeWriter.java b/buildSrc/src/main/java/org/apache/lucene/gradle/StdOutTeeWriter.java
new file mode 100644
index 00000000000..20a4c8524f6
--- /dev/null
+++ b/buildSrc/src/main/java/org/apache/lucene/gradle/StdOutTeeWriter.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.gradle;
+
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.Writer;
+
+class StdOutTeeWriter extends Writer {
+ private final Writer delegate;
+ private final PrintStream out = System.out;
+
+ public StdOutTeeWriter(Writer delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public void write(int c) throws IOException {
+ delegate.write(c);
+ out.write(c);
+ }
+
+ @Override
+ public void write(char[] cbuf) throws IOException {
+ delegate.write(cbuf);
+ out.print(cbuf);
+ }
+
+ @Override
+ public void write(String str) throws IOException {
+ delegate.write(str);
+ out.print(str);
+ }
+
+ @Override
+ public void write(String str, int off, int len) throws IOException {
+ delegate.write(str, off, len);
+ out.append(str, off, len);
+ }
+
+ @Override
+ public Writer append(CharSequence csq) throws IOException {
+ delegate.append(csq);
+ out.append(csq);
+ return this;
+ }
+
+ @Override
+ public Writer append(CharSequence csq, int start, int end) throws IOException {
+ delegate.append(csq, start, end);
+ out.append(csq, start, end);
+ return this;
+ }
+
+ @Override
+ public Writer append(char c) throws IOException {
+ delegate.append(c);
+ out.append(c);
+ return this;
+ }
+
+ @Override
+ public void write(char[] cbuf, int off, int len) throws IOException {
+ delegate.write(cbuf, off, len);
+ out.print(new String(cbuf, off, len));
+ }
+
+ @Override
+ public void flush() throws IOException {
+ delegate.flush();
+ out.flush();
+ }
+
+ @Override
+ public void close() throws IOException {
+ delegate.close();
+ // Don't close the actual output.
+ }
+}
diff --git a/gradle/testing/defaults-tests.gradle b/gradle/testing/defaults-tests.gradle
index be133ca83d0..b15ec210cbd 100644
--- a/gradle/testing/defaults-tests.gradle
+++ b/gradle/testing/defaults-tests.gradle
@@ -76,39 +76,26 @@ allprojects {
reports.html.enabled = false
// Set up logging.
- if (verboseMode) {
- testLogging {
- events TestLogEvent.FAILED
- exceptionFormat TestExceptionFormat.FULL
- showExceptions true
- showCauses true
- showStackTraces true
- showStandardStreams = false
- }
- onOutput { td, event ->
- print event.message
- }
- } else {
- testLogging {
- events TestLogEvent.FAILED
- exceptionFormat TestExceptionFormat.FULL
- showExceptions true
- showCauses true
- showStackTraces true
- }
-
- // Set up custom test output handler.
- def testOutputsDir = file("${reports.junitXml.destination}/outputs")
- doFirst {
- project.delete testOutputsDir
- }
+ testLogging {
+ events TestLogEvent.FAILED
+ exceptionFormat TestExceptionFormat.FULL
+ showExceptions true
+ showCauses true
+ showStackTraces true
+ showStandardStreams false
+ }
- def spillDir = getTemporaryDir().toPath()
- def listener = new ErrorReportingTestListener(test.testLogging, spillDir, testOutputsDir.toPath())
- addTestOutputListener(listener)
- addTestListener(listener)
+ // Set up custom test output handler.
+ def testOutputsDir = file("${reports.junitXml.destination}/outputs")
+ doFirst {
+ project.delete testOutputsDir
}
+ def spillDir = getTemporaryDir().toPath()
+ def listener = new ErrorReportingTestListener(test.testLogging, spillDir, testOutputsDir.toPath(), verboseMode)
+ addTestOutputListener(listener)
+ addTestListener(listener)
+
doFirst {
// Print some diagnostics about locations used.
logger.info("Test folders for {}: cwd={}, tmp={}", project.path, testsWorkDir, testsTmpDir)