You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by tm...@apache.org on 2019/05/27 10:54:18 UTC

[netbeans] branch master updated: [NETBEANS-1851] PHPUnit java.lang.AssertionError: At least 2 lines must be found (message + stacktrace)

This is an automated email from the ASF dual-hosted git repository.

tmysik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 212a9c4  [NETBEANS-1851] PHPUnit java.lang.AssertionError: At least 2 lines must be found (message + stacktrace)
     new ac716ae  Merge pull request #1265 from junichi11/netbeans-1851
212a9c4 is described below

commit 212a9c411301000e2c3cd32c85c3c60a44b2b9bb
Author: Junichi Yamamoto <ju...@apache.org>
AuthorDate: Sat May 25 12:04:53 2019 +0900

    [NETBEANS-1851] PHPUnit java.lang.AssertionError: At least 2 lines must be found (message + stacktrace)
    
    - stacktrace may be empty
---
 .../modules/php/phpunit/run/PhpUnitLogParser.java  |  7 +++-
 .../test/unit/data/phpunit-log-netbeans1851.xml    | 47 ++++++++++++++++++++++
 .../php/phpunit/run/PhpUnitLogParserTest.java      | 15 +++++++
 3 files changed, 68 insertions(+), 1 deletion(-)

diff --git a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/run/PhpUnitLogParser.java b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/run/PhpUnitLogParser.java
index 5b39d22..b7cf90d 100644
--- a/php/php.phpunit/src/org/netbeans/modules/php/phpunit/run/PhpUnitLogParser.java
+++ b/php/php.phpunit/src/org/netbeans/modules/php/phpunit/run/PhpUnitLogParser.java
@@ -190,10 +190,15 @@ public final class PhpUnitLogParser extends DefaultHandler {
 
     private void fillStacktrace() {
         String[] lines = buffer.toString().trim().split("\n"); // NOI18N
-        assert lines.length >= 2 : "At least 2 lines must be found (message + stacktrace)";
+        // stacktrace may be empty, so check whether the new line is contained instead of lines.length >= 2
+        assert buffer.toString().contains("\n") : "At least 2 lines must be found (message + stacktrace)"; // NOI18N
 
         buffer = new StringBuilder(200);
         boolean stacktraceStarted = false;
+        // NETBEANS-1851 stacktrace is empty
+        if (lines.length == 1) {
+            buffer.append(lines[0]);
+        }
         // 1st line is skipped
         for (int i = 1; i < lines.length; ++i) {
             String line = lines[i];
diff --git a/php/php.phpunit/test/unit/data/phpunit-log-netbeans1851.xml b/php/php.phpunit/test/unit/data/phpunit-log-netbeans1851.xml
new file mode 100644
index 0000000..4521099
--- /dev/null
+++ b/php/php.phpunit/test/unit/data/phpunit-log-netbeans1851.xml
@@ -0,0 +1,47 @@
+<?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.
+
+-->
+<testsuites>
+  <testsuite name="" tests="17" assertions="16" errors="1" failures="0" skipped="0" time="0.003465">
+    <testsuite name="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" tests="17" assertions="16" errors="1" failures="0" skipped="0" time="0.003465">
+      <testcase name="testPlus" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="46" assertions="1" time="0.002022"/>
+      <testcase name="testPlus2" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="53" assertions="1" time="0.000110"/>
+      <testcase name="testPlus3" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="60" assertions="1" time="0.000112"/>
+      <testcase name="testPlus4" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="67" assertions="1" time="0.000159"/>
+      <testcase name="testMinus" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="74" assertions="1" time="0.000166"/>
+      <testcase name="testMinus2" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="81" assertions="1" time="0.000156"/>
+      <testcase name="testMinus3" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="88" assertions="1" time="0.000092"/>
+      <testcase name="testMinus4" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="95" assertions="1" time="0.000073"/>
+      <testcase name="testMultiply" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="102" assertions="1" time="0.000066"/>
+      <testcase name="testMultiply2" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="109" assertions="1" time="0.000066"/>
+      <testcase name="testMultiply3" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="116" assertions="1" time="0.000065"/>
+      <testcase name="testMultiply4" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="123" assertions="1" time="0.000063"/>
+      <testcase name="testMultiply5" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="130" assertions="1" time="0.000064"/>
+      <testcase name="testDivide" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="137" assertions="1" time="0.000066"/>
+      <testcase name="testDivide2" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="144" assertions="1" time="0.000065"/>
+      <testcase name="testDivide3" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="151" assertions="1" time="0.000064"/>
+      <testcase name="testModulo" class="CalculatorTest" classname="CalculatorTest" file="/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php" line="158" assertions="0" time="0.000056">
+        <error type="PHPUnit\Framework\RiskyTestError">Risky Test
+</error>
+      </testcase>
+    </testsuite>
+  </testsuite>
+</testsuites>
diff --git a/php/php.phpunit/test/unit/src/org/netbeans/modules/php/phpunit/run/PhpUnitLogParserTest.java b/php/php.phpunit/test/unit/src/org/netbeans/modules/php/phpunit/run/PhpUnitLogParserTest.java
index 6bdd885..9c467ea 100644
--- a/php/php.phpunit/test/unit/src/org/netbeans/modules/php/phpunit/run/PhpUnitLogParserTest.java
+++ b/php/php.phpunit/test/unit/src/org/netbeans/modules/php/phpunit/run/PhpUnitLogParserTest.java
@@ -280,6 +280,21 @@ public class PhpUnitLogParserTest extends NbTestCase {
         assertEquals(1465, tests);
     }
 
+    public void testParseLogNETBEANS1851() throws Exception {
+        Reader reader = createReader("phpunit-log-netbeans1851.xml");
+        TestSessionVo testSession = new TestSessionVo(null);
+
+        PhpUnitLogParser.parse(reader, testSession);
+
+        assertSame(1, testSession.getTestSuites().size());
+        TestSuiteVo testSuite = testSession.getTestSuites().get(0);
+        assertEquals("CalculatorTest", testSuite.getName());
+        assertEquals("/tmp/Calculator-PHPUnit/test/src/CalculatorTest.php", testSuite.getFile());
+        TestCaseVo testCase = testSuite.getTestCases().get(16);
+        assertTrue(testCase.isError());
+        assertEquals("Risky Test", testCase.getStackTrace()[0]);
+    }
+
     private Reader createReader(String filename) throws FileNotFoundException {
         return new BufferedReader(new FileReader(new File(getDataDir(), filename)));
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists