You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2021/12/16 13:49:22 UTC
[freemarker] 02/02: Print JUnit test failure details to console when building on Travis CI
This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a commit to branch FREEMARKER-35
in repository https://gitbox.apache.org/repos/asf/freemarker.git
commit beee05959b48982a9151cbe751dfca8f2ebfe527
Author: ddekany <dd...@apache.org>
AuthorDate: Thu Dec 16 14:19:59 2021 +0100
Print JUnit test failure details to console when building on Travis CI
---
build.xml | 26 +++++++++++++++--
.../freemarker/ext/beans/ErrorMessagesTest.java | 1 -
src/test/resources/logback-test-ci.xml | 34 ++++++++++++++++++++++
3 files changed, 57 insertions(+), 4 deletions(-)
diff --git a/build.xml b/build.xml
index 5f48e22..3250361 100644
--- a/build.xml
+++ b/build.xml
@@ -388,15 +388,24 @@
<!-- Testing -->
<!-- ================================================================= -->
- <target name="test" depends="compileTest" description="Run test cases">
+ <target name="test" depends="_test, _testFailedCheck" />
+
+ <target name="_test" depends="compileTest, _setTestPropertiesIfCiMode">
<mkdir dir="build/junit-reports" />
<ivy:cachepath conf="run.test" pathid="ivy.dep.run.test" />
- <junit haltonfailure="on" logfailedtests="true" fork="true" forkmode="once">
+ <junit failureproperty="testFailed" logfailedtests="true" fork="true" forkmode="once">
<classpath>
<pathelement path="build/test-classes" />
<pathelement path="build/classes" />
<path refid="ivy.dep.run.test" />
</classpath>
+ <syspropertyset>
+ <propertyref prefix="testSystemProperties."/>
+ <mapper type="glob" from="testSystemProperties.*" to="*"/>
+ </syspropertyset>
+ <!-- Print failure details on Travis CI to the console, as we can't access the report files there: -->
+ <formatter type="brief" usefile="false" if="ciMode" />
+ <!-- When not on Travis CI, these contain the detailed log: -->
<formatter type="plain" />
<formatter type="xml" />
<batchtest todir="build/junit-reports">
@@ -404,11 +413,21 @@
<include name="**/*Test.java" />
<include name="**/*TestSuite.java" />
<exclude name="**/Abstract*.java" />
+ <exclude name="**/AdhocTest*.java" />
</fileset>
</batchtest>
</junit>
</target>
-
+
+ <target name="_setTestPropertiesIfCiMode" if="ciMode">
+ <property name="testSystemProperties.logback.configurationFile" value="logback-test-ci.xml" />
+ <property name="testSystemProperties.logback.statusListenerClass" value="ch.qos.logback.core.status.OnConsoleStatusListener" />
+ </target>
+
+ <target name="_testFailedCheck" if="testFailed">
+ <fail message="Some tests have failed! Check build/junit-reports, or previous Ant log messages." />
+ </target>
+
<!-- ================================================================= -->
<!-- Generate docs -->
<!-- ================================================================= -->
@@ -929,6 +948,7 @@ Proceed? </input>
<target name="ci-setup">
<ivy:settings file="ivysettings-ci.xml" />
+ <property name="ciMode" value="true" />
</target>
<target name="ci"
diff --git a/src/test/java/freemarker/ext/beans/ErrorMessagesTest.java b/src/test/java/freemarker/ext/beans/ErrorMessagesTest.java
index 9849b8e..5ae80b7 100644
--- a/src/test/java/freemarker/ext/beans/ErrorMessagesTest.java
+++ b/src/test/java/freemarker/ext/beans/ErrorMessagesTest.java
@@ -45,7 +45,6 @@ public class ErrorMessagesTest {
try {
thm.get("foo");
} catch (TemplateModelException e) {
- e.printStackTrace();
final String msg = e.getMessage();
assertThat(msg, containsString("\"foo\""));
assertThat(msg, containsString("existing sub-variable"));
diff --git a/src/test/resources/logback-test-ci.xml b/src/test/resources/logback-test-ci.xml
new file mode 100644
index 0000000..140479d
--- /dev/null
+++ b/src/test/resources/logback-test-ci.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<configuration>
+ <!--
+ In Continuous Integration mode the Ant junit task is configured to print the failed test details to the console,
+ because we can't get the JUnit report on Travis CI, but see what was printed to the console. But then, for some
+ reason, the stdout of the tests will be echoed on the console as well. Thus we have to prevent it being flooded
+ by logs messages.
+ -->
+
+ <appender name="NOP" class="ch.qos.logback.core.helpers.NOPAppender" />
+
+ <root level="OFF">
+ <appender-ref ref="NOP" />
+ </root>
+
+</configuration>
\ No newline at end of file