You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@creadur.apache.org by po...@apache.org on 2018/10/03 20:02:10 UTC

svn commit: r1842757 - in /creadur/rat/trunk: apache-rat-plugin/src/test/java/org/apache/rat/mp/ apache-rat-tasks/src/main/java/org/apache/rat/anttasks/ apache-rat-tasks/src/test/resources/antunit/ src/changes/

Author: pottlinger
Date: Wed Oct  3 20:02:10 2018
New Revision: 1842757

URL: http://svn.apache.org/viewvc?rev=1842757&view=rev
Log:
RAT-228: Fix broken Ant integration tests

Make tests more deterministic and fix matcher setup.
Thanks to Romain Manni-Bucau

Modified:
    creadur/rat/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java
    creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
    creadur/rat/trunk/apache-rat-tasks/src/test/resources/antunit/report-normal-operation.xml
    creadur/rat/trunk/src/changes/changes.xml

Modified: creadur/rat/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java?rev=1842757&r1=1842756&r2=1842757&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java (original)
+++ creadur/rat/trunk/apache-rat-plugin/src/test/java/org/apache/rat/mp/RatCheckMojoTest.java Wed Oct  3 20:02:10 2018
@@ -42,6 +42,7 @@ import static org.apache.rat.mp.RatTestH
 import static org.apache.rat.mp.RatTestHelpers.newArtifactResolver;
 import static org.apache.rat.mp.RatTestHelpers.newSiteRenderer;
 import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
 
 /**
  * Test case for the {@link RatCheckMojo} and {@link RatReportMojo}.
@@ -233,23 +234,23 @@ public class RatCheckMojoTest extends Ab
             assertFalse("no null allowed in '" + msg + "'", (msg.toUpperCase()
                     .contains("NULL")));
         }
+        assertTrue(ratTxtFile.exists());
         DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
         FileInputStream fis = new FileInputStream(ratTxtFile);
-        boolean documentParsed = false;
         try {
             Document doc = db.parse(fis);
-            boolean byteSequencePresent = doc.getElementsByTagName("header-sample")
-                    .item(0)
-                    .getTextContent()
-                    .contains("\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF");
-            assertTrue("Report should contain test umlauts", byteSequencePresent);
-            documentParsed = true;
+            NodeList headerSample = doc.getElementsByTagName("header-sample");
+            String textContent = headerSample.item(0).getTextContent();
+            if (textContent.length() == 0) { // can be the pom since this test will parse 2 files but the pom is "ok"
+                textContent = headerSample.item(1).getTextContent();
+            }
+            boolean byteSequencePresent = textContent.contains("\u00E4\u00F6\u00FC\u00C4\u00D6\u00DC\u00DF");
+            assertTrue("Report should contain test umlauts, got '" + textContent + "'", byteSequencePresent);
         } catch (Exception ex) {
-            documentParsed = false;
+            fail("Report file could not be parsed as XML: " + ex.getMessage());
         } finally {
             fis.close();
         }
-        assertTrue("Report file could not be parsed as XML", documentParsed);
     }
 
 

Modified: creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java?rev=1842757&r1=1842756&r2=1842757&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java (original)
+++ creadur/rat/trunk/apache-rat-tasks/src/main/java/org/apache/rat/anttasks/Report.java Wed Oct  3 20:02:10 2018
@@ -292,14 +292,13 @@ public class Report extends Task {
      * required) into a single array.
      */
     private List<IHeaderMatcher> getLicenseMatchers() {
-        List<IHeaderMatcher> matchers = new ArrayList<IHeaderMatcher>(Defaults.DEFAULT_MATCHERS);
+        List<IHeaderMatcher> matchers = new ArrayList<IHeaderMatcher>(
+        (addDefaultLicenseMatchers ? Defaults.DEFAULT_MATCHERS.size() : 0) + licenseMatchers.size());
         if (addDefaultLicenseMatchers) {
-            int nestedSize = licenseMatchers.size();
-            if (nestedSize != 0) {
-                matchers.addAll(licenseMatchers);
-            }
+            matchers.addAll(Defaults.DEFAULT_MATCHERS);
+            matchers.addAll(licenseMatchers);
         } else {
-            matchers = new ArrayList<IHeaderMatcher>();
+            matchers = new ArrayList<IHeaderMatcher>(licenseMatchers);
         }
         return matchers;
     }

Modified: creadur/rat/trunk/apache-rat-tasks/src/test/resources/antunit/report-normal-operation.xml
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/apache-rat-tasks/src/test/resources/antunit/report-normal-operation.xml?rev=1842757&r1=1842756&r2=1842757&view=diff
==============================================================================
--- creadur/rat/trunk/apache-rat-tasks/src/test/resources/antunit/report-normal-operation.xml (original)
+++ creadur/rat/trunk/apache-rat-tasks/src/test/resources/antunit/report-normal-operation.xml Wed Oct  3 20:02:10 2018
@@ -330,7 +330,7 @@ public class LicenseFamily implements IL
 }
 ]]></echo>
     <javac srcdir="${output.dir}/src" destdir="${output.dir}/dest"
-           classpath="${test.classpath}"/>
+           classpath="${test.classpath}" fork="true"/>
     <typedef name="exmpl" classname="org.example.Matcher"
              classpathref="all-classes-needed-for-tests"
              loaderref="testloader"/>

Modified: creadur/rat/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/creadur/rat/trunk/src/changes/changes.xml?rev=1842757&r1=1842756&r2=1842757&view=diff
==============================================================================
--- creadur/rat/trunk/src/changes/changes.xml (original)
+++ creadur/rat/trunk/src/changes/changes.xml Wed Oct  3 20:02:10 2018
@@ -55,6 +55,9 @@ The <action> type attribute can be add,u
 
   <body>
     <release version="0.13" date="2018-xx-xx" description="Current SNAPSHOT - to be done">
+      <action issue="RAT-228" type="add" due-to="Romain Manni-Bucau" dev="pottlinger">
+        Fixing broken Ant unit test setup and making tests run more deterministic.
+      </action>
       <action issue="RAT-245" type="add" dev="pottlinger">
         Update to latest available and compatible Apache ANT 1.9.12 to get bugfixes and newer JDK support.
       </action>