From c1283673d47726e6ef69634199dc6cf3f198c56a Mon Sep 17 00:00:00 2001 From: Kristian Rosenvold Date: Mon, 7 Jan 2013 04:14:11 +0100 Subject: [PATCH 01/14] o Fixed broken IT --- .../surefire/report/StatelessXmlReporter.java | 67 ++++++++++++++++++- .../report/TestSuiteXmlParserTest.java | 17 +++++ 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java index ec150b61a7..b4f11111dd 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java @@ -211,7 +211,7 @@ private void getTestProblems( XMLWriter ppw, WrappedReportEntry report, boolean if ( report.getMessage() != null && report.getMessage().length() > 0 ) { - ppw.addAttribute( "message", report.getMessage() ); + ppw.addAttribute( "message", extraEscape( report.getMessage(), true ) ); } if ( report.getStackTraceWriter() != null ) @@ -235,7 +235,7 @@ private void getTestProblems( XMLWriter ppw, WrappedReportEntry report, boolean if ( stackTrace != null ) { - ppw.writeText( stackTrace ); + ppw.writeText( extraEscape( stackTrace, false ) ); } ppw.endElement(); // entry type @@ -252,7 +252,7 @@ private void addOutputStreamElement( XMLWriter xmlWriter, String stdOut, String if ( stdOut != null && stdOut.trim().length() > 0 ) { xmlWriter.startElement( name ); - xmlWriter.writeText( stdOut ); + xmlWriter.writeText( extraEscape( stdOut, false ) ); xmlWriter.endElement(); } } @@ -296,4 +296,65 @@ private void showProperties( XMLWriter xmlWriter ) } xmlWriter.endElement(); } + + /** + * Handle stuff that may pop up in java that is not legal in xml + * + * @param message The string + * @param attribute + * @return The escaped string + */ + private static String extraEscape( String message, boolean attribute ) + { + // Someday convert to xml 1.1 which handles everything but 0 inside string + if ( !containsEscapesIllegalnXml10( message ) ) + { + return message; + } + return escapeXml( message, attribute ); + } + + private static boolean containsEscapesIllegalnXml10( String message ) + { + int size = message.length(); + for ( int i = 0; i < size; i++ ) + { + if ( isIllegalEscape( message.charAt( i ) ) ) + { + return true; + } + + } + return false; + } + + private static boolean isIllegalEscape( char c ) + { + return c < 32 && c != '\n' && c != '\r' && c != '\t'; + } + + private static String escapeXml( String text, boolean attribute ) + { + StringBuilder sb = new StringBuilder( text.length() * 2 ); + for ( int i = 0; i < text.length(); i++ ) + { + char c = text.charAt( i ); + if ( isIllegalEscape( c ) ) + { + // uh-oh! This character is illegal in XML 1.0! + // http://www.w3.org/TR/1998/REC-xml-19980210#charsets + // we're going to deliberately doubly-XML escape it... + // there's nothing better we can do! :-( + // SUREFIRE-456 + sb.append( attribute ? "&#" : "&#" ).append( (int) c ).append( + ';' ); // & Will be encoded to amp inside xml encodingSHO + } + else + { + sb.append( c ); + } + } + return sb.toString(); + } + } diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java index 0b8c871d03..a71158a113 100644 --- a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java +++ b/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java @@ -94,6 +94,23 @@ public void testParser() assertEquals( 2, next.getNumberOfTests() ); + } + + public void notTestParserBadFile() // Determine problem with xml file. + throws IOException, SAXException, ParserConfigurationException + { + TestSuiteXmlParser parser = new TestSuiteXmlParser(); + + Collection oldResult = parser.parse( + "../surefire-integration-tests/target/Surefire224WellFormedXmlFailuresIT/testWellFormedXmlFailures/target/surefire-reports/TEST-wellFormedXmlFailures.TestSurefire3.xml" ); + + assertNotNull( oldResult ); + + assertEquals( 1, oldResult.size() ); + ReportTestSuite next = oldResult.iterator().next(); + assertEquals( 2, next.getNumberOfTests() ); + + } public void testParserHitsFailsafeSummary() From 4dfdb08ccc881daa4f0745547dc2f649eefc8134 Mon Sep 17 00:00:00 2001 From: Kristian Rosenvold Date: Tue, 8 Jan 2013 15:54:48 +0100 Subject: [PATCH 02/14] o Fixed testcase on windows. o Fixed 2.2.1 tests by splitting report parser to separate module --- .../surefire/report/StatelessXmlReporter.java | 2 +- .../surefire/report/ReportTestCase.java | 0 .../surefire/report/ReportTestSuite.java | 0 .../surefire/report/SurefireReportParser.java | 0 .../surefire/report/TestSuiteXmlParser.java | 615 +++++++++--------- .../surefire/report/ReportTestCaseTest.java | 0 .../surefire/report/ReportTestSuiteTest.java | 0 .../report/SurefireReportParserTest.java | 0 .../report/TestSuiteXmlParserTest.java | 268 ++++---- ...apache.maven.surefire.test.FailingTest.xml | 0 .../failsafe-summary-old.xml | 0 .../testsuitexmlparser/failsafe-summary.xml | 0 .../resources/test-reports/TEST-AntUnit.xml | 0 .../test-reports/TEST-NoPackageTest.xml | 0 .../test-reports/TEST-NoTimeTestCaseTest.xml | 0 ...EST-classWithNoTests.NoMethodsTestCase.xml | 0 .../TEST-com.shape.CircleTest.xml | 0 .../test-reports/TEST-com.shape.PointTest.xml | 0 ...unit.twoTestCaseSuite.WrapperTestSuite.xml | 0 .../test-reports/com.shape.CircleTest.txt | 0 .../com.shapeclone.CircleTest.txt | 0 maven-surefire-report-plugin/pom.xml | 5 + pom.xml | 8 +- surefire-integration-tests/pom.xml | 4 +- .../test/resources/unicode-testnames/pom.xml | 5 + surefire-report-parser/pom.xml | 94 +++ .../surefire/report/ReportTestCase.java | 111 ++++ .../surefire/report/ReportTestSuite.java | 167 +++++ .../surefire/report/SurefireReportParser.java | 274 ++++++++ .../surefire/report/TestSuiteXmlParser.java | 310 +++++++++ .../surefire/report/ReportTestCaseTest.java | 82 +++ .../surefire/report/ReportTestSuiteTest.java | 118 ++++ .../report/SurefireReportParserTest.java | 242 +++++++ .../report/TestSuiteXmlParserTest.java | 136 ++++ ...apache.maven.surefire.test.FailingTest.xml | 154 +++++ .../failsafe-summary-old.xml | 8 + .../testsuitexmlparser/failsafe-summary.xml | 8 + .../resources/test-reports/TEST-AntUnit.xml | 11 + .../test-reports/TEST-NoPackageTest.xml | 256 ++++++++ .../test-reports/TEST-NoTimeTestCaseTest.xml | 92 +++ ...EST-classWithNoTests.NoMethodsTestCase.xml | 73 +++ .../TEST-com.shape.CircleTest.xml | 200 ++++++ .../test-reports/TEST-com.shape.PointTest.xml | 142 ++++ ...unit.twoTestCaseSuite.WrapperTestSuite.xml | 73 +++ .../test-reports/com.shape.CircleTest.txt | 122 ++++ .../com.shapeclone.CircleTest.txt | 122 ++++ 46 files changed, 3261 insertions(+), 441 deletions(-) rename {maven-surefire-report-plugin => maven-surefire-common}/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java (95%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java (90%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/TEST-AntUnit.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/TEST-NoPackageTest.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/TEST-com.shape.PointTest.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/com.shape.CircleTest.txt (100%) rename {maven-surefire-report-plugin => maven-surefire-common}/src/test/resources/test-reports/com.shapeclone.CircleTest.txt (100%) create mode 100644 surefire-report-parser/pom.xml create mode 100644 surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java create mode 100644 surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java create mode 100644 surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java create mode 100644 surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java create mode 100644 surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java create mode 100644 surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java create mode 100644 surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java create mode 100644 surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java create mode 100644 surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml create mode 100644 surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml create mode 100644 surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml create mode 100644 surefire-report-parser/src/test/resources/test-reports/TEST-AntUnit.xml create mode 100644 surefire-report-parser/src/test/resources/test-reports/TEST-NoPackageTest.xml create mode 100644 surefire-report-parser/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml create mode 100644 surefire-report-parser/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml create mode 100644 surefire-report-parser/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml create mode 100644 surefire-report-parser/src/test/resources/test-reports/TEST-com.shape.PointTest.xml create mode 100644 surefire-report-parser/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml create mode 100644 surefire-report-parser/src/test/resources/test-reports/com.shape.CircleTest.txt create mode 100644 surefire-report-parser/src/test/resources/test-reports/com.shapeclone.CircleTest.txt diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java index b4f11111dd..7690d0a7f4 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/StatelessXmlReporter.java @@ -288,7 +288,7 @@ private void showProperties( XMLWriter xmlWriter ) xmlWriter.addAttribute( "name", key ); - xmlWriter.addAttribute( "value", value ); + xmlWriter.addAttribute( "value", extraEscape( value, true )); xmlWriter.endElement(); diff --git a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java b/maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java similarity index 100% rename from maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java rename to maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java diff --git a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java b/maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java similarity index 100% rename from maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java rename to maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java diff --git a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java b/maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java similarity index 100% rename from maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java rename to maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java diff --git a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java b/maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java similarity index 95% rename from maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java rename to maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java index c2d8ee51ec..3f600b291a 100644 --- a/maven-surefire-report-plugin/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java @@ -1,305 +1,310 @@ -package org.apache.maven.plugins.surefire.report; - -/* - * 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. - */ - -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.text.NumberFormat; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.StringTokenizer; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.xml.sax.Attributes; -import org.xml.sax.SAXException; -import org.xml.sax.helpers.DefaultHandler; - -/** - * - */ -public class TestSuiteXmlParser - extends DefaultHandler -{ - private ReportTestSuite defaultSuite; - - private ReportTestSuite currentSuite; - - private Map classesToSuites; - - private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH ); - - /** - * @noinspection StringBufferField - */ - private StringBuffer currentElement; - - private ReportTestCase testCase; - - private boolean valid; - - public Collection parse( String xmlPath ) - throws ParserConfigurationException, SAXException, IOException - { - - File f = new File( xmlPath ); - - FileInputStream fileInputStream = new FileInputStream( f ); - - try - { - return parse( fileInputStream ); - } - finally - { - fileInputStream.close(); - } - } - - public Collection parse( InputStream stream ) - throws ParserConfigurationException, SAXException, IOException - { - SAXParserFactory factory = SAXParserFactory.newInstance(); - - SAXParser saxParser = factory.newSAXParser(); - - valid = true; - - classesToSuites = new HashMap(); - - saxParser.parse( stream, this ); - - if ( currentSuite != defaultSuite ) - { // omit the defaultSuite if it's empty and there are alternatives - if ( defaultSuite.getNumberOfTests() == 0 ) - { - classesToSuites.remove( defaultSuite.getFullClassName() ); - } - } - - return classesToSuites.values(); - } - - /** - * {@inheritDoc} - */ - public void startElement( String uri, String localName, String qName, Attributes attributes ) - throws SAXException - { - if ( !valid ) - { - return; - } - try - { - if ( "testsuite".equals( qName ) ) - { - currentSuite = defaultSuite = new ReportTestSuite(); - - try - { - Number time = numberFormat.parse( attributes.getValue( "time" ) ); - - defaultSuite.setTimeElapsed( time.floatValue() ); - } - catch ( NullPointerException npe ) - { - System.err.println( "WARNING: no time attribute found on testsuite element" ); - } - - //check if group attribute is existing - if ( attributes.getValue( "group" ) != null && !"".equals( attributes.getValue( "group" ) ) ) - { - String packageName = attributes.getValue( "group" ); - String name = attributes.getValue( "name" ); - - defaultSuite.setFullClassName( packageName + "." + name ); - } - else - { - String fullClassName = attributes.getValue( "name" ); - defaultSuite.setFullClassName( fullClassName ); - } - - classesToSuites.put( defaultSuite.getFullClassName(), defaultSuite ); - } - else if ( "testcase".equals( qName ) ) - { - currentElement = new StringBuffer(); - - testCase = new ReportTestCase(); - - testCase.setName( attributes.getValue( "name" ) ); - - String fullClassName = attributes.getValue( "classname" ); - - // if the testcase declares its own classname, it may need to belong to its own suite - if ( fullClassName != null ) - { - currentSuite = classesToSuites.get( fullClassName ); - if ( currentSuite == null ) - { - currentSuite = new ReportTestSuite(); - currentSuite.setFullClassName( fullClassName ); - classesToSuites.put( fullClassName, currentSuite ); - } - } - - testCase.setFullClassName( currentSuite.getFullClassName() ); - testCase.setClassName( currentSuite.getName() ); - testCase.setFullName( currentSuite.getFullClassName() + "." + testCase.getName() ); - - String timeAsString = attributes.getValue( "time" ); - - Number time = 0; - - if ( timeAsString != null ) - { - time = numberFormat.parse( timeAsString ); - } - - testCase.setTime( time.floatValue() ); - - if ( currentSuite != defaultSuite ) - { - currentSuite.setTimeElapsed( time.floatValue() + currentSuite.getTimeElapsed() ); - } - } - else if ( "failure".equals( qName ) ) - { - testCase.addFailure( attributes.getValue( "message" ), attributes.getValue( "type" ) ); - currentSuite.setNumberOfFailures( 1 + currentSuite.getNumberOfFailures() ); - } - else if ( "error".equals( qName ) ) - { - testCase.addFailure( attributes.getValue( "message" ), attributes.getValue( "type" ) ); - currentSuite.setNumberOfErrors( 1 + currentSuite.getNumberOfErrors() ); - } - else if ( "skipped".equals( qName ) ) - { - final String message = attributes.getValue( "message" ); - testCase.addFailure( message != null ? message : "skipped", "skipped" ); - currentSuite.setNumberOfSkipped( 1 + currentSuite.getNumberOfSkipped() ); - } - else if ( "failsafe-summary".equals( qName ) ) - { - valid = false; - } - } - catch ( ParseException e ) - { - throw new SAXException( e.getMessage(), e ); - } - } - - /** - * {@inheritDoc} - */ - public void endElement( String uri, String localName, String qName ) - throws SAXException - { - if ( "testcase".equals( qName ) ) - { - currentSuite.getTestCases().add( testCase ); - } - else if ( "failure".equals( qName ) ) - { - Map failure = testCase.getFailure(); - - failure.put( "detail", parseCause( currentElement.toString() ) ); - } - else if ( "error".equals( qName ) ) - { - Map error = testCase.getFailure(); - - error.put( "detail", parseCause( currentElement.toString() ) ); - } - else if ( "time".equals( qName ) ) - { - try - { - Number time = numberFormat.parse( currentElement.toString() ); - defaultSuite.setTimeElapsed( time.floatValue() ); - } - catch ( ParseException e ) - { - throw new SAXException( e.getMessage(), e ); - } - } - // TODO extract real skipped reasons - } - - /** - * {@inheritDoc} - */ - public void characters( char[] ch, int start, int length ) - throws SAXException - { - if ( !valid ) - { - return; - } - String s = new String( ch, start, length ); - - if ( !"".equals( s.trim() ) ) - { - currentElement.append( s ); - } - } - - private List parseCause( String detail ) - { - String fullName = testCase.getFullName(); - String name = fullName.substring( fullName.lastIndexOf( "." ) + 1 ); - return parseCause( detail, name ); - } - - private List parseCause( String detail, String compareTo ) - { - StringTokenizer stringTokenizer = new StringTokenizer( detail, "\n" ); - List parsedDetail = new ArrayList( stringTokenizer.countTokens() ); - - while ( stringTokenizer.hasMoreTokens() ) - { - String lineString = stringTokenizer.nextToken().trim(); - parsedDetail.add( lineString ); - if ( lineString.contains( compareTo ) ) - { - break; - } - } - - return parsedDetail; - } - - public boolean isValid() - { - return valid; - } -} +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * + */ +public class TestSuiteXmlParser + extends DefaultHandler +{ + private ReportTestSuite defaultSuite; + + private ReportTestSuite currentSuite; + + private Map classesToSuites; + + private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH ); + + /** + * @noinspection StringBufferField + */ + private StringBuffer currentElement; + + private ReportTestCase testCase; + + private boolean valid; + + public Collection parse( String xmlPath ) + throws ParserConfigurationException, SAXException, IOException + { + + File f = new File( xmlPath ); + + FileInputStream fileInputStream = new FileInputStream( f ); + + InputStreamReader inputStreamReader = new InputStreamReader( fileInputStream, "UTF-8" ); + + try + { + return parse( inputStreamReader ); + } + finally + { + inputStreamReader.close(); + fileInputStream.close(); + } + } + + public Collection parse( InputStreamReader stream ) + throws ParserConfigurationException, SAXException, IOException + { + SAXParserFactory factory = SAXParserFactory.newInstance(); + + SAXParser saxParser = factory.newSAXParser(); + + valid = true; + + classesToSuites = new HashMap(); + + saxParser.parse( new InputSource( stream ), this ); + + if ( currentSuite != defaultSuite ) + { // omit the defaultSuite if it's empty and there are alternatives + if ( defaultSuite.getNumberOfTests() == 0 ) + { + classesToSuites.remove( defaultSuite.getFullClassName() ); + } + } + + return classesToSuites.values(); + } + + /** + * {@inheritDoc} + */ + public void startElement( String uri, String localName, String qName, Attributes attributes ) + throws SAXException + { + if ( !valid ) + { + return; + } + try + { + if ( "testsuite".equals( qName ) ) + { + currentSuite = defaultSuite = new ReportTestSuite(); + + try + { + Number time = numberFormat.parse( attributes.getValue( "time" ) ); + + defaultSuite.setTimeElapsed( time.floatValue() ); + } + catch ( NullPointerException npe ) + { + System.err.println( "WARNING: no time attribute found on testsuite element" ); + } + + //check if group attribute is existing + if ( attributes.getValue( "group" ) != null && !"".equals( attributes.getValue( "group" ) ) ) + { + String packageName = attributes.getValue( "group" ); + String name = attributes.getValue( "name" ); + + defaultSuite.setFullClassName( packageName + "." + name ); + } + else + { + String fullClassName = attributes.getValue( "name" ); + defaultSuite.setFullClassName( fullClassName ); + } + + classesToSuites.put( defaultSuite.getFullClassName(), defaultSuite ); + } + else if ( "testcase".equals( qName ) ) + { + currentElement = new StringBuffer(); + + testCase = new ReportTestCase(); + + testCase.setName( attributes.getValue( "name" ) ); + + String fullClassName = attributes.getValue( "classname" ); + + // if the testcase declares its own classname, it may need to belong to its own suite + if ( fullClassName != null ) + { + currentSuite = classesToSuites.get( fullClassName ); + if ( currentSuite == null ) + { + currentSuite = new ReportTestSuite(); + currentSuite.setFullClassName( fullClassName ); + classesToSuites.put( fullClassName, currentSuite ); + } + } + + testCase.setFullClassName( currentSuite.getFullClassName() ); + testCase.setClassName( currentSuite.getName() ); + testCase.setFullName( currentSuite.getFullClassName() + "." + testCase.getName() ); + + String timeAsString = attributes.getValue( "time" ); + + Number time = 0; + + if ( timeAsString != null ) + { + time = numberFormat.parse( timeAsString ); + } + + testCase.setTime( time.floatValue() ); + + if ( currentSuite != defaultSuite ) + { + currentSuite.setTimeElapsed( time.floatValue() + currentSuite.getTimeElapsed() ); + } + } + else if ( "failure".equals( qName ) ) + { + testCase.addFailure( attributes.getValue( "message" ), attributes.getValue( "type" ) ); + currentSuite.setNumberOfFailures( 1 + currentSuite.getNumberOfFailures() ); + } + else if ( "error".equals( qName ) ) + { + testCase.addFailure( attributes.getValue( "message" ), attributes.getValue( "type" ) ); + currentSuite.setNumberOfErrors( 1 + currentSuite.getNumberOfErrors() ); + } + else if ( "skipped".equals( qName ) ) + { + final String message = attributes.getValue( "message" ); + testCase.addFailure( message != null ? message : "skipped", "skipped" ); + currentSuite.setNumberOfSkipped( 1 + currentSuite.getNumberOfSkipped() ); + } + else if ( "failsafe-summary".equals( qName ) ) + { + valid = false; + } + } + catch ( ParseException e ) + { + throw new SAXException( e.getMessage(), e ); + } + } + + /** + * {@inheritDoc} + */ + public void endElement( String uri, String localName, String qName ) + throws SAXException + { + if ( "testcase".equals( qName ) ) + { + currentSuite.getTestCases().add( testCase ); + } + else if ( "failure".equals( qName ) ) + { + Map failure = testCase.getFailure(); + + failure.put( "detail", parseCause( currentElement.toString() ) ); + } + else if ( "error".equals( qName ) ) + { + Map error = testCase.getFailure(); + + error.put( "detail", parseCause( currentElement.toString() ) ); + } + else if ( "time".equals( qName ) ) + { + try + { + Number time = numberFormat.parse( currentElement.toString() ); + defaultSuite.setTimeElapsed( time.floatValue() ); + } + catch ( ParseException e ) + { + throw new SAXException( e.getMessage(), e ); + } + } + // TODO extract real skipped reasons + } + + /** + * {@inheritDoc} + */ + public void characters( char[] ch, int start, int length ) + throws SAXException + { + if ( !valid ) + { + return; + } + String s = new String( ch, start, length ); + + if ( !"".equals( s.trim() ) ) + { + currentElement.append( s ); + } + } + + private List parseCause( String detail ) + { + String fullName = testCase.getFullName(); + String name = fullName.substring( fullName.lastIndexOf( "." ) + 1 ); + return parseCause( detail, name ); + } + + private List parseCause( String detail, String compareTo ) + { + StringTokenizer stringTokenizer = new StringTokenizer( detail, "\n" ); + List parsedDetail = new ArrayList( stringTokenizer.countTokens() ); + + while ( stringTokenizer.hasMoreTokens() ) + { + String lineString = stringTokenizer.nextToken().trim(); + parsedDetail.add( lineString ); + if ( lineString.contains( compareTo ) ) + { + break; + } + } + + return parsedDetail; + } + + public boolean isValid() + { + return valid; + } +} diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java similarity index 100% rename from maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java rename to maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java similarity index 100% rename from maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java rename to maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java similarity index 100% rename from maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java rename to maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java diff --git a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java similarity index 90% rename from maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java rename to maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java index a71158a113..beaf1b2dcc 100644 --- a/maven-surefire-report-plugin/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java @@ -1,132 +1,136 @@ -package org.apache.maven.plugins.surefire.report; - -/* - * 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. - */ - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Collection; - -import javax.xml.parsers.ParserConfigurationException; - -import junit.framework.TestCase; -import org.xml.sax.SAXException; - -/** - * @author Kristian Rosenvold - */ -public class TestSuiteXmlParserTest - extends TestCase -{ - public void testParse() - throws Exception - { - TestSuiteXmlParser testSuiteXmlParser = new TestSuiteXmlParser(); - String xml = "\n" + - "\n" - + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " junit.framework.AssertionFailedError: \n" - + - "\tat junit.framework.Assert.fail(Assert.java:47)\n" + - "\tat wellFormedXmlFailures.TestSurefire3.testU0000(TestSurefire3.java:40)\n" + - "\n" + - " \n" + - " \n" + - " junit.framework.AssertionFailedError: >\n" - + - "\tat junit.framework.Assert.fail(Assert.java:47)\n" + - "\tat wellFormedXmlFailures.TestSurefire3.testGreater(TestSurefire3.java:35)\n" + - "\n" + - " \n" + - " \n" + - " junit.framework.AssertionFailedError: \"\n" - + - "\tat junit.framework.Assert.fail(Assert.java:47)\n" + - "\tat wellFormedXmlFailures.TestSurefire3.testQuote(TestSurefire3.java:25)\n" + - "\n" + - " \n" + - ""; - InputStream byteArrayIs = new ByteArrayInputStream( xml.getBytes() ); - Collection parse = testSuiteXmlParser.parse( byteArrayIs ); - } - - public void testParser() - throws IOException, SAXException, ParserConfigurationException - { - TestSuiteXmlParser parser = new TestSuiteXmlParser(); - - Collection oldResult = parser.parse( - "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" ); - - assertNotNull( oldResult ); - - assertEquals( 1, oldResult.size() ); - ReportTestSuite next = oldResult.iterator().next(); - assertEquals( 2, next.getNumberOfTests() ); - - - } - - public void notTestParserBadFile() // Determine problem with xml file. - throws IOException, SAXException, ParserConfigurationException - { - TestSuiteXmlParser parser = new TestSuiteXmlParser(); - - Collection oldResult = parser.parse( - "../surefire-integration-tests/target/Surefire224WellFormedXmlFailuresIT/testWellFormedXmlFailures/target/surefire-reports/TEST-wellFormedXmlFailures.TestSurefire3.xml" ); - - assertNotNull( oldResult ); - - assertEquals( 1, oldResult.size() ); - ReportTestSuite next = oldResult.iterator().next(); - assertEquals( 2, next.getNumberOfTests() ); - - - } - - public void testParserHitsFailsafeSummary() - throws IOException, SAXException, ParserConfigurationException - { - TestSuiteXmlParser parser = new TestSuiteXmlParser(); - - parser.parse( "src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml" ); - - assertFalse( parser.isValid() ); - - parser.parse( - "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" ); - - assertTrue( parser.isValid() ); - } - - -} +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Collection; + +import javax.xml.parsers.ParserConfigurationException; + +import junit.framework.TestCase; +import org.xml.sax.SAXException; + +/** + * @author Kristian Rosenvold + */ +public class TestSuiteXmlParserTest + extends TestCase +{ + public void testParse() + throws Exception + { + TestSuiteXmlParser testSuiteXmlParser = new TestSuiteXmlParser(); + String xml = "\n" + + "\n" + + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " junit.framework.AssertionFailedError: \n" + + + "\tat junit.framework.Assert.fail(Assert.java:47)\n" + + "\tat wellFormedXmlFailures.TestSurefire3.testU0000(TestSurefire3.java:40)\n" + + "\n" + + " \n" + + " \n" + + " junit.framework.AssertionFailedError: >\n" + + + "\tat junit.framework.Assert.fail(Assert.java:47)\n" + + "\tat wellFormedXmlFailures.TestSurefire3.testGreater(TestSurefire3.java:35)\n" + + "\n" + + " \n" + + " \n" + + " junit.framework.AssertionFailedError: \"\n" + + + "\tat junit.framework.Assert.fail(Assert.java:47)\n" + + "\tat wellFormedXmlFailures.TestSurefire3.testQuote(TestSurefire3.java:25)\n" + + "\n" + + " \n" + + ""; + InputStream byteArrayIs = new ByteArrayInputStream( xml.getBytes() ); + Collection parse = testSuiteXmlParser.parse( new InputStreamReader(byteArrayIs, "UTF-8") ); + } + + public void testParser() + throws IOException, SAXException, ParserConfigurationException + { + TestSuiteXmlParser parser = new TestSuiteXmlParser(); + + Collection oldResult = parser.parse( + "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" ); + + assertNotNull( oldResult ); + + assertEquals( 1, oldResult.size() ); + ReportTestSuite next = oldResult.iterator().next(); + assertEquals( 2, next.getNumberOfTests() ); + + + } + + public void noTestParserBadFile() // Determine problem with xml file. + throws IOException, SAXException, ParserConfigurationException + { + TestSuiteXmlParser parser = new TestSuiteXmlParser(); + + File file = new File( "../surefire-integration-tests/target/UmlautDirIT/junit-pathWith\u00DCmlaut/target/surefire-reports/TEST-umlautTest.BasicTest.xml" ); + assertTrue(file.exists()); + Collection oldResult = parser.parse( + "..\\surefire-integration-tests\\target\\UmlautDirIT\\junit-pathWith\u00DCmlaut\\target\\surefire-reports\\TEST-umlautTest.BasicTest.xml" ); + + assertNotNull( oldResult ); + + assertEquals( 1, oldResult.size() ); + ReportTestSuite next = oldResult.iterator().next(); + assertEquals( 2, next.getNumberOfTests() ); + + + } + + public void testParserHitsFailsafeSummary() + throws IOException, SAXException, ParserConfigurationException + { + TestSuiteXmlParser parser = new TestSuiteXmlParser(); + + parser.parse( "src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml" ); + + assertFalse( parser.isValid() ); + + parser.parse( + "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" ); + + assertTrue( parser.isValid() ); + } + + +} diff --git a/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml b/maven-surefire-common/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml rename to maven-surefire-common/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml diff --git a/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml b/maven-surefire-common/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml rename to maven-surefire-common/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml diff --git a/maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml b/maven-surefire-common/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml rename to maven-surefire-common/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/TEST-AntUnit.xml b/maven-surefire-common/src/test/resources/test-reports/TEST-AntUnit.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/TEST-AntUnit.xml rename to maven-surefire-common/src/test/resources/test-reports/TEST-AntUnit.xml diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/TEST-NoPackageTest.xml b/maven-surefire-common/src/test/resources/test-reports/TEST-NoPackageTest.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/TEST-NoPackageTest.xml rename to maven-surefire-common/src/test/resources/test-reports/TEST-NoPackageTest.xml diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml b/maven-surefire-common/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml rename to maven-surefire-common/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml b/maven-surefire-common/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml rename to maven-surefire-common/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml b/maven-surefire-common/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml rename to maven-surefire-common/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/TEST-com.shape.PointTest.xml b/maven-surefire-common/src/test/resources/test-reports/TEST-com.shape.PointTest.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/TEST-com.shape.PointTest.xml rename to maven-surefire-common/src/test/resources/test-reports/TEST-com.shape.PointTest.xml diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml b/maven-surefire-common/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml rename to maven-surefire-common/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/com.shape.CircleTest.txt b/maven-surefire-common/src/test/resources/test-reports/com.shape.CircleTest.txt similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/com.shape.CircleTest.txt rename to maven-surefire-common/src/test/resources/test-reports/com.shape.CircleTest.txt diff --git a/maven-surefire-report-plugin/src/test/resources/test-reports/com.shapeclone.CircleTest.txt b/maven-surefire-common/src/test/resources/test-reports/com.shapeclone.CircleTest.txt similarity index 100% rename from maven-surefire-report-plugin/src/test/resources/test-reports/com.shapeclone.CircleTest.txt rename to maven-surefire-common/src/test/resources/test-reports/com.shapeclone.CircleTest.txt diff --git a/maven-surefire-report-plugin/pom.xml b/maven-surefire-report-plugin/pom.xml index 34c60942c4..3c2666bf87 100644 --- a/maven-surefire-report-plugin/pom.xml +++ b/maven-surefire-report-plugin/pom.xml @@ -65,6 +65,11 @@ maven-plugin-api + + org.apache.maven.surefire + surefire-report-parser + ${project.version} + org.apache.maven.reporting diff --git a/pom.xml b/pom.xml index c29ada6fc8..0fda14a87b 100644 --- a/pom.xml +++ b/pom.xml @@ -89,6 +89,7 @@ surefire-grouper surefire-providers maven-surefire-common + surefire-report-parser maven-surefire-plugin maven-failsafe-plugin maven-surefire-report-plugin @@ -112,7 +113,7 @@ 2.0.9 - 2.13 + 2.12.4 3.2 @@ -157,6 +158,11 @@ maven-surefire-common ${project.version} + + org.apache.maven.reporting + maven-reporting-api + ${mavenVersion} + org.apache.maven maven-core diff --git a/surefire-integration-tests/pom.xml b/surefire-integration-tests/pom.xml index 8df007ee5a..1fb0fccc5a 100644 --- a/surefire-integration-tests/pom.xml +++ b/surefire-integration-tests/pom.xml @@ -43,8 +43,8 @@ - org.apache.maven.plugins - maven-surefire-report-plugin + org.apache.maven.surefire + surefire-report-parser ${project.version} test diff --git a/surefire-integration-tests/src/test/resources/unicode-testnames/pom.xml b/surefire-integration-tests/src/test/resources/unicode-testnames/pom.xml index f42d50595d..1056c79212 100644 --- a/surefire-integration-tests/src/test/resources/unicode-testnames/pom.xml +++ b/surefire-integration-tests/src/test/resources/unicode-testnames/pom.xml @@ -48,6 +48,11 @@ maven-surefire-plugin ${surefire.version} + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + diff --git a/surefire-report-parser/pom.xml b/surefire-report-parser/pom.xml new file mode 100644 index 0000000000..5d1c8c7e2e --- /dev/null +++ b/surefire-report-parser/pom.xml @@ -0,0 +1,94 @@ + + + + + 4.0.0 + + + org.apache.maven.surefire + surefire + 2.14-SNAPSHOT + ../pom.xml + + + surefire-report-parser + + Surefire Report Parser + Parses report output files from surefire + + + 2.0.9 + + + + + org.apache.maven.shared + maven-shared-utils + + + org.apache.maven.reporting + maven-reporting-api + + + + + + maven-surefire-plugin + + true + + + + org.apache.maven.surefire + surefire-shadefire + ${project.version} + + + + + + org.apache.maven.plugins + maven-shade-plugin + + + package + + shade + + + true + + + org.apache.maven.shared:maven-shared-utils + + + + + org.apache.maven.shared + org.apache.maven.surefire.shade.org.apache.maven.shared + + + + + + + + + diff --git a/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java new file mode 100644 index 0000000000..3203f498ed --- /dev/null +++ b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestCase.java @@ -0,0 +1,111 @@ +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.util.HashMap; +import java.util.Map; + +/** + * + */ +public class ReportTestCase +{ + private String fullClassName; + + private String className; + + private String fullName; + + private String name; + + private float time; + + private Map failure; + + public String getName() + { + return name; + } + + public void setName( String name ) + { + this.name = name; + } + + public String getFullClassName() + { + return fullClassName; + } + + public void setFullClassName( String name ) + { + this.fullClassName = name; + } + + public String getClassName() + { + return className; + } + + public void setClassName( String name ) + { + this.className = name; + } + + public float getTime() + { + return time; + } + + public void setTime( float time ) + { + this.time = time; + } + + public Map getFailure() + { + return failure; + } + + public String getFullName() + { + return fullName; + } + + public void setFullName( String fullName ) + { + this.fullName = fullName; + } + + public void addFailure( String message, String type ) + { + failure = new HashMap(); + failure.put( "message", message ); + failure.put( "type", type ); + } + + /** + * {@inheritDoc} + */ + public String toString() + { + return fullName; + } +} diff --git a/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java new file mode 100644 index 0000000000..2bd65136f1 --- /dev/null +++ b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/ReportTestSuite.java @@ -0,0 +1,167 @@ +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +/** + * + */ +public class ReportTestSuite +{ + private List testCases = new ArrayList(); + + private int numberOfErrors; + + private int numberOfFailures; + + private int numberOfSkipped; + + private Integer numberOfTests; + + private String name; + + private String fullClassName; + + private String packageName; + + private float timeElapsed; + + public List getTestCases() + { + return this.testCases; + } + + public int getNumberOfErrors() + { + return numberOfErrors; + } + + public void setNumberOfErrors( int numberOfErrors ) + { + this.numberOfErrors = numberOfErrors; + } + + public int getNumberOfFailures() + { + return numberOfFailures; + } + + public void setNumberOfFailures( int numberOfFailures ) + { + this.numberOfFailures = numberOfFailures; + } + + public int getNumberOfSkipped() + { + return numberOfSkipped; + } + + public void setNumberOfSkipped( int numberOfSkipped ) + { + this.numberOfSkipped = numberOfSkipped; + } + + public int getNumberOfTests() + { + if ( numberOfTests != null ) + { + return numberOfTests; + } + if ( testCases != null ) + { + return testCases.size(); + } + return 0; + } + + public void setNumberOfTests( int numberOfTests ) + { + this.numberOfTests = numberOfTests; + } + + public String getName() + { + return name; + } + + public void setName( String name ) + { + this.name = name; + } + + public String getFullClassName() + { + return fullClassName; + } + + public void setFullClassName( String fullClassName ) + { + this.fullClassName = fullClassName; + int lastDotPosition = fullClassName.lastIndexOf( "." ); + + name = fullClassName.substring( lastDotPosition + 1, fullClassName.length() ); + + if ( lastDotPosition < 0 ) + { + /* no package name */ + packageName = ""; + } + else + { + packageName = fullClassName.substring( 0, lastDotPosition ); + } + } + + public String getPackageName() + { + return packageName; + } + + public void setPackageName( String packageName ) + { + this.packageName = packageName; + } + + public float getTimeElapsed() + { + return this.timeElapsed; + } + + public void setTimeElapsed( float timeElapsed ) + { + this.timeElapsed = timeElapsed; + } + + public void setTestCases( List testCases ) + { + this.testCases = testCases; + } + + /** + * {@inheritDoc} + */ + public String toString() + { + return fullClassName + " [" + getNumberOfTests() + "/" + getNumberOfFailures() + "/" + getNumberOfErrors() + "/" + + getNumberOfSkipped() + "]"; + } +} diff --git a/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java new file mode 100644 index 0000000000..feba2458b5 --- /dev/null +++ b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/SurefireReportParser.java @@ -0,0 +1,274 @@ +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import org.apache.maven.reporting.MavenReportException; +import org.apache.maven.shared.utils.StringUtils; +import org.apache.maven.shared.utils.io.DirectoryScanner; + +import javax.xml.parsers.ParserConfigurationException; + +import org.xml.sax.SAXException; + +/** + * + */ +public class SurefireReportParser +{ + private static final String INCLUDES = "*.xml"; + + private static final String EXCLUDES = "*.txt, testng-failed.xml, testng-failures.xml, testng-results.xml, failsafe-summary*.xml"; + + private NumberFormat numberFormat = NumberFormat.getInstance(); + + private List reportsDirectories; + + private final List testSuites = new ArrayList(); + + private static final int PCENT = 100; + + public SurefireReportParser() + { + } + + public SurefireReportParser( List reportsDirectoriesFiles, Locale locale ) + { + this.reportsDirectories = reportsDirectoriesFiles; + + setLocale( locale ); + } + + public List parseXMLReportFiles() + throws MavenReportException + { + List xmlReportFileList = new ArrayList(); + for ( File reportsDirectory : reportsDirectories ) + { + if ( !reportsDirectory.exists() ) + { + continue; + } + String[] xmlReportFiles = getIncludedFiles( reportsDirectory, INCLUDES, EXCLUDES ); + for ( String xmlReportFile : xmlReportFiles ) + { + File xmlReport = new File( reportsDirectory, xmlReportFile ); + xmlReportFileList.add( xmlReport ); + } + } + TestSuiteXmlParser parser = new TestSuiteXmlParser(); + for ( File aXmlReportFileList : xmlReportFileList ) + { + Collection suites; + + try + { + suites = parser.parse( aXmlReportFileList.getAbsolutePath() ); + } + catch ( ParserConfigurationException e ) + { + throw new MavenReportException( "Error setting up parser for JUnit XML report", e ); + } + catch ( SAXException e ) + { + throw new MavenReportException( "Error parsing JUnit XML report " + aXmlReportFileList, e ); + } + catch ( IOException e ) + { + throw new MavenReportException( "Error reading JUnit XML report " + aXmlReportFileList, e ); + } + + testSuites.addAll( suites ); + } + + return testSuites; + } + + protected String parseTestSuiteName( String lineString ) + { + return lineString.substring( lineString.lastIndexOf( "." ) + 1, lineString.length() ); + } + + protected String parseTestSuitePackageName( String lineString ) + { + return lineString.substring( lineString.indexOf( ":" ) + 2, lineString.lastIndexOf( "." ) ); + } + + protected String parseTestCaseName( String lineString ) + { + return lineString.substring( 0, lineString.indexOf( "(" ) ); + } + + public Map getSummary( List suites ) + { + Map totalSummary = new HashMap(); + + int totalNumberOfTests = 0; + + int totalNumberOfErrors = 0; + + int totalNumberOfFailures = 0; + + int totalNumberOfSkipped = 0; + + float totalElapsedTime = 0.0f; + + for ( ReportTestSuite suite : suites ) + { + totalNumberOfTests += suite.getNumberOfTests(); + + totalNumberOfErrors += suite.getNumberOfErrors(); + + totalNumberOfFailures += suite.getNumberOfFailures(); + + totalNumberOfSkipped += suite.getNumberOfSkipped(); + + totalElapsedTime += suite.getTimeElapsed(); + } + + String totalPercentage = + computePercentage( totalNumberOfTests, totalNumberOfErrors, totalNumberOfFailures, totalNumberOfSkipped ); + + totalSummary.put( "totalTests", Integer.toString( totalNumberOfTests ) ); + + totalSummary.put( "totalErrors", Integer.toString( totalNumberOfErrors ) ); + + totalSummary.put( "totalFailures", Integer.toString( totalNumberOfFailures ) ); + + totalSummary.put( "totalSkipped", Integer.toString( totalNumberOfSkipped ) ); + + totalSummary.put( "totalElapsedTime", numberFormat.format( totalElapsedTime ) ); + + totalSummary.put( "totalPercentage", totalPercentage ); + + return totalSummary; + } + + public void setReportsDirectory( File reportsDirectory ) + { + this.reportsDirectories = Collections.singletonList( reportsDirectory ); + } + + public final void setLocale( Locale locale ) + { + numberFormat = NumberFormat.getInstance( locale ); + } + + public NumberFormat getNumberFormat() + { + return this.numberFormat; + } + + public Map> getSuitesGroupByPackage( List testSuitesList ) + { + Map> suitePackage = new HashMap>(); + + for ( ReportTestSuite suite : testSuitesList ) + { + List suiteList = new ArrayList(); + + if ( suitePackage.get( suite.getPackageName() ) != null ) + { + suiteList = suitePackage.get( suite.getPackageName() ); + } + + suiteList.add( suite ); + + suitePackage.put( suite.getPackageName(), suiteList ); + } + + return suitePackage; + } + + public String computePercentage( int tests, int errors, int failures, int skipped ) + { + float percentage; + if ( tests == 0 ) + { + percentage = 0; + } + else + { + percentage = ( (float) ( tests - errors - failures - skipped ) / (float) tests ) * PCENT; + } + + return numberFormat.format( percentage ); + } + + public List getFailureDetails( List testSuitesList ) + { + List failureDetailList = new ArrayList(); + + for ( ReportTestSuite suite : testSuitesList ) + { + List testCaseList = suite.getTestCases(); + + if ( testCaseList != null ) + { + for ( ReportTestCase tCase : testCaseList ) + { + + if ( tCase.getFailure() != null ) + { + failureDetailList.add( tCase ); + } + } + } + } + + return failureDetailList; + } + + /** + * Returns {@code true} if the specified directory contains at least one report file. + * + * @param directory the directory + * @return {@code true} if the specified directory contains at least one report file. + */ + public static boolean hasReportFiles( File directory ) + { + return directory != null && directory.isDirectory() + && getIncludedFiles( directory, INCLUDES, EXCLUDES ).length > 0; + } + + private static String[] getIncludedFiles( File directory, String includes, String excludes ) + { + DirectoryScanner scanner = new DirectoryScanner(); + + scanner.setBasedir( directory ); + + scanner.setIncludes( StringUtils.split( includes, "," ) ); + + scanner.setExcludes( StringUtils.split( excludes, "," ) ); + + scanner.scan(); + + return scanner.getIncludedFiles(); + } +} diff --git a/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java new file mode 100644 index 0000000000..3f600b291a --- /dev/null +++ b/surefire-report-parser/src/main/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParser.java @@ -0,0 +1,310 @@ +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.text.NumberFormat; +import java.text.ParseException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.StringTokenizer; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.xml.sax.Attributes; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; +import org.xml.sax.helpers.DefaultHandler; + +/** + * + */ +public class TestSuiteXmlParser + extends DefaultHandler +{ + private ReportTestSuite defaultSuite; + + private ReportTestSuite currentSuite; + + private Map classesToSuites; + + private final NumberFormat numberFormat = NumberFormat.getInstance( Locale.ENGLISH ); + + /** + * @noinspection StringBufferField + */ + private StringBuffer currentElement; + + private ReportTestCase testCase; + + private boolean valid; + + public Collection parse( String xmlPath ) + throws ParserConfigurationException, SAXException, IOException + { + + File f = new File( xmlPath ); + + FileInputStream fileInputStream = new FileInputStream( f ); + + InputStreamReader inputStreamReader = new InputStreamReader( fileInputStream, "UTF-8" ); + + try + { + return parse( inputStreamReader ); + } + finally + { + inputStreamReader.close(); + fileInputStream.close(); + } + } + + public Collection parse( InputStreamReader stream ) + throws ParserConfigurationException, SAXException, IOException + { + SAXParserFactory factory = SAXParserFactory.newInstance(); + + SAXParser saxParser = factory.newSAXParser(); + + valid = true; + + classesToSuites = new HashMap(); + + saxParser.parse( new InputSource( stream ), this ); + + if ( currentSuite != defaultSuite ) + { // omit the defaultSuite if it's empty and there are alternatives + if ( defaultSuite.getNumberOfTests() == 0 ) + { + classesToSuites.remove( defaultSuite.getFullClassName() ); + } + } + + return classesToSuites.values(); + } + + /** + * {@inheritDoc} + */ + public void startElement( String uri, String localName, String qName, Attributes attributes ) + throws SAXException + { + if ( !valid ) + { + return; + } + try + { + if ( "testsuite".equals( qName ) ) + { + currentSuite = defaultSuite = new ReportTestSuite(); + + try + { + Number time = numberFormat.parse( attributes.getValue( "time" ) ); + + defaultSuite.setTimeElapsed( time.floatValue() ); + } + catch ( NullPointerException npe ) + { + System.err.println( "WARNING: no time attribute found on testsuite element" ); + } + + //check if group attribute is existing + if ( attributes.getValue( "group" ) != null && !"".equals( attributes.getValue( "group" ) ) ) + { + String packageName = attributes.getValue( "group" ); + String name = attributes.getValue( "name" ); + + defaultSuite.setFullClassName( packageName + "." + name ); + } + else + { + String fullClassName = attributes.getValue( "name" ); + defaultSuite.setFullClassName( fullClassName ); + } + + classesToSuites.put( defaultSuite.getFullClassName(), defaultSuite ); + } + else if ( "testcase".equals( qName ) ) + { + currentElement = new StringBuffer(); + + testCase = new ReportTestCase(); + + testCase.setName( attributes.getValue( "name" ) ); + + String fullClassName = attributes.getValue( "classname" ); + + // if the testcase declares its own classname, it may need to belong to its own suite + if ( fullClassName != null ) + { + currentSuite = classesToSuites.get( fullClassName ); + if ( currentSuite == null ) + { + currentSuite = new ReportTestSuite(); + currentSuite.setFullClassName( fullClassName ); + classesToSuites.put( fullClassName, currentSuite ); + } + } + + testCase.setFullClassName( currentSuite.getFullClassName() ); + testCase.setClassName( currentSuite.getName() ); + testCase.setFullName( currentSuite.getFullClassName() + "." + testCase.getName() ); + + String timeAsString = attributes.getValue( "time" ); + + Number time = 0; + + if ( timeAsString != null ) + { + time = numberFormat.parse( timeAsString ); + } + + testCase.setTime( time.floatValue() ); + + if ( currentSuite != defaultSuite ) + { + currentSuite.setTimeElapsed( time.floatValue() + currentSuite.getTimeElapsed() ); + } + } + else if ( "failure".equals( qName ) ) + { + testCase.addFailure( attributes.getValue( "message" ), attributes.getValue( "type" ) ); + currentSuite.setNumberOfFailures( 1 + currentSuite.getNumberOfFailures() ); + } + else if ( "error".equals( qName ) ) + { + testCase.addFailure( attributes.getValue( "message" ), attributes.getValue( "type" ) ); + currentSuite.setNumberOfErrors( 1 + currentSuite.getNumberOfErrors() ); + } + else if ( "skipped".equals( qName ) ) + { + final String message = attributes.getValue( "message" ); + testCase.addFailure( message != null ? message : "skipped", "skipped" ); + currentSuite.setNumberOfSkipped( 1 + currentSuite.getNumberOfSkipped() ); + } + else if ( "failsafe-summary".equals( qName ) ) + { + valid = false; + } + } + catch ( ParseException e ) + { + throw new SAXException( e.getMessage(), e ); + } + } + + /** + * {@inheritDoc} + */ + public void endElement( String uri, String localName, String qName ) + throws SAXException + { + if ( "testcase".equals( qName ) ) + { + currentSuite.getTestCases().add( testCase ); + } + else if ( "failure".equals( qName ) ) + { + Map failure = testCase.getFailure(); + + failure.put( "detail", parseCause( currentElement.toString() ) ); + } + else if ( "error".equals( qName ) ) + { + Map error = testCase.getFailure(); + + error.put( "detail", parseCause( currentElement.toString() ) ); + } + else if ( "time".equals( qName ) ) + { + try + { + Number time = numberFormat.parse( currentElement.toString() ); + defaultSuite.setTimeElapsed( time.floatValue() ); + } + catch ( ParseException e ) + { + throw new SAXException( e.getMessage(), e ); + } + } + // TODO extract real skipped reasons + } + + /** + * {@inheritDoc} + */ + public void characters( char[] ch, int start, int length ) + throws SAXException + { + if ( !valid ) + { + return; + } + String s = new String( ch, start, length ); + + if ( !"".equals( s.trim() ) ) + { + currentElement.append( s ); + } + } + + private List parseCause( String detail ) + { + String fullName = testCase.getFullName(); + String name = fullName.substring( fullName.lastIndexOf( "." ) + 1 ); + return parseCause( detail, name ); + } + + private List parseCause( String detail, String compareTo ) + { + StringTokenizer stringTokenizer = new StringTokenizer( detail, "\n" ); + List parsedDetail = new ArrayList( stringTokenizer.countTokens() ); + + while ( stringTokenizer.hasMoreTokens() ) + { + String lineString = stringTokenizer.nextToken().trim(); + parsedDetail.add( lineString ); + if ( lineString.contains( compareTo ) ) + { + break; + } + } + + return parsedDetail; + } + + public boolean isValid() + { + return valid; + } +} diff --git a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java new file mode 100644 index 0000000000..ecf529a77d --- /dev/null +++ b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestCaseTest.java @@ -0,0 +1,82 @@ +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import junit.framework.TestCase; + +/** + * @author Jontri + */ +public class ReportTestCaseTest + extends TestCase +{ + private ReportTestCase tCase; + + /** + * {@inheritDoc} + */ + protected void setUp() + throws Exception + { + super.setUp(); + + tCase = new ReportTestCase(); + } + + /** + * {@inheritDoc} + */ + protected void tearDown() + throws Exception + { + super.tearDown(); + + tCase = null; + } + + public void testSetName() + { + tCase.setName( "Test Case Name" ); + + assertEquals( "Test Case Name", tCase.getName() ); + } + + public void testSetTime() + { + tCase.setTime( .06f ); + + assertEquals( .06f, tCase.getTime(), 0.0 ); + } + + public void testSetFailure() + { + tCase.addFailure( "messageVal", "typeVal" ); + + assertEquals( "messageVal", tCase.getFailure().get( "message" ) ); + assertEquals( "typeVal", tCase.getFailure().get( "type" ) ); + } + + public void testSetFullName() + { + tCase.setFullName( "Test Case Full Name" ); + + assertEquals( "Test Case Full Name", tCase.getFullName() ); + } +} diff --git a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java new file mode 100644 index 0000000000..63e6eaca8f --- /dev/null +++ b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/ReportTestSuiteTest.java @@ -0,0 +1,118 @@ +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +/** + * + */ +public class ReportTestSuiteTest + extends TestCase +{ + private ReportTestSuite tSuite; + + /** + * {@inheritDoc} + */ + protected void setUp() + throws Exception + { + super.setUp(); + + tSuite = new ReportTestSuite(); + } + + /** + * {@inheritDoc} + */ + protected void tearDown() + throws Exception + { + super.tearDown(); + + tSuite = null; + } + + public void testSetTestCases() + { + ReportTestCase tCase = new ReportTestCase(); + + List tCaseList = new ArrayList(); + + tCaseList.add( tCase ); + + tSuite.setTestCases( tCaseList ); + + assertEquals( tCase, tSuite.getTestCases().get( 0 ) ); + } + + public void testSetNumberdOfErrors() + { + tSuite.setNumberOfErrors( 9 ); + + assertEquals( 9, tSuite.getNumberOfErrors() ); + } + + public void testSetNumberOfFailures() + { + tSuite.setNumberOfFailures( 10 ); + + assertEquals( 10, tSuite.getNumberOfFailures() ); + } + + public void testSetNumberOfSkipped() + { + tSuite.setNumberOfSkipped( 5 ); + + assertEquals( 5, tSuite.getNumberOfSkipped() ); + } + + public void testSetNumberOfTests() + { + tSuite.setNumberOfTests( 11 ); + + assertEquals( 11, tSuite.getNumberOfTests() ); + } + + public void testSetName() + { + tSuite.setName( "Suite Name" ); + + assertEquals( "Suite Name", tSuite.getName() ); + } + + public void testSetPackageName() + { + tSuite.setPackageName( "Suite Package Name" ); + + assertEquals( "Suite Package Name", tSuite.getPackageName() ); + } + + public void testSetTimeElapsed() + { + tSuite.setTimeElapsed( .06f ); + + assertEquals( .06f, tSuite.getTimeElapsed(), 0.0 ); + } +} diff --git a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java new file mode 100644 index 0000000000..2bd5248962 --- /dev/null +++ b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/SurefireReportParserTest.java @@ -0,0 +1,242 @@ +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.io.File; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.URLDecoder; +import java.text.NumberFormat; +import java.util.ArrayList; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import org.apache.maven.reporting.MavenReportException; + +import junit.framework.TestCase; + +/** + * + */ +public class SurefireReportParserTest + extends TestCase +{ + private SurefireReportParser report; + + /** + * {@inheritDoc} + */ + protected void setUp() + throws Exception + { + super.setUp(); + + report = new SurefireReportParser(); + + report.setLocale( Locale.ENGLISH ); + } + + /** + * {@inheritDoc} + */ + protected void tearDown() + throws Exception + { + super.tearDown(); + + report = null; + } + + public void testParseXMLReportFiles() + throws MavenReportException, UnsupportedEncodingException + { + report.setReportsDirectory( getTestDir( "/test-reports" ) ); + + List suites = report.parseXMLReportFiles(); + + assertEquals( 8, suites.size() ); + + for ( ReportTestSuite suite : suites ) + { + assertNotNull( suite.getName() + " was not correctly parsed", suite.getTestCases() ); + assertNotNull( suite.getName() ); + assertNotNull( suite.getPackageName() ); + } + } + + private File getTestDir( String path ) + throws UnsupportedEncodingException + { + URL resource = getClass().getResource( path ); + // URLDecoder.decode necessary for JDK 1.5+, where spaces are escaped to %20 + return new File( URLDecoder.decode( resource.getPath(), "UTF-8" ) ).getAbsoluteFile(); + } + + public void testParseTestSuiteName() + { + assertEquals( "CircleTest", report.parseTestSuiteName( "Battery: com.shape.CircleTest" ) ); + } + + public void testParseTestSuitePackageName() + { + assertEquals( "com.shape", report.parseTestSuitePackageName( "Battery: com.shape.CircleTest" ) ); + } + + public void testParseTestCaseName() + { + assertEquals( "testCase", report.parseTestCaseName( "testCase(com.shape.CircleTest)" ) ); + } + + public void testGetSummary() + throws Exception + { + ReportTestSuite tSuite1 = new ReportTestSuite(); + + ReportTestSuite tSuite2 = new ReportTestSuite(); + + tSuite1.setNumberOfErrors( 10 ); + + tSuite1.setNumberOfFailures( 20 ); + + tSuite1.setNumberOfSkipped( 2 ); + + tSuite1.setTimeElapsed( 1.0f ); + + tSuite1.setNumberOfTests( 100 ); + + tSuite2.setNumberOfErrors( 10 ); + + tSuite2.setNumberOfFailures( 20 ); + + tSuite2.setNumberOfSkipped( 2 ); + + tSuite2.setTimeElapsed( 1.0f ); + + tSuite2.setNumberOfTests( 100 ); + + List suiteList = new ArrayList(); + + suiteList.add( tSuite1 ); + + suiteList.add( tSuite2 ); + + Map testMap = report.getSummary( suiteList ); + + assertEquals( 20, Integer.parseInt( testMap.get( "totalErrors" ).toString() ) ); + + assertEquals( 40, Integer.parseInt( testMap.get( "totalFailures" ).toString() ) ); + + assertEquals( 200, Integer.parseInt( testMap.get( "totalTests" ).toString() ) ); + + assertEquals( 4, Integer.parseInt( testMap.get( "totalSkipped" ).toString() ) ); + + NumberFormat numberFormat = report.getNumberFormat(); + + assertEquals( 2.0f, numberFormat.parse( testMap.get( "totalElapsedTime" ).toString() ).floatValue(), 0.0f ); + + assertEquals( 68.00f, numberFormat.parse( (String) testMap.get( "totalPercentage" ) ).floatValue(), 0 ); + } + + public void testGetSuitesGroupByPackage() + { + ReportTestSuite tSuite1 = new ReportTestSuite(); + + ReportTestSuite tSuite2 = new ReportTestSuite(); + + ReportTestSuite tSuite3 = new ReportTestSuite(); + + tSuite1.setPackageName( "Package1" ); + + tSuite2.setPackageName( "Package1" ); + + tSuite3.setPackageName( "Package2" ); + + List suiteList = new ArrayList(); + + suiteList.add( tSuite1 ); + + suiteList.add( tSuite2 ); + + suiteList.add( tSuite3 ); + + Map> groupMap = report.getSuitesGroupByPackage( suiteList ); + + assertEquals( 2, groupMap.size() ); + + assertEquals( tSuite1, groupMap.get( "Package1" ).get( 0 ) ); + + assertEquals( tSuite2, groupMap.get( "Package1" ).get( 1 ) ); + + assertEquals( tSuite3, groupMap.get( "Package2" ).get( 0 ) ); + } + + public void testComputePercentage() + throws Exception + { + NumberFormat numberFormat = report.getNumberFormat(); + + assertEquals( 70.00f, numberFormat.parse( report.computePercentage( 100, 20, 10, 0 ) ).floatValue(), 0 ); + } + + public void testGetFailureDetails() + { + ReportTestSuite tSuite1 = new ReportTestSuite(); + + ReportTestSuite tSuite2 = new ReportTestSuite(); + + ReportTestCase tCase1 = new ReportTestCase(); + + ReportTestCase tCase2 = new ReportTestCase(); + + ReportTestCase tCase3 = new ReportTestCase(); + + tCase1.addFailure( null, null ); + + tCase3.addFailure( null, null ); + + List tCaseList = new ArrayList(); + + List tCaseList2 = new ArrayList(); + + tCaseList.add( tCase1 ); + + tCaseList.add( tCase2 ); + + tCaseList2.add( tCase3 ); + + tSuite1.setTestCases( tCaseList ); + + tSuite2.setTestCases( tCaseList2 ); + + List suiteList = new ArrayList(); + + suiteList.add( tSuite1 ); + + suiteList.add( tSuite2 ); + + List failList = report.getFailureDetails( suiteList ); + + assertEquals( 2, failList.size() ); + + assertEquals( tCase1, failList.get( 0 ) ); + + assertEquals( tCase3, failList.get( 1 ) ); + } +} diff --git a/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java new file mode 100644 index 0000000000..beaf1b2dcc --- /dev/null +++ b/surefire-report-parser/src/test/java/org/apache/maven/plugins/surefire/report/TestSuiteXmlParserTest.java @@ -0,0 +1,136 @@ +package org.apache.maven.plugins.surefire.report; + +/* + * 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. + */ + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.Collection; + +import javax.xml.parsers.ParserConfigurationException; + +import junit.framework.TestCase; +import org.xml.sax.SAXException; + +/** + * @author Kristian Rosenvold + */ +public class TestSuiteXmlParserTest + extends TestCase +{ + public void testParse() + throws Exception + { + TestSuiteXmlParser testSuiteXmlParser = new TestSuiteXmlParser(); + String xml = "\n" + + "\n" + + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " junit.framework.AssertionFailedError: \n" + + + "\tat junit.framework.Assert.fail(Assert.java:47)\n" + + "\tat wellFormedXmlFailures.TestSurefire3.testU0000(TestSurefire3.java:40)\n" + + "\n" + + " \n" + + " \n" + + " junit.framework.AssertionFailedError: >\n" + + + "\tat junit.framework.Assert.fail(Assert.java:47)\n" + + "\tat wellFormedXmlFailures.TestSurefire3.testGreater(TestSurefire3.java:35)\n" + + "\n" + + " \n" + + " \n" + + " junit.framework.AssertionFailedError: \"\n" + + + "\tat junit.framework.Assert.fail(Assert.java:47)\n" + + "\tat wellFormedXmlFailures.TestSurefire3.testQuote(TestSurefire3.java:25)\n" + + "\n" + + " \n" + + ""; + InputStream byteArrayIs = new ByteArrayInputStream( xml.getBytes() ); + Collection parse = testSuiteXmlParser.parse( new InputStreamReader(byteArrayIs, "UTF-8") ); + } + + public void testParser() + throws IOException, SAXException, ParserConfigurationException + { + TestSuiteXmlParser parser = new TestSuiteXmlParser(); + + Collection oldResult = parser.parse( + "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" ); + + assertNotNull( oldResult ); + + assertEquals( 1, oldResult.size() ); + ReportTestSuite next = oldResult.iterator().next(); + assertEquals( 2, next.getNumberOfTests() ); + + + } + + public void noTestParserBadFile() // Determine problem with xml file. + throws IOException, SAXException, ParserConfigurationException + { + TestSuiteXmlParser parser = new TestSuiteXmlParser(); + + File file = new File( "../surefire-integration-tests/target/UmlautDirIT/junit-pathWith\u00DCmlaut/target/surefire-reports/TEST-umlautTest.BasicTest.xml" ); + assertTrue(file.exists()); + Collection oldResult = parser.parse( + "..\\surefire-integration-tests\\target\\UmlautDirIT\\junit-pathWith\u00DCmlaut\\target\\surefire-reports\\TEST-umlautTest.BasicTest.xml" ); + + assertNotNull( oldResult ); + + assertEquals( 1, oldResult.size() ); + ReportTestSuite next = oldResult.iterator().next(); + assertEquals( 2, next.getNumberOfTests() ); + + + } + + public void testParserHitsFailsafeSummary() + throws IOException, SAXException, ParserConfigurationException + { + TestSuiteXmlParser parser = new TestSuiteXmlParser(); + + parser.parse( "src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml" ); + + assertFalse( parser.isValid() ); + + parser.parse( + "src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml" ); + + assertTrue( parser.isValid() ); + } + + +} diff --git a/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml b/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml new file mode 100644 index 0000000000..09c9c6dade --- /dev/null +++ b/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/TEST-org.apache.maven.surefire.test.FailingTest.xml @@ -0,0 +1,154 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + java.lang.AssertionError: +Expected: "wrong" + got: "value" + + at org.junit.Assert.assertThat(Assert.java:778) + at org.junit.Assert.assertThat(Assert.java:736) + at org.apache.maven.surefire.test.FailingTest.defaultTestValueIs_Value(FailingTest.java:23) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:601) + at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) + at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) + at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) + at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) + at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) + at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48) + at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) + at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) + at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) + at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) + at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) + at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) + at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) + at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) + at org.junit.runners.ParentRunner.run(ParentRunner.java:236) + at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:262) + at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:151) + at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:122) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:601) + at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) + at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) + at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) + at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:128) + at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:88) + + + + java.lang.AssertionError: +Expected: "bar" + got: "foo" + + at org.junit.Assert.assertThat(Assert.java:778) + at org.junit.Assert.assertThat(Assert.java:736) + at org.apache.maven.surefire.test.FailingTest.setTestAndRetrieveValue(FailingTest.java:34) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:601) + at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44) + at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) + at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41) + at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) + at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31) + at org.junit.rules.TestWatchman$1.evaluate(TestWatchman.java:48) + at org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79) + at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71) + at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49) + at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193) + at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52) + at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191) + at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42) + at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184) + at org.junit.runners.ParentRunner.run(ParentRunner.java:236) + at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:262) + at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:151) + at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:122) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) + at java.lang.reflect.Method.invoke(Method.java:601) + at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189) + at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165) + at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85) + at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:128) + at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:88) + + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml b/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml new file mode 100644 index 0000000000..6839aa98c6 --- /dev/null +++ b/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/failsafe-summary-old.xml @@ -0,0 +1,8 @@ + + + 1 + 0 + 1 + 0 + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml b/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml new file mode 100644 index 0000000000..1bc82d9031 --- /dev/null +++ b/surefire-report-parser/src/test/resources/fixture/testsuitexmlparser/failsafe-summary.xml @@ -0,0 +1,8 @@ + + + 4 + 0 + 2 + 0 + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/test-reports/TEST-AntUnit.xml b/surefire-report-parser/src/test/resources/test-reports/TEST-AntUnit.xml new file mode 100644 index 0000000000..71e5342e1c --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/TEST-AntUnit.xml @@ -0,0 +1,11 @@ + + + + + + 1 + 0 + 0 + + diff --git a/surefire-report-parser/src/test/resources/test-reports/TEST-NoPackageTest.xml b/surefire-report-parser/src/test/resources/test-reports/TEST-NoPackageTest.xml new file mode 100644 index 0000000000..4c0f831ab4 --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/TEST-NoPackageTest.xml @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + junit.framework.AssertionFailedError: " + at junit.framework.Assert.fail(Assert.java:47) + at NoPackageTest.testQuote(NoPackageTest.java:23) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.apache.maven.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:242) + at org.apache.maven.surefire.battery.JUnitBattery.execute(JUnitBattery.java:216) + at org.apache.maven.surefire.Surefire.executeBattery(Surefire.java:215) + at org.apache.maven.surefire.Surefire.run(Surefire.java:163) + at org.apache.maven.surefire.Surefire.run(Surefire.java:87) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.apache.maven.surefire.SurefireBooter.runTestsInProcess(SurefireBooter.java:300) + at org.apache.maven.surefire.SurefireBooter.run(SurefireBooter.java:216) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:369) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:415) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecycle(DefaultLifecycleExecutor.java:867) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(DefaultLifecycleExecutor.java:739) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:510) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:493) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:463) + at + org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:274) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140) + at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:249) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) + + + + junit.framework.AssertionFailedError: < + at junit.framework.Assert.fail(Assert.java:47) + at NoPackageTest.testLower(NoPackageTest.java:28) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.apache.maven.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:242) + at org.apache.maven.surefire.battery.JUnitBattery.execute(JUnitBattery.java:216) + at org.apache.maven.surefire.Surefire.executeBattery(Surefire.java:215) + at org.apache.maven.surefire.Surefire.run(Surefire.java:163) + at org.apache.maven.surefire.Surefire.run(Surefire.java:87) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.apache.maven.surefire.SurefireBooter.runTestsInProcess(SurefireBooter.java:300) + at org.apache.maven.surefire.SurefireBooter.run(SurefireBooter.java:216) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:369) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:415) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecycle(DefaultLifecycleExecutor.java:867) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(DefaultLifecycleExecutor.java:739) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:510) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:493) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:463) + at + org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:274) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140) + at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:249) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) + + + + junit.framework.AssertionFailedError: > + at junit.framework.Assert.fail(Assert.java:47) + at NoPackageTest.testGreater(NoPackageTest.java:33) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.apache.maven.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:242) + at org.apache.maven.surefire.battery.JUnitBattery.execute(JUnitBattery.java:216) + at org.apache.maven.surefire.Surefire.executeBattery(Surefire.java:215) + at org.apache.maven.surefire.Surefire.run(Surefire.java:163) + at org.apache.maven.surefire.Surefire.run(Surefire.java:87) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.apache.maven.surefire.SurefireBooter.runTestsInProcess(SurefireBooter.java:300) + at org.apache.maven.surefire.SurefireBooter.run(SurefireBooter.java:216) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:369) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:415) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecycle(DefaultLifecycleExecutor.java:867) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(DefaultLifecycleExecutor.java:739) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:510) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:493) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:463) + at + org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:274) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:140) + at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:322) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:115) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:249) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) + + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml b/surefire-report-parser/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml new file mode 100644 index 0000000000..a36a19a605 --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/TEST-NoTimeTestCaseTest.xml @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml b/surefire-report-parser/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml new file mode 100644 index 0000000000..31f7ea56f8 --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/TEST-classWithNoTests.NoMethodsTestCase.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml b/surefire-report-parser/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml new file mode 100644 index 0000000000..1ce1d3dd13 --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/TEST-com.shape.CircleTest.xml @@ -0,0 +1,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + junit.framework.AssertionFailedError: expected:<20> but was:<10> + at junit.framework.Assert.fail(Assert.java:47) + at junit.framework.Assert.failNotEquals(Assert.java:282) + at junit.framework.Assert.assertEquals(Assert.java:64) + at junit.framework.Assert.assertEquals(Assert.java:201) + at junit.framework.Assert.assertEquals(Assert.java:207) + at com.shape.CircleTest.testRadius(CircleTest.java:34) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:246) + at org.codehaus.surefire.battery.JUnitBattery.execute(JUnitBattery.java:220) + at org.codehaus.surefire.Surefire.executeBattery(Surefire.java:203) + at org.codehaus.surefire.Surefire.run(Surefire.java:152) + at org.codehaus.surefire.Surefire.run(Surefire.java:76) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.SurefireBooter.run(SurefireBooter.java:104) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:241) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:357) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:479) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:452) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:438) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:131) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:186) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:316) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) + + [OUT] : Getting the diameter + + [ERR] : Getting the Circumference + + + + java.lang.ArithmeticException: / by zero + at com.shape.CircleTest.testProperties(CircleTest.java:44) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:246) + at org.codehaus.surefire.battery.JUnitBattery.execute(JUnitBattery.java:220) + at org.codehaus.surefire.Surefire.executeBattery(Surefire.java:203) + at org.codehaus.surefire.Surefire.run(Surefire.java:152) + at org.codehaus.surefire.Surefire.run(Surefire.java:76) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.SurefireBooter.run(SurefireBooter.java:104) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:241) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:357) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:479) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:452) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:438) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:131) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:186) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:316) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) + + [OUT] : Getting the diameter + + [ERR] : Getting the Circumference + + + + + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/test-reports/TEST-com.shape.PointTest.xml b/surefire-report-parser/src/test/resources/test-reports/TEST-com.shape.PointTest.xml new file mode 100644 index 0000000000..7dda584c02 --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/TEST-com.shape.PointTest.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + junit.framework.AssertionFailedError: expected:<0> but was:<1> + at junit.framework.Assert.fail(Assert.java:47) + at junit.framework.Assert.failNotEquals(Assert.java:282) + at junit.framework.Assert.assertEquals(Assert.java:64) + at junit.framework.Assert.assertEquals(Assert.java:201) + at junit.framework.Assert.assertEquals(Assert.java:207) + at com.shape.PointTest.testXY(PointTest.java:28) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.battery.JUnitBattery.executeJUnit(JUnitBattery.java:246) + at org.codehaus.surefire.battery.JUnitBattery.execute(JUnitBattery.java:220) + at org.codehaus.surefire.Surefire.executeBattery(Surefire.java:203) + at org.codehaus.surefire.Surefire.run(Surefire.java:152) + at org.codehaus.surefire.Surefire.run(Surefire.java:76) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.SurefireBooter.run(SurefireBooter.java:104) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:241) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:357) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:479) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:452) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:438) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:273) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:131) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:186) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:316) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) + + + + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml b/surefire-report-parser/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml new file mode 100644 index 0000000000..cd94387a6a --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/TEST-junit.twoTestCaseSuite.WrapperTestSuite.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/surefire-report-parser/src/test/resources/test-reports/com.shape.CircleTest.txt b/surefire-report-parser/src/test/resources/test-reports/com.shape.CircleTest.txt new file mode 100644 index 0000000000..5030dee18c --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/com.shape.CircleTest.txt @@ -0,0 +1,122 @@ +------------------------------------------------------------------------------- +Battery: com.shape.CircleTest +------------------------------------------------------------------------------- +testX(com.shape.CircleTest) +testY(com.shape.CircleTest) +testXY(com.shape.CircleTest) +testRadius(com.shape.CircleTest) + +[ stdout ] --------------------------------------------------------------- + + +[ stderr ] --------------------------------------------------------------- + + +[ stacktrace ] ----------------------------------------------------------- + +junit.framework.AssertionFailedError: expected:<20> but was:<10> + at junit.framework.Assert.fail(Assert.java:47) + at junit.framework.Assert.failNotEquals(Assert.java:282) + at junit.framework.Assert.assertEquals(Assert.java:64) + at junit.framework.Assert.assertEquals(Assert.java:201) + at junit.framework.Assert.assertEquals(Assert.java:207) + at com.shape.CircleTest.testRadius(CircleTest.java:34) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.battery.JUnitBattery.execute(JUnitBattery.java:190) + at org.codehaus.surefire.Surefire.executeBattery(Surefire.java:155) + at org.codehaus.surefire.Surefire.run(Surefire.java:105) + at org.codehaus.surefire.Surefire.run(Surefire.java:59) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.SurefireBooter.run(SurefireBooter.java:83) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:218) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:361) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:472) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:445) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:431) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:268) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:127) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:186) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:292) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) +testProperties(com.shape.CircleTest) + +[ stdout ] --------------------------------------------------------------- + + +[ stderr ] --------------------------------------------------------------- + + +[ stacktrace ] ----------------------------------------------------------- + +java.lang.ArithmeticException: / by zero + at com.shape.CircleTest.testProperties(CircleTest.java:44) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.battery.JUnitBattery.execute(JUnitBattery.java:190) + at org.codehaus.surefire.Surefire.executeBattery(Surefire.java:155) + at org.codehaus.surefire.Surefire.run(Surefire.java:105) + at org.codehaus.surefire.Surefire.run(Surefire.java:59) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.SurefireBooter.run(SurefireBooter.java:83) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:218) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:361) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:472) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:445) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:431) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:268) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:127) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:186) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:292) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) +testPI(com.shape.CircleTest) +testCircumference(com.shape.CircleTest) +testDiameter(com.shape.CircleTest) diff --git a/surefire-report-parser/src/test/resources/test-reports/com.shapeclone.CircleTest.txt b/surefire-report-parser/src/test/resources/test-reports/com.shapeclone.CircleTest.txt new file mode 100644 index 0000000000..90e323991c --- /dev/null +++ b/surefire-report-parser/src/test/resources/test-reports/com.shapeclone.CircleTest.txt @@ -0,0 +1,122 @@ +------------------------------------------------------------------------------- +Battery: com.shapeclone.CircleTest +------------------------------------------------------------------------------- +testX(com.shapeclone.CircleTest) +testY(com.shapeclone.CircleTest) +testXY(com.shapeclone.CircleTest) +testRadius(com.shapeclone.CircleTest) + +[ stdout ] --------------------------------------------------------------- + + +[ stderr ] --------------------------------------------------------------- + + +[ stacktrace ] ----------------------------------------------------------- + +junit.framework.AssertionFailedError: expected:<20> but was:<10> + at junit.framework.Assert.fail(Assert.java:47) + at junit.framework.Assert.failNotEquals(Assert.java:282) + at junit.framework.Assert.assertEquals(Assert.java:64) + at junit.framework.Assert.assertEquals(Assert.java:201) + at junit.framework.Assert.assertEquals(Assert.java:207) + at com.shapeclone.CircleTest.testRadius(CircleTest.java:34) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.battery.JUnitBattery.execute(JUnitBattery.java:190) + at org.codehaus.surefire.Surefire.executeBattery(Surefire.java:155) + at org.codehaus.surefire.Surefire.run(Surefire.java:105) + at org.codehaus.surefire.Surefire.run(Surefire.java:59) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.SurefireBooter.run(SurefireBooter.java:83) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:218) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:361) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:472) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:445) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:431) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:268) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:127) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:186) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:292) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) +testProperties(com.shapeclone.CircleTest) + +[ stdout ] --------------------------------------------------------------- + + +[ stderr ] --------------------------------------------------------------- + + +[ stacktrace ] ----------------------------------------------------------- + +java.lang.ArithmeticException: / by zero + at com.shapeclone.CircleTest.testProperties(CircleTest.java:44) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at junit.framework.TestCase.runTest(TestCase.java:154) + at junit.framework.TestCase.runBare(TestCase.java:127) + at junit.framework.TestResult$1.protect(TestResult.java:106) + at junit.framework.TestResult.runProtected(TestResult.java:124) + at junit.framework.TestResult.run(TestResult.java:109) + at junit.framework.TestCase.run(TestCase.java:118) + at junit.framework.TestSuite.runTest(TestSuite.java:208) + at junit.framework.TestSuite.run(TestSuite.java:203) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.battery.JUnitBattery.execute(JUnitBattery.java:190) + at org.codehaus.surefire.Surefire.executeBattery(Surefire.java:155) + at org.codehaus.surefire.Surefire.run(Surefire.java:105) + at org.codehaus.surefire.Surefire.run(Surefire.java:59) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.surefire.SurefireBooter.run(SurefireBooter.java:83) + at org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:218) + at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:361) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:472) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:445) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:431) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:268) + at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:127) + at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:186) + at org.apache.maven.cli.MavenCli.main(MavenCli.java:292) + at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) + at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) + at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) + at java.lang.reflect.Method.invoke(Method.java:585) + at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) + at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) + at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) + at org.codehaus.classworlds.Launcher.main(Launcher.java:375) +testPI(com.shapeclone.CircleTest) +testCircumference(com.shapeclone.CircleTest) +testDiameter(com.shapeclone.CircleTest) From 350dd6fd745f82dcdf071ff910665d8b388dfe7b Mon Sep 17 00:00:00 2001 From: Kristian Rosenvold Date: Wed, 9 Jan 2013 18:20:50 +0100 Subject: [PATCH 03/14] o Made sleep timeout configurable in forkModeIt for testing SUREFIRE-946 --- .../resources/fork-mode/src/test/java/forkMode/Test1.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java b/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java index ca5af552be..8dd33075ed 100644 --- a/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java +++ b/surefire-integration-tests/src/test/resources/fork-mode/src/test/java/forkMode/Test1.java @@ -17,9 +17,9 @@ public class Test1 public void test1() throws IOException, InterruptedException { - Thread.sleep( 750 ); + int sleepLength = Integer.valueOf( System.getProperty( "sleepLength", "750" )); + Thread.sleep(sleepLength); dumpPidFile( this ); - } public static void dumpPidFile( TestCase test ) From e54dbd810f62fe723800f11279b881bff244b707 Mon Sep 17 00:00:00 2001 From: agudian Date: Sat, 5 Jan 2013 21:13:12 +0100 Subject: [PATCH 04/14] [SUREFIRE-946] prevent hanging main process if forked process was killed (softly) Fixed with extended IT --- .../surefire/booterclient/ForkStarter.java | 140 ++++++++++++++---- .../TestProvidingInputStream.java | 29 ++-- .../booterclient/output/ForkClient.java | 22 ++- .../surefire/booter/ForkingRunListener.java | 3 + .../maven/surefire/booter/ForkedBooter.java | 74 +++++++-- .../maven/surefire/its/CrashDetectionIT.java | 7 +- 6 files changed, 215 insertions(+), 60 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java index 620dfd490f..892c6a9bc6 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java @@ -21,6 +21,8 @@ import java.io.File; import java.io.IOException; +import java.io.InputStream; +import java.security.AccessControlException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -36,6 +38,7 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; + import org.apache.maven.plugin.surefire.AbstractSurefireMojo; import org.apache.maven.plugin.surefire.CommonReflector; import org.apache.maven.plugin.surefire.StartupReportConfiguration; @@ -63,14 +66,13 @@ import org.apache.maven.surefire.suite.RunResult; import org.apache.maven.surefire.util.DefaultScanResult; - /** * Starts the fork or runs in-process. *

* Lives only on the plugin-side (not present in remote vms) *

* Knows how to fork new vms and also how to delegate non-forking invocation to SurefireStarter directly - * + * * @author Jason van Zyl * @author Emmanuel Venisse * @author Brett Porter @@ -80,6 +82,36 @@ */ public class ForkStarter { + /** + * Closes an InputStream + */ + private final class InputStreamCloser + extends Thread + { + private InputStream testProvidingInputStream; + + public InputStreamCloser( InputStream testProvidingInputStream ) + { + this.testProvidingInputStream = testProvidingInputStream; + } + + @Override + public void run() + { + if ( testProvidingInputStream != null ) + { + try + { + testProvidingInputStream.close(); + } + catch ( IOException e ) + { + // ignore + } + } + } + } + private final int forkedProcessTimeoutInSeconds; private final ProviderConfiguration providerConfiguration; @@ -105,7 +137,6 @@ protected Integer initialValue() } }; - public ForkStarter( ProviderConfiguration providerConfiguration, StartupConfiguration startupConfiguration, ForkConfiguration forkConfiguration, int forkedProcessTimeoutInSeconds, StartupReportConfiguration startupReportConfiguration ) @@ -167,8 +198,9 @@ private RunResult runSuitesForkOncePerThread( final SurefireProperties effective { ArrayList> results = new ArrayList>( forkCount ); - ExecutorService executorService = new ThreadPoolExecutor( forkCount, forkCount, 60, TimeUnit.SECONDS, - new ArrayBlockingQueue( forkCount ) ); + ExecutorService executorService = + new ThreadPoolExecutor( forkCount, forkCount, 60, TimeUnit.SECONDS, + new ArrayBlockingQueue( forkCount ) ); try { @@ -196,16 +228,15 @@ private RunResult runSuitesForkOncePerThread( final SurefireProperties effective public RunResult call() throws Exception { - TestProvidingInputStream testProvidingInputStream = - new TestProvidingInputStream( messageQueue ); + TestProvidingInputStream testProvidingInputStream = new TestProvidingInputStream( messageQueue ); ForkClient forkClient = - new ForkClient( defaultReporterFactory, startupReportConfiguration.getTestVmSystemProperties(), + new ForkClient( defaultReporterFactory, + startupReportConfiguration.getTestVmSystemProperties(), testProvidingInputStream ); return fork( null, new PropertiesWrapper( providerConfiguration.getProviderProperties() ), - forkClient, effectiveSystemProperties, finalThreadNumber, - testProvidingInputStream ); + forkClient, effectiveSystemProperties, finalThreadNumber, testProvidingInputStream ); } }; @@ -270,12 +301,13 @@ public RunResult call() if ( thisThreadsThreadNumber > forkCount ) { // this would be a bug in the ThreadPoolExecutor - throw new IllegalStateException( - "More threads than " + forkCount + " have been created by the ThreadPoolExecutor." ); + throw new IllegalStateException( "More threads than " + forkCount + + " have been created by the ThreadPoolExecutor." ); } - ForkClient forkClient = new ForkClient( defaultReporterFactory, - startupReportConfiguration.getTestVmSystemProperties() ); + ForkClient forkClient = + new ForkClient( defaultReporterFactory, + startupReportConfiguration.getTestVmSystemProperties() ); return fork( testSet, new PropertiesWrapper( providerConfiguration.getProviderProperties() ), forkClient, effectiveSystemProperties, thisThreadsThreadNumber, null ); } @@ -353,8 +385,9 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC AbstractSurefireMojo.createCopyAndReplaceThreadNumPlaceholder( effectiveSystemProperties, threadNumber ); systPropsFile = - SystemPropertyManager.writePropertiesFile( filteredProperties, forkConfiguration.getTempDirectory(), - "surefire_" + systemPropertiesFileCounter++, + SystemPropertyManager.writePropertiesFile( filteredProperties, + forkConfiguration.getTempDirectory(), "surefire_" + + systemPropertiesFileCounter++, forkConfiguration.isDebug() ); } } @@ -365,22 +398,31 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC final Classpath bootClasspathConfiguration = forkConfiguration.getBootClasspath(); - final Classpath additionlClassPathUrls = startupConfiguration.useSystemClassLoader() - ? startupConfiguration.getClasspathConfiguration().getTestClasspath() - : null; + final Classpath additionlClassPathUrls = + startupConfiguration.useSystemClassLoader() ? startupConfiguration.getClasspathConfiguration().getTestClasspath() + : null; // Surefire-booter + all test classes if "useSystemClassloader" // Surefire-booter if !useSystemClassLoader Classpath bootClasspath = Classpath.join( bootClasspathConfiguration, additionlClassPathUrls ); - @SuppressWarnings( "unchecked" ) OutputStreamFlushableCommandline cli = + @SuppressWarnings( "unchecked" ) + OutputStreamFlushableCommandline cli = forkConfiguration.createCommandLine( bootClasspath.getClassPath(), startupConfiguration.getClassLoaderConfiguration(), startupConfiguration.isShadefire(), threadNumber ); + final InputStreamCloser inputStreamCloserHook; if ( testProvidingInputStream != null ) { testProvidingInputStream.setFlushReceiverProvider( cli ); + + inputStreamCloserHook = new InputStreamCloser( testProvidingInputStream ); + addShutDownHook( inputStreamCloserHook ); + } + else + { + inputStreamCloserHook = null; } cli.createArg().setFile( surefireProperties ); @@ -410,7 +452,6 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC throw new SurefireBooterForkException( "Error occurred in starting fork, check output in log" ); } - } catch ( CommandLineTimeOutException e ) { @@ -424,6 +465,11 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC finally { threadedStreamConsumer.close(); + if ( inputStreamCloserHook != null ) + { + removeShutdownHook( inputStreamCloserHook ); + inputStreamCloserHook.run(); + } if ( runResult == null ) { runResult = defaultReporterFactory.getGlobalRunStatistics().getRunResult(); @@ -433,16 +479,16 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC StackTraceWriter errorInFork = forkClient.getErrorInFork(); if ( errorInFork != null ) { - //noinspection ThrowFromFinallyBlock - throw new RuntimeException( - "There was an error in the forked process\n" + errorInFork.writeTraceToString() ); + // noinspection ThrowFromFinallyBlock + throw new RuntimeException( "There was an error in the forked process\n" + + errorInFork.writeTraceToString() ); } if ( !forkClient.isSaidGoodBye() ) { - //noinspection ThrowFromFinallyBlock + // noinspection ThrowFromFinallyBlock throw new RuntimeException( - "The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?" + - "\nCommand was" + cli.toString() ); + "The forked VM terminated without saying properly goodbye. VM crash or System.exit called ?" + + "\nCommand was" + cli.toString() ); } } @@ -460,15 +506,14 @@ private Iterator> getSuitesIterator() { final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration(); ClassLoader testsClassLoader = classpathConfiguration.createTestClassLoader( false ); - ClassLoader surefireClassLoader = - classpathConfiguration.createInprocSurefireClassLoader( testsClassLoader ); + ClassLoader surefireClassLoader = classpathConfiguration.createInprocSurefireClassLoader( testsClassLoader ); CommonReflector commonReflector = new CommonReflector( surefireClassLoader ); Object reporterFactory = commonReflector.createReportingReporterFactory( startupReportConfiguration ); final ProviderFactory providerFactory = - new ProviderFactory( startupConfiguration, providerConfiguration, surefireClassLoader, testsClassLoader, - reporterFactory ); + new ProviderFactory( startupConfiguration, providerConfiguration, surefireClassLoader, + testsClassLoader, reporterFactory ); SurefireProvider surefireProvider = providerFactory.createProvider( false ); return surefireProvider.getSuites(); } @@ -478,4 +523,37 @@ private Iterator> getSuitesIterator() } } + // TODO use ShutdownHookUtils, once it's public again + public static void addShutDownHook( Thread hook ) + { + try + { + Runtime.getRuntime().addShutdownHook( hook ); + } + catch ( IllegalStateException ignore ) + { + // ignore + } + catch ( AccessControlException ignore ) + { + // ignore + } + } + + // TODO use ShutdownHookUtils, once it's public again + public static void removeShutdownHook( Thread hook ) + { + try + { + Runtime.getRuntime().removeShutdownHook( hook ); + } + catch ( IllegalStateException ignore ) + { + // ignore + } + catch ( AccessControlException ignore ) + { + // ignore + } + } } diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java index 1e63234537..df14d3594f 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java @@ -25,16 +25,14 @@ import java.util.concurrent.Semaphore; /** - * An {@link InputStream} that, when read, provides test class names out of - * a queue. + * An {@link InputStream} that, when read, provides test class names out of a queue. *

- * The Stream provides only one test at a time, but only after {@link #provideNewTest()} - * has been invoked. + * The Stream provides only one test at a time, but only after {@link #provideNewTest()} has been invoked. *

- * After providing each test class name, followed by a newline character, a flush is - * performed on the {@link FlushReceiver} provided by the {@link FlushReceiverProvider} - * that can be set using {@link #setFlushReceiverProvider(FlushReceiverProvider)}. - * + * After providing each test class name, followed by a newline character, a flush is performed on the + * {@link FlushReceiver} provided by the {@link FlushReceiverProvider} that can be set using + * {@link #setFlushReceiverProvider(FlushReceiverProvider)}. + * * @author Andreas Gudian */ public class TestProvidingInputStream @@ -50,9 +48,11 @@ public class TestProvidingInputStream private FlushReceiverProvider flushReceiverProvider; + private boolean closed = false; + /** * C'tor - * + * * @param testItemQueue source of the tests to be read from this stream */ public TestProvidingInputStream( Queue testItemQueue ) @@ -81,6 +81,11 @@ public synchronized int read() semaphore.acquireUninterruptibly(); + if ( closed ) + { + return -1; + } + String currentElement = testItemQueue.poll(); if ( null != currentElement ) { @@ -111,4 +116,10 @@ public void provideNewTest() { semaphore.release(); } + + public void close() + { + closed = true; + semaphore.release(); + } } \ No newline at end of file diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java index 9fde697c57..932f148cc0 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java @@ -44,7 +44,7 @@ /** * Knows how to reconstruct *all* the state transmitted over stdout by the forked process. - * + * * @author Kristian Rosenvold */ public class ForkClient @@ -156,7 +156,11 @@ public void consumeLine( String s ) case ForkingRunListener.BOOTERCODE_ERROR: errorInFork = deserializeStackStraceWriter( new StringTokenizer( remaining, "," ) ); break; + case ForkingRunListener.BOOTERCODE_CRASH: + closeTestProvidingInputStream(); + break; case ForkingRunListener.BOOTERCODE_BYE: + closeTestProvidingInputStream(); saidGoodBye = true; break; default: @@ -173,6 +177,14 @@ public void consumeLine( String s ) } } + private void closeTestProvidingInputStream() + { + if ( null != testProvidingInputStream ) + { + testProvidingInputStream.close(); + } + } + public void consumeMultiLineContent( String s ) throws IOException { @@ -217,9 +229,9 @@ private StackTraceWriter deserializeStackStraceWriter( StringTokenizer tokens ) String stackTraceMessage = nullableCsv( tokens.nextToken() ); String smartStackTrace = nullableCsv( tokens.nextToken() ); String stackTrace = tokens.hasMoreTokens() ? nullableCsv( tokens.nextToken() ) : null; - stackTraceWriter = stackTrace != null - ? new DeserializedStacktraceWriter( stackTraceMessage, smartStackTrace, stackTrace ) - : null; + stackTraceWriter = + stackTrace != null ? new DeserializedStacktraceWriter( stackTraceMessage, smartStackTrace, stackTrace ) + : null; return stackTraceWriter; } @@ -242,7 +254,7 @@ private String unescape( String source ) /** * Used when getting reporters on the plugin side of a fork. - * + * * @param channelNumber The logical channel number * @return A mock provider reporter */ diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java index 9974c5ccd1..6ec7223383 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java @@ -69,6 +69,8 @@ public class ForkingRunListener public static final byte BOOTERCODE_TEST_SKIPPED = (byte) '9'; + public static final byte BOOTERCODE_CRASH = (byte) 'C'; + public static final byte BOOTERCODE_TEST_ASSUMPTIONFAILURE = (byte) 'G'; public static final byte BOOTERCODE_CONSOLE = (byte) 'H'; @@ -81,6 +83,7 @@ public class ForkingRunListener public static final byte BOOTERCODE_BYE = (byte) 'Z'; + private final PrintStream target; private final Integer testSetChannelId; diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java index c06297aeef..4b04a99e6f 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileInputStream; +import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; @@ -35,7 +36,7 @@ *

* Deals with deserialization of the booter wire-level protocol *

- * + * * @author Jason van Zyl * @author Emmanuel Venisse * @author Kristian Rosenvold @@ -43,10 +44,58 @@ public class ForkedBooter { + private final static long SYSTEM_EXIT_TIMEOUT = 30 * 1000; + + private final static String GOODBYE_MESSAGE = ( (char) ForkingRunListener.BOOTERCODE_BYE ) + ",0,BYE!"; + + private final static String CRASH_MESSAGE = ( (char) ForkingRunListener.BOOTERCODE_CRASH ) + ",0,F!"; + + private static boolean sayGoodbye = false; + + private static final class GoodbyeReporterAndStdStreamCloser + implements Runnable + { + + private InputStream originalIn; + + private PrintStream originalOut; + + public GoodbyeReporterAndStdStreamCloser() + { + this.originalIn = System.in; + this.originalOut = System.out; + } + + public void run() + { + try + { + originalIn.close(); + } + catch ( IOException e ) + { + } + + if ( sayGoodbye ) + { + originalOut.println( GOODBYE_MESSAGE ); + } + else + { + originalOut.println( CRASH_MESSAGE ); + } + + originalOut.flush(); + originalOut.close(); + } + } + /** * This method is invoked when Surefire is forked - this method parses and organizes the arguments passed to it and - * then calls the Surefire class' run method.

The system exit code will be 1 if an exception is thrown. - * + * then calls the Surefire class' run method. + *

+ * The system exit code will be 1 if an exception is thrown. + * * @param args Commandline arguments * @throws Throwable Upon throwables */ @@ -54,6 +103,9 @@ public static void main( String[] args ) throws Throwable { final PrintStream originalOut = System.out; + + Runtime.getRuntime().addShutdownHook( new Thread( new GoodbyeReporterAndStdStreamCloser() ) ); + try { if ( args.length > 1 ) @@ -71,8 +123,8 @@ public static void main( String[] args ) boolean readTestsFromInputStream = providerConfiguration.isReadTestsFromInStream(); final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration(); - final ClassLoader testClassLoader = classpathConfiguration.createForkingTestClassLoader( - startupConfiguration.isManifestOnlyJarRequestedAndUsable() ); + final ClassLoader testClassLoader = + classpathConfiguration.createForkingTestClassLoader( startupConfiguration.isManifestOnlyJarRequestedAndUsable() ); startupConfiguration.writeSurefireTestClasspathProperty(); @@ -92,8 +144,7 @@ else if ( readTestsFromInputStream ) try { - runSuitesInProcess( testSet, testClassLoader, startupConfiguration, providerConfiguration, - originalOut ); + runSuitesInProcess( testSet, testClassLoader, startupConfiguration, providerConfiguration, originalOut ); } catch ( InvocationTargetException t ) { @@ -111,10 +162,8 @@ else if ( readTestsFromInputStream ) ForkingRunListener.encode( stringBuffer, stackTraceWriter, false ); originalOut.println( ( (char) ForkingRunListener.BOOTERCODE_ERROR ) + ",0," + stringBuffer.toString() ); } - // Say bye. - originalOut.println( ( (char) ForkingRunListener.BOOTERCODE_BYE ) + ",0,BYE!" ); - originalOut.flush(); - // noinspection CallToSystemExit + + sayGoodbye = true; exit( 0 ); } catch ( Throwable t ) @@ -127,15 +176,12 @@ else if ( readTestsFromInputStream ) } } - private final static long SYSTEM_EXIT_TIMEOUT = 30 * 1000; - private static void exit( final int returnCode ) { launchLastDitchDaemonShutdownThread( returnCode ); System.exit( returnCode ); } - private static RunResult runSuitesInProcess( Object testSet, ClassLoader testsClassLoader, StartupConfiguration startupConfiguration, ProviderConfiguration providerConfiguration, diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CrashDetectionIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CrashDetectionIT.java index 7dc868f6ad..31e3e01565 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CrashDetectionIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CrashDetectionIT.java @@ -27,8 +27,13 @@ public class CrashDetectionIT extends SurefireIntegrationTestCase { - public void testArgLine() + public void testCrashInFork() { unpack( "crash-detection" ).maven().withFailure().executeTest(); } + + public void testCrashInReusableFork() + { + unpack( "crash-detection" ).forkOncePerThread().threadCount( 1 ).maven().withFailure().executeTest(); + } } From 230c46a26eaffcb0da57fd317e6a7611ba2c8e96 Mon Sep 17 00:00:00 2001 From: Kristian Rosenvold Date: Wed, 9 Jan 2013 19:03:30 +0100 Subject: [PATCH 05/14] o Removed warning --- .../java/org/apache/maven/surefire/booter/ForkedBooter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java index 4b04a99e6f..5f711f42d2 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java @@ -72,7 +72,7 @@ public void run() { originalIn.close(); } - catch ( IOException e ) + catch ( IOException ignore ) { } From 126f44957784ea8a0e5e2bd1b32687f37cb8aaec Mon Sep 17 00:00:00 2001 From: Kristian Rosenvold Date: Wed, 9 Jan 2013 19:48:40 +0100 Subject: [PATCH 06/14] o Removed windows linefeeds --- .../lazytestprovider/FlushReceiver.java | 76 +-- .../FlushReceiverProvider.java | 66 +-- .../OutputStreamFlushableCommandline.java | 162 +++--- .../TestProvidingInputStream.java | 248 ++++----- .../surefire/report/ConsoleReporter.java | 266 +++++----- .../report/DefaultReporterFactory.java | 286 +++++----- .../surefire/report/DirectConsoleOutput.java | 130 ++--- .../surefire/report/ReportEntryType.java | 58 +- .../surefire/report/TestSetRunListener.java | 494 +++++++++--------- .../TestcycleConsoleOutputReceiver.java | 76 +-- .../surefire/util/DirectoryScanner.java | 258 ++++----- .../surefire/util/SpecificFileFilter.java | 134 ++--- .../report/WrappedReportEntryTest.java | 146 +++--- .../surefire/util/DirectoryScannerTest.java | 120 ++--- .../surefire/util/SpecificFileFilterTest.java | 126 ++--- .../surefire/report/RunStatisticsTest.java | 216 ++++---- .../report/DefaultConsoleReporter.java | 82 +-- .../report/DefaultDirectConsoleReporter.java | 80 +-- .../src/test/resources/ant-ignore/.gitignore | 6 +- .../src/test/resources/ant-ignore/build.xml | 104 ++-- .../src/test/resources/ant-ignore/ivy.xml | 12 +- .../src/test/resources/ant-ignore/src/ivy.xml | 12 +- .../java/failingbuilds/ExceptionsTest.java | 36 +- .../BeforeClassError.java | 84 +-- .../BeforeClassFailure.java | 84 +-- .../failureresultcounting/BeforeError.java | 94 ++-- .../failureresultcounting/BeforeFailure.java | 84 +-- .../java/failureresultcounting/NoErrors.java | 84 +-- .../failureresultcounting/OrdinaryError.java | 82 +-- .../java/resultcounting/MySuiteTest1.java | 48 +- .../java/resultcounting/MySuiteTest2.java | 50 +- .../java/resultcounting/MySuiteTest3.java | 52 +- .../src/test/java/resultcounting/Test1.java | 150 +++--- .../test/java/smallresultcounting/Test1.java | 92 ++-- .../test/java/smallresultcounting/Test2.java | 174 +++--- .../test/java/surefire500/PassingTest.java | 66 +-- .../src/test/java/surefire500/Suite.java | 20 +- .../src/it/java/mho/MySuiteTest1.java | 58 +- .../src/it/java/mho/MySuiteTest2.java | 60 +-- .../src/it/java/mho/MySuiteTest3.java | 60 +-- .../src/test/java/surefire685/TestA.java | 58 +- .../src/test/java/surefire685/TestB.java | 58 +- .../src/test/java/surefire685/TestC.java | 58 +- .../surefire-818-ignored-tests-on-npe/pom.xml | 74 +-- .../src/test/java/cyril/test/FirstTest.java | 72 +-- .../src/test/java/cyril/test/IgnoredTest.java | 32 +- .../src/test/java/cyril/test/Message.java | 36 +- .../src/test/java/cyril/test/MyService.java | 16 +- .../test/java/cyril/test/MyServiceImpl.java | 24 +- .../surefire/testcase/JunitParamsTest.java | 102 ++-- .../surefire/testcase/NonJunitParamsTest.java | 74 +-- .../resources/surefire-847-testngfail/pom.xml | 134 ++--- .../surefire-926-2-provider-failure/pom.xml | 82 +-- .../src/test/java/com/company/JUnitTest.java | 24 +- .../src/test/java/com/company/TestNGTest.java | 24 +- .../surefire-931-provider-failure/pom.xml | 96 ++-- .../java/com/mycompany/testfailed/App.java | 26 +- .../com/mycompany/testfailed/AppTest.java | 36 +- .../surefire/junit/JUnitTestSetTest.java | 240 ++++----- .../junitcore/AsynchronousRunner.java | 162 +++--- .../surefire/junitcore/SynchronousRunner.java | 74 +-- 61 files changed, 3019 insertions(+), 3019 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/FlushReceiver.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/FlushReceiver.java index 969affac8b..a7aa62e951 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/FlushReceiver.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/FlushReceiver.java @@ -1,38 +1,38 @@ -package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; - -/* - * 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. - */ - -import java.io.IOException; - -/** - * Something that can be flushed. - * - * @author Andreas Gudian - */ -public interface FlushReceiver -{ - /** - * Performs a flush, releasing any buffered resources. - * - * @throws IOException in case the flush operation failed - */ - void flush() - throws IOException; -} +package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; + +/* + * 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. + */ + +import java.io.IOException; + +/** + * Something that can be flushed. + * + * @author Andreas Gudian + */ +public interface FlushReceiver +{ + /** + * Performs a flush, releasing any buffered resources. + * + * @throws IOException in case the flush operation failed + */ + void flush() + throws IOException; +} diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/FlushReceiverProvider.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/FlushReceiverProvider.java index 8c15fa6567..96ea32ca5b 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/FlushReceiverProvider.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/FlushReceiverProvider.java @@ -1,34 +1,34 @@ -package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; - -/* - * 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. - */ - -/** - * Provides a {@link FlushReceiver}. - * - * @author Andreas Gudian - */ -public interface FlushReceiverProvider -{ - - /** - * @return a {@link FlushReceiver} - */ - FlushReceiver getFlushReceiver(); +package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; + +/* + * 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. + */ + +/** + * Provides a {@link FlushReceiver}. + * + * @author Andreas Gudian + */ +public interface FlushReceiverProvider +{ + + /** + * @return a {@link FlushReceiver} + */ + FlushReceiver getFlushReceiver(); } \ No newline at end of file diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java index 60b8325d89..deefbd0ee0 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/OutputStreamFlushableCommandline.java @@ -1,82 +1,82 @@ -package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; - -/* - * 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. - */ - -import java.io.IOException; -import java.io.OutputStream; -import org.apache.maven.shared.utils.cli.CommandLineException; -import org.apache.maven.shared.utils.cli.Commandline; - -/** - * A {@link Commandline} implementation that provides the output stream of - * the executed process in form of a {@link FlushReceiver}, for it to be - * flushed on demand. - * - * @author Andreas Gudian - */ -public class OutputStreamFlushableCommandline - extends Commandline - implements FlushReceiverProvider -{ - /** - * Wraps an output stream in order to delegate a flush. - */ - private final class OutputStreamFlushReceiver - implements FlushReceiver - { - private final OutputStream outputStream; - - private OutputStreamFlushReceiver( OutputStream outputStream ) - { - this.outputStream = outputStream; - } - - public void flush() - throws IOException - { - outputStream.flush(); - } - } - - private FlushReceiver flushReceiver; - - @Override - public Process execute() - throws CommandLineException - { - Process process = super.execute(); - - if ( process.getOutputStream() != null ) - { - flushReceiver = new OutputStreamFlushReceiver( process.getOutputStream() ); - } - - return process; - } - - /* (non-Javadoc) - * @see org.apache.maven.plugin.surefire.booterclient.lazytestprovider.FlushReceiverProvider#getFlushReceiver() - */ - public FlushReceiver getFlushReceiver() - { - return flushReceiver; - } - +package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; + +/* + * 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. + */ + +import java.io.IOException; +import java.io.OutputStream; +import org.apache.maven.shared.utils.cli.CommandLineException; +import org.apache.maven.shared.utils.cli.Commandline; + +/** + * A {@link Commandline} implementation that provides the output stream of + * the executed process in form of a {@link FlushReceiver}, for it to be + * flushed on demand. + * + * @author Andreas Gudian + */ +public class OutputStreamFlushableCommandline + extends Commandline + implements FlushReceiverProvider +{ + /** + * Wraps an output stream in order to delegate a flush. + */ + private final class OutputStreamFlushReceiver + implements FlushReceiver + { + private final OutputStream outputStream; + + private OutputStreamFlushReceiver( OutputStream outputStream ) + { + this.outputStream = outputStream; + } + + public void flush() + throws IOException + { + outputStream.flush(); + } + } + + private FlushReceiver flushReceiver; + + @Override + public Process execute() + throws CommandLineException + { + Process process = super.execute(); + + if ( process.getOutputStream() != null ) + { + flushReceiver = new OutputStreamFlushReceiver( process.getOutputStream() ); + } + + return process; + } + + /* (non-Javadoc) + * @see org.apache.maven.plugin.surefire.booterclient.lazytestprovider.FlushReceiverProvider#getFlushReceiver() + */ + public FlushReceiver getFlushReceiver() + { + return flushReceiver; + } + } \ No newline at end of file diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java index df14d3594f..730443559f 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java @@ -1,125 +1,125 @@ -package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; - -/* - * 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. - */ - -import java.io.IOException; -import java.io.InputStream; -import java.util.Queue; -import java.util.concurrent.Semaphore; - -/** - * An {@link InputStream} that, when read, provides test class names out of a queue. - *

- * The Stream provides only one test at a time, but only after {@link #provideNewTest()} has been invoked. - *

- * After providing each test class name, followed by a newline character, a flush is performed on the - * {@link FlushReceiver} provided by the {@link FlushReceiverProvider} that can be set using - * {@link #setFlushReceiverProvider(FlushReceiverProvider)}. - * - * @author Andreas Gudian - */ -public class TestProvidingInputStream - extends InputStream -{ - private final Queue testItemQueue; - - private byte[] currentBuffer; - - private int currentPos; - - private Semaphore semaphore = new Semaphore( 0 ); - - private FlushReceiverProvider flushReceiverProvider; - - private boolean closed = false; - - /** - * C'tor - * - * @param testItemQueue source of the tests to be read from this stream - */ - public TestProvidingInputStream( Queue testItemQueue ) - { - this.testItemQueue = testItemQueue; - } - - /** - * @param flushReceiverProvider the provider for a flush receiver. - */ - public void setFlushReceiverProvider( FlushReceiverProvider flushReceiverProvider ) - { - this.flushReceiverProvider = flushReceiverProvider; - } - - @Override - public synchronized int read() - throws IOException - { - if ( null == currentBuffer ) - { - if ( null != flushReceiverProvider && null != flushReceiverProvider.getFlushReceiver() ) - { - flushReceiverProvider.getFlushReceiver().flush(); - } - - semaphore.acquireUninterruptibly(); - - if ( closed ) - { - return -1; - } - - String currentElement = testItemQueue.poll(); - if ( null != currentElement ) - { - currentBuffer = currentElement.getBytes(); - currentPos = 0; - } - else - { - return -1; - } - } - - if ( currentPos < currentBuffer.length ) - { - return ( currentBuffer[currentPos++] & 0xff ); - } - else - { - currentBuffer = null; - return ( '\n' & 0xff ); - } - } - - /** - * Signal that a new test is to be provided. - */ - public void provideNewTest() - { - semaphore.release(); - } - - public void close() - { - closed = true; - semaphore.release(); - } +package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; + +/* + * 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. + */ + +import java.io.IOException; +import java.io.InputStream; +import java.util.Queue; +import java.util.concurrent.Semaphore; + +/** + * An {@link InputStream} that, when read, provides test class names out of a queue. + *

+ * The Stream provides only one test at a time, but only after {@link #provideNewTest()} has been invoked. + *

+ * After providing each test class name, followed by a newline character, a flush is performed on the + * {@link FlushReceiver} provided by the {@link FlushReceiverProvider} that can be set using + * {@link #setFlushReceiverProvider(FlushReceiverProvider)}. + * + * @author Andreas Gudian + */ +public class TestProvidingInputStream + extends InputStream +{ + private final Queue testItemQueue; + + private byte[] currentBuffer; + + private int currentPos; + + private Semaphore semaphore = new Semaphore( 0 ); + + private FlushReceiverProvider flushReceiverProvider; + + private boolean closed = false; + + /** + * C'tor + * + * @param testItemQueue source of the tests to be read from this stream + */ + public TestProvidingInputStream( Queue testItemQueue ) + { + this.testItemQueue = testItemQueue; + } + + /** + * @param flushReceiverProvider the provider for a flush receiver. + */ + public void setFlushReceiverProvider( FlushReceiverProvider flushReceiverProvider ) + { + this.flushReceiverProvider = flushReceiverProvider; + } + + @Override + public synchronized int read() + throws IOException + { + if ( null == currentBuffer ) + { + if ( null != flushReceiverProvider && null != flushReceiverProvider.getFlushReceiver() ) + { + flushReceiverProvider.getFlushReceiver().flush(); + } + + semaphore.acquireUninterruptibly(); + + if ( closed ) + { + return -1; + } + + String currentElement = testItemQueue.poll(); + if ( null != currentElement ) + { + currentBuffer = currentElement.getBytes(); + currentPos = 0; + } + else + { + return -1; + } + } + + if ( currentPos < currentBuffer.length ) + { + return ( currentBuffer[currentPos++] & 0xff ); + } + else + { + currentBuffer = null; + return ( '\n' & 0xff ); + } + } + + /** + * Signal that a new test is to be provided. + */ + public void provideNewTest() + { + semaphore.release(); + } + + public void close() + { + closed = true; + semaphore.release(); + } } \ No newline at end of file diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java index 52165af113..1fa55c9f8e 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ConsoleReporter.java @@ -1,133 +1,133 @@ -package org.apache.maven.plugin.surefire.report; - -/* - * 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. - */ - -import java.io.BufferedOutputStream; -import java.io.OutputStreamWriter; -import java.io.PrintStream; -import java.io.PrintWriter; -import java.util.List; -import org.apache.maven.surefire.report.ReportEntry; -import org.apache.maven.surefire.report.ReporterException; - -/** - * Base class for console reporters. - * - * @author Brett Porter - * @author Kristian Rosenvold - */ -public class ConsoleReporter -{ - public static final String BRIEF = "brief"; - - public static final String PLAIN = "plain"; - - private static final String TEST_SET_STARTING_PREFIX = "Running "; - - private static final String TEST_SET_STARTING_GROUP_PREFIX = " (of "; - - private static final String TEST_SET_STARTING_GROUP_SUFIX = ")"; - - private static final int BUFFER_SIZE = 4096; - - private final PrintWriter writer; - - - public ConsoleReporter( PrintStream originalSystemOut ) - { - OutputStreamWriter out = new OutputStreamWriter( new BufferedOutputStream( originalSystemOut, BUFFER_SIZE ) ); - this.writer = new PrintWriter( out ); - } - - public void testSetStarting( ReportEntry report ) - throws ReporterException - { - writeMessage( getTestSetStartingMessage( report ) ); - } - - public void writeMessage( String message ) - { - if ( writer != null ) - { - writer.print( message ); - - writer.flush(); - } - } - - public void writeLnMessage( String message ) - { - if ( writer != null ) - { - writer.println( message ); - - writer.flush(); - } - } - - public void testSetCompleted( WrappedReportEntry report, TestSetStats testSetStats, List testResults ) - throws ReporterException - { - writeMessage( testSetStats.getTestSetSummary( report ) ); - - if ( testResults != null ) - { - for ( String testResult : testResults ) - { - writeLnMessage( testResult ); - } - } - } - - - public void reset() - { - if ( writer != null ) - { - writer.flush(); - } - } - - /** - * Get the test set starting message for a report. - * eg. "Running org.foo.BarTest ( of group )" - * - * @param report report whose test set is starting - * @return the message - */ - static String getTestSetStartingMessage( ReportEntry report ) - { - StringBuilder message = new StringBuilder(); - message.append( TEST_SET_STARTING_PREFIX ); - message.append( report.getName() ); - - if ( report.getGroup() != null && !report.getName().equals( report.getGroup() ) ) - { - message.append( TEST_SET_STARTING_GROUP_PREFIX ); - message.append( report.getGroup() ); - message.append( TEST_SET_STARTING_GROUP_SUFIX ); - } - - message.append( "\n" ); - return message.toString(); - } - - -} +package org.apache.maven.plugin.surefire.report; + +/* + * 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. + */ + +import java.io.BufferedOutputStream; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.io.PrintWriter; +import java.util.List; +import org.apache.maven.surefire.report.ReportEntry; +import org.apache.maven.surefire.report.ReporterException; + +/** + * Base class for console reporters. + * + * @author Brett Porter + * @author Kristian Rosenvold + */ +public class ConsoleReporter +{ + public static final String BRIEF = "brief"; + + public static final String PLAIN = "plain"; + + private static final String TEST_SET_STARTING_PREFIX = "Running "; + + private static final String TEST_SET_STARTING_GROUP_PREFIX = " (of "; + + private static final String TEST_SET_STARTING_GROUP_SUFIX = ")"; + + private static final int BUFFER_SIZE = 4096; + + private final PrintWriter writer; + + + public ConsoleReporter( PrintStream originalSystemOut ) + { + OutputStreamWriter out = new OutputStreamWriter( new BufferedOutputStream( originalSystemOut, BUFFER_SIZE ) ); + this.writer = new PrintWriter( out ); + } + + public void testSetStarting( ReportEntry report ) + throws ReporterException + { + writeMessage( getTestSetStartingMessage( report ) ); + } + + public void writeMessage( String message ) + { + if ( writer != null ) + { + writer.print( message ); + + writer.flush(); + } + } + + public void writeLnMessage( String message ) + { + if ( writer != null ) + { + writer.println( message ); + + writer.flush(); + } + } + + public void testSetCompleted( WrappedReportEntry report, TestSetStats testSetStats, List testResults ) + throws ReporterException + { + writeMessage( testSetStats.getTestSetSummary( report ) ); + + if ( testResults != null ) + { + for ( String testResult : testResults ) + { + writeLnMessage( testResult ); + } + } + } + + + public void reset() + { + if ( writer != null ) + { + writer.flush(); + } + } + + /** + * Get the test set starting message for a report. + * eg. "Running org.foo.BarTest ( of group )" + * + * @param report report whose test set is starting + * @return the message + */ + static String getTestSetStartingMessage( ReportEntry report ) + { + StringBuilder message = new StringBuilder(); + message.append( TEST_SET_STARTING_PREFIX ); + message.append( report.getName() ); + + if ( report.getGroup() != null && !report.getName().equals( report.getGroup() ) ) + { + message.append( TEST_SET_STARTING_GROUP_PREFIX ); + message.append( report.getGroup() ); + message.append( TEST_SET_STARTING_GROUP_SUFIX ); + } + + message.append( "\n" ); + return message.toString(); + } + + +} diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java index 1e29241383..d02eddc9a8 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java @@ -1,143 +1,143 @@ -package org.apache.maven.plugin.surefire.report; - -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.apache.maven.plugin.surefire.StartupReportConfiguration; -import org.apache.maven.plugin.surefire.runorder.StatisticsReporter; -import org.apache.maven.surefire.report.DefaultDirectConsoleReporter; -import org.apache.maven.surefire.report.ReporterFactory; -import org.apache.maven.surefire.report.RunListener; -import org.apache.maven.surefire.report.RunStatistics; -import org.apache.maven.surefire.suite.RunResult; - -/** - * Provides reporting modules on the plugin side. - *

- * Keeps a centralized count of test run results. - * - * @author Kristian Rosenvold - */ -public class DefaultReporterFactory - implements ReporterFactory -{ - - private final RunStatistics globalStats = new RunStatistics(); - - private final StartupReportConfiguration reportConfiguration; - - private final StatisticsReporter statisticsReporter; - - private final List listeners = - Collections.synchronizedList( new ArrayList() ); - - public DefaultReporterFactory( StartupReportConfiguration reportConfiguration ) - { - this.reportConfiguration = reportConfiguration; - this.statisticsReporter = reportConfiguration.instantiateStatisticsReporter(); - runStarting(); - } - - public RunListener createReporter() - { - return createTestSetRunListener(); - } - - public RunListener createTestSetRunListener() - { - TestSetRunListener testSetRunListener = - new TestSetRunListener( reportConfiguration.instantiateConsoleReporter(), - reportConfiguration.instantiateFileReporter(), - reportConfiguration.instantiateStatelessXmlReporter(), - reportConfiguration.instantiateConsoleOutputFileReporter(), statisticsReporter, - globalStats, reportConfiguration.isTrimStackTrace(), - ConsoleReporter.PLAIN.equals( reportConfiguration.getReportFormat() ), - reportConfiguration.isBriefOrPlainFormat() ); - listeners.add( testSetRunListener ); - return testSetRunListener; - } - - public RunResult close() - { - runCompleted(); - for ( TestSetRunListener listener : listeners ) - { - listener.close(); - } - return globalStats.getRunResult(); - } - - private DefaultDirectConsoleReporter createConsoleLogger() - { - return new DefaultDirectConsoleReporter( reportConfiguration.getOriginalSystemOut() ); - } - - public void runStarting() - { - final DefaultDirectConsoleReporter consoleReporter = createConsoleLogger(); - consoleReporter.info( "" ); - consoleReporter.info( "-------------------------------------------------------" ); - consoleReporter.info( " T E S T S" ); - consoleReporter.info( "-------------------------------------------------------" ); - } - - private void runCompleted() - { - final DefaultDirectConsoleReporter logger = createConsoleLogger(); - if ( reportConfiguration.isPrintSummary() ) - { - logger.info( "" ); - logger.info( "Results :" ); - logger.info( "" ); - } - if ( globalStats.hadFailures() ) - { - logger.info( "Failed tests: " ); - for ( Object o : this.globalStats.getFailureSources() ) - { - logger.info( " " + o ); - } - logger.info( "" ); - } - if ( globalStats.hadErrors() ) - { - logger.info( "Tests in error: " ); - for ( Object o : this.globalStats.getErrorSources() ) - { - logger.info( " " + o ); - } - logger.info( "" ); - } - logger.info( globalStats.getSummary() ); - logger.info( "" ); - } - - public RunStatistics getGlobalRunStatistics() - { - return globalStats; - } - - public static DefaultReporterFactory defaultNoXml() - { - return new DefaultReporterFactory( StartupReportConfiguration.defaultNoXml() ); - } -} +package org.apache.maven.plugin.surefire.report; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.apache.maven.plugin.surefire.StartupReportConfiguration; +import org.apache.maven.plugin.surefire.runorder.StatisticsReporter; +import org.apache.maven.surefire.report.DefaultDirectConsoleReporter; +import org.apache.maven.surefire.report.ReporterFactory; +import org.apache.maven.surefire.report.RunListener; +import org.apache.maven.surefire.report.RunStatistics; +import org.apache.maven.surefire.suite.RunResult; + +/** + * Provides reporting modules on the plugin side. + *

+ * Keeps a centralized count of test run results. + * + * @author Kristian Rosenvold + */ +public class DefaultReporterFactory + implements ReporterFactory +{ + + private final RunStatistics globalStats = new RunStatistics(); + + private final StartupReportConfiguration reportConfiguration; + + private final StatisticsReporter statisticsReporter; + + private final List listeners = + Collections.synchronizedList( new ArrayList() ); + + public DefaultReporterFactory( StartupReportConfiguration reportConfiguration ) + { + this.reportConfiguration = reportConfiguration; + this.statisticsReporter = reportConfiguration.instantiateStatisticsReporter(); + runStarting(); + } + + public RunListener createReporter() + { + return createTestSetRunListener(); + } + + public RunListener createTestSetRunListener() + { + TestSetRunListener testSetRunListener = + new TestSetRunListener( reportConfiguration.instantiateConsoleReporter(), + reportConfiguration.instantiateFileReporter(), + reportConfiguration.instantiateStatelessXmlReporter(), + reportConfiguration.instantiateConsoleOutputFileReporter(), statisticsReporter, + globalStats, reportConfiguration.isTrimStackTrace(), + ConsoleReporter.PLAIN.equals( reportConfiguration.getReportFormat() ), + reportConfiguration.isBriefOrPlainFormat() ); + listeners.add( testSetRunListener ); + return testSetRunListener; + } + + public RunResult close() + { + runCompleted(); + for ( TestSetRunListener listener : listeners ) + { + listener.close(); + } + return globalStats.getRunResult(); + } + + private DefaultDirectConsoleReporter createConsoleLogger() + { + return new DefaultDirectConsoleReporter( reportConfiguration.getOriginalSystemOut() ); + } + + public void runStarting() + { + final DefaultDirectConsoleReporter consoleReporter = createConsoleLogger(); + consoleReporter.info( "" ); + consoleReporter.info( "-------------------------------------------------------" ); + consoleReporter.info( " T E S T S" ); + consoleReporter.info( "-------------------------------------------------------" ); + } + + private void runCompleted() + { + final DefaultDirectConsoleReporter logger = createConsoleLogger(); + if ( reportConfiguration.isPrintSummary() ) + { + logger.info( "" ); + logger.info( "Results :" ); + logger.info( "" ); + } + if ( globalStats.hadFailures() ) + { + logger.info( "Failed tests: " ); + for ( Object o : this.globalStats.getFailureSources() ) + { + logger.info( " " + o ); + } + logger.info( "" ); + } + if ( globalStats.hadErrors() ) + { + logger.info( "Tests in error: " ); + for ( Object o : this.globalStats.getErrorSources() ) + { + logger.info( " " + o ); + } + logger.info( "" ); + } + logger.info( globalStats.getSummary() ); + logger.info( "" ); + } + + public RunStatistics getGlobalRunStatistics() + { + return globalStats; + } + + public static DefaultReporterFactory defaultNoXml() + { + return new DefaultReporterFactory( StartupReportConfiguration.defaultNoXml() ); + } +} diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DirectConsoleOutput.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DirectConsoleOutput.java index 9bc883f8ee..ab710e964d 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DirectConsoleOutput.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DirectConsoleOutput.java @@ -1,65 +1,65 @@ -package org.apache.maven.plugin.surefire.report; - -/* - * 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. - */ - -import java.io.PrintStream; -import org.apache.maven.surefire.report.ReportEntry; - -/** - * Outputs test system out/system err directly to the console - *

- * Just a step on the road to getting the separation of reporting concerns - * operating properly. - * - * @author Kristian Rosenvold - */ -public class DirectConsoleOutput - implements TestcycleConsoleOutputReceiver -{ - private final PrintStream sout; - - private final PrintStream serr; - - public DirectConsoleOutput( PrintStream sout, PrintStream serr ) - { - this.sout = sout; - this.serr = serr; - } - - - public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) - { - PrintStream stream = stdout ? sout : serr; - stream.write( buf, off, len ); - } - - public void testSetStarting( ReportEntry reportEntry ) - { - } - - public void testSetCompleted( ReportEntry report ) - { - } - - public void close() - { - //To change body of implemented methods use File | Settings | File Templates. - } -} +package org.apache.maven.plugin.surefire.report; + +/* + * 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. + */ + +import java.io.PrintStream; +import org.apache.maven.surefire.report.ReportEntry; + +/** + * Outputs test system out/system err directly to the console + *

+ * Just a step on the road to getting the separation of reporting concerns + * operating properly. + * + * @author Kristian Rosenvold + */ +public class DirectConsoleOutput + implements TestcycleConsoleOutputReceiver +{ + private final PrintStream sout; + + private final PrintStream serr; + + public DirectConsoleOutput( PrintStream sout, PrintStream serr ) + { + this.sout = sout; + this.serr = serr; + } + + + public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) + { + PrintStream stream = stdout ? sout : serr; + stream.write( buf, off, len ); + } + + public void testSetStarting( ReportEntry reportEntry ) + { + } + + public void testSetCompleted( ReportEntry report ) + { + } + + public void close() + { + //To change body of implemented methods use File | Settings | File Templates. + } +} diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java index 734a5aef9e..562b123066 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/ReportEntryType.java @@ -1,29 +1,29 @@ -package org.apache.maven.plugin.surefire.report; - -/* - * 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. - */ - -public enum ReportEntryType -{ - error, - failure, - skipped, - success - -} +package org.apache.maven.plugin.surefire.report; + +/* + * 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. + */ + +public enum ReportEntryType +{ + error, + failure, + skipped, + success + +} diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java index 608b37e4bf..230e0e7e76 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java @@ -1,247 +1,247 @@ -package org.apache.maven.plugin.surefire.report; - -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.apache.maven.plugin.surefire.runorder.StatisticsReporter; -import org.apache.maven.surefire.report.ConsoleLogger; -import org.apache.maven.surefire.report.ConsoleOutputReceiver; -import org.apache.maven.surefire.report.ReportEntry; -import org.apache.maven.surefire.report.RunListener; -import org.apache.maven.surefire.report.RunStatistics; -import org.apache.maven.surefire.util.internal.ByteBuffer; - -/** - * Reports data for a single test set. - *

- * - * @author Kristian Rosenvold - */ -public class TestSetRunListener - implements RunListener, ConsoleOutputReceiver, ConsoleLogger -{ - private final RunStatistics globalStatistics; - - private final TestSetStats detailsForThis; - - private final List testStdOut = Collections.synchronizedList( new ArrayList() ); - - private final List testStdErr = Collections.synchronizedList( new ArrayList() ); - - private final TestcycleConsoleOutputReceiver consoleOutputReceiver; - - private final boolean briefOrPlainFormat; - - private final StatelessXmlReporter simpleXMLReporter; - - private final ConsoleReporter consoleReporter; - - private final FileReporter fileReporter; - - private final StatisticsReporter statisticsReporter; - - public TestSetRunListener( ConsoleReporter consoleReporter, FileReporter fileReporter, - StatelessXmlReporter simpleXMLReporter, - TestcycleConsoleOutputReceiver consoleOutputReceiver, - StatisticsReporter statisticsReporter, RunStatistics globalStats, boolean trimStackTrace, - boolean isPlainFormat, boolean briefOrPlainFormat ) - { - this.consoleReporter = consoleReporter; - this.fileReporter = fileReporter; - this.statisticsReporter = statisticsReporter; - this.simpleXMLReporter = simpleXMLReporter; - this.consoleOutputReceiver = consoleOutputReceiver; - this.briefOrPlainFormat = briefOrPlainFormat; - this.detailsForThis = new TestSetStats( trimStackTrace, isPlainFormat ); - this.globalStatistics = globalStats; - } - - public void info( String message ) - { - if ( consoleReporter != null ) - { - consoleReporter.writeMessage( message ); - } - } - - public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) - { - ByteBuffer byteBuffer = new ByteBuffer( buf, off, len ); - if ( stdout ) - { - testStdOut.add( byteBuffer ); - } - else - { - testStdErr.add( byteBuffer ); - } - consoleOutputReceiver.writeTestOutput( buf, off, len, stdout ); - } - - public void testSetStarting( ReportEntry report ) - { - detailsForThis.testSetStart(); - if ( consoleReporter != null ) - { - consoleReporter.testSetStarting( report ); - } - consoleOutputReceiver.testSetStarting( report ); - } - - public void clearCapture() - { - testStdErr.clear(); - testStdOut.clear(); - } - - public void testSetCompleted( ReportEntry report ) - { - WrappedReportEntry wrap = wrapTestSet( report, null ); - List testResults = briefOrPlainFormat ? detailsForThis.getTestResults() : null; - if ( consoleReporter != null ) - { - consoleReporter.testSetCompleted( wrap, detailsForThis, testResults ); - } - consoleOutputReceiver.testSetCompleted( wrap ); - if ( fileReporter != null ) - { - fileReporter.testSetCompleted( wrap, detailsForThis, testResults ); - } - if ( simpleXMLReporter != null ) - { - simpleXMLReporter.testSetCompleted( wrap, detailsForThis ); - } - if ( statisticsReporter != null ) - { - statisticsReporter.testSetCompleted(); - } - if ( consoleReporter != null ) - { - consoleReporter.reset(); - } - - globalStatistics.add( detailsForThis ); - detailsForThis.reset(); - - } - - // ---------------------------------------------------------------------- - // Test - // ---------------------------------------------------------------------- - - public void testStarting( ReportEntry report ) - { - detailsForThis.testStart(); - - } - - public void testSucceeded( ReportEntry reportEntry ) - { - WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.success ); - detailsForThis.testSucceeded( wrapped ); - if ( statisticsReporter != null ) - { - statisticsReporter.testSucceeded( reportEntry ); - } - clearCapture(); - } - - public void testError( ReportEntry reportEntry ) - { - WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.error ); - detailsForThis.testError( wrapped ); - if ( statisticsReporter != null ) - { - statisticsReporter.testError( reportEntry ); - } - globalStatistics.addErrorSource( reportEntry.getStackTraceWriter() ); - clearCapture(); - } - - public void testFailed( ReportEntry reportEntry ) - { - WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.failure ); - detailsForThis.testFailure( wrapped ); - if ( statisticsReporter != null ) - { - statisticsReporter.testFailed( reportEntry ); - } - globalStatistics.addFailureSource( reportEntry.getStackTraceWriter() ); - clearCapture(); - } - - // ---------------------------------------------------------------------- - // Counters - // ---------------------------------------------------------------------- - - public void testSkipped( ReportEntry reportEntry ) - { - - WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.skipped ); - detailsForThis.testSkipped( wrapped ); - if ( statisticsReporter != null ) - { - statisticsReporter.testSkipped( reportEntry ); - } - clearCapture(); - } - - public void testAssumptionFailure( ReportEntry report ) - { - testSkipped( report ); - } - - public String getAsString( List byteBufferList ) - { - StringBuilder stringBuffer = new StringBuilder(); - // To avoid getting a java.util.ConcurrentModificationException while iterating (see SUREFIRE-879) we need to - // iterate over a copy or the elements array. Since the passed in byteBufferList is always wrapped with - // Collections.synchronizedList( ) we are guaranteed toArray() is going to be atomic, so we are safe. - for ( Object byteBuffer : byteBufferList.toArray() ) - { - stringBuffer.append( byteBuffer.toString() ); - } - return stringBuffer.toString(); - } - - private WrappedReportEntry wrap( ReportEntry other, ReportEntryType reportEntryType ) - { - return new WrappedReportEntry( other, reportEntryType, other.getElapsed() != null - ? other.getElapsed() - : detailsForThis.getElapsedSinceLastStart(), getAsString( testStdOut ), getAsString( testStdErr ) ); - } - - private WrappedReportEntry wrapTestSet( ReportEntry other, ReportEntryType reportEntryType ) - { - return new WrappedReportEntry( other, reportEntryType, other.getElapsed() != null - ? other.getElapsed() - : detailsForThis.getElapsedSinceTestSetStart(), getAsString( testStdOut ), getAsString( testStdErr ) ); - } - - public void close() - { - if ( consoleOutputReceiver != null ) - { - consoleOutputReceiver.close(); - } - } -} +package org.apache.maven.plugin.surefire.report; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.apache.maven.plugin.surefire.runorder.StatisticsReporter; +import org.apache.maven.surefire.report.ConsoleLogger; +import org.apache.maven.surefire.report.ConsoleOutputReceiver; +import org.apache.maven.surefire.report.ReportEntry; +import org.apache.maven.surefire.report.RunListener; +import org.apache.maven.surefire.report.RunStatistics; +import org.apache.maven.surefire.util.internal.ByteBuffer; + +/** + * Reports data for a single test set. + *

+ * + * @author Kristian Rosenvold + */ +public class TestSetRunListener + implements RunListener, ConsoleOutputReceiver, ConsoleLogger +{ + private final RunStatistics globalStatistics; + + private final TestSetStats detailsForThis; + + private final List testStdOut = Collections.synchronizedList( new ArrayList() ); + + private final List testStdErr = Collections.synchronizedList( new ArrayList() ); + + private final TestcycleConsoleOutputReceiver consoleOutputReceiver; + + private final boolean briefOrPlainFormat; + + private final StatelessXmlReporter simpleXMLReporter; + + private final ConsoleReporter consoleReporter; + + private final FileReporter fileReporter; + + private final StatisticsReporter statisticsReporter; + + public TestSetRunListener( ConsoleReporter consoleReporter, FileReporter fileReporter, + StatelessXmlReporter simpleXMLReporter, + TestcycleConsoleOutputReceiver consoleOutputReceiver, + StatisticsReporter statisticsReporter, RunStatistics globalStats, boolean trimStackTrace, + boolean isPlainFormat, boolean briefOrPlainFormat ) + { + this.consoleReporter = consoleReporter; + this.fileReporter = fileReporter; + this.statisticsReporter = statisticsReporter; + this.simpleXMLReporter = simpleXMLReporter; + this.consoleOutputReceiver = consoleOutputReceiver; + this.briefOrPlainFormat = briefOrPlainFormat; + this.detailsForThis = new TestSetStats( trimStackTrace, isPlainFormat ); + this.globalStatistics = globalStats; + } + + public void info( String message ) + { + if ( consoleReporter != null ) + { + consoleReporter.writeMessage( message ); + } + } + + public void writeTestOutput( byte[] buf, int off, int len, boolean stdout ) + { + ByteBuffer byteBuffer = new ByteBuffer( buf, off, len ); + if ( stdout ) + { + testStdOut.add( byteBuffer ); + } + else + { + testStdErr.add( byteBuffer ); + } + consoleOutputReceiver.writeTestOutput( buf, off, len, stdout ); + } + + public void testSetStarting( ReportEntry report ) + { + detailsForThis.testSetStart(); + if ( consoleReporter != null ) + { + consoleReporter.testSetStarting( report ); + } + consoleOutputReceiver.testSetStarting( report ); + } + + public void clearCapture() + { + testStdErr.clear(); + testStdOut.clear(); + } + + public void testSetCompleted( ReportEntry report ) + { + WrappedReportEntry wrap = wrapTestSet( report, null ); + List testResults = briefOrPlainFormat ? detailsForThis.getTestResults() : null; + if ( consoleReporter != null ) + { + consoleReporter.testSetCompleted( wrap, detailsForThis, testResults ); + } + consoleOutputReceiver.testSetCompleted( wrap ); + if ( fileReporter != null ) + { + fileReporter.testSetCompleted( wrap, detailsForThis, testResults ); + } + if ( simpleXMLReporter != null ) + { + simpleXMLReporter.testSetCompleted( wrap, detailsForThis ); + } + if ( statisticsReporter != null ) + { + statisticsReporter.testSetCompleted(); + } + if ( consoleReporter != null ) + { + consoleReporter.reset(); + } + + globalStatistics.add( detailsForThis ); + detailsForThis.reset(); + + } + + // ---------------------------------------------------------------------- + // Test + // ---------------------------------------------------------------------- + + public void testStarting( ReportEntry report ) + { + detailsForThis.testStart(); + + } + + public void testSucceeded( ReportEntry reportEntry ) + { + WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.success ); + detailsForThis.testSucceeded( wrapped ); + if ( statisticsReporter != null ) + { + statisticsReporter.testSucceeded( reportEntry ); + } + clearCapture(); + } + + public void testError( ReportEntry reportEntry ) + { + WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.error ); + detailsForThis.testError( wrapped ); + if ( statisticsReporter != null ) + { + statisticsReporter.testError( reportEntry ); + } + globalStatistics.addErrorSource( reportEntry.getStackTraceWriter() ); + clearCapture(); + } + + public void testFailed( ReportEntry reportEntry ) + { + WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.failure ); + detailsForThis.testFailure( wrapped ); + if ( statisticsReporter != null ) + { + statisticsReporter.testFailed( reportEntry ); + } + globalStatistics.addFailureSource( reportEntry.getStackTraceWriter() ); + clearCapture(); + } + + // ---------------------------------------------------------------------- + // Counters + // ---------------------------------------------------------------------- + + public void testSkipped( ReportEntry reportEntry ) + { + + WrappedReportEntry wrapped = wrap( reportEntry, ReportEntryType.skipped ); + detailsForThis.testSkipped( wrapped ); + if ( statisticsReporter != null ) + { + statisticsReporter.testSkipped( reportEntry ); + } + clearCapture(); + } + + public void testAssumptionFailure( ReportEntry report ) + { + testSkipped( report ); + } + + public String getAsString( List byteBufferList ) + { + StringBuilder stringBuffer = new StringBuilder(); + // To avoid getting a java.util.ConcurrentModificationException while iterating (see SUREFIRE-879) we need to + // iterate over a copy or the elements array. Since the passed in byteBufferList is always wrapped with + // Collections.synchronizedList( ) we are guaranteed toArray() is going to be atomic, so we are safe. + for ( Object byteBuffer : byteBufferList.toArray() ) + { + stringBuffer.append( byteBuffer.toString() ); + } + return stringBuffer.toString(); + } + + private WrappedReportEntry wrap( ReportEntry other, ReportEntryType reportEntryType ) + { + return new WrappedReportEntry( other, reportEntryType, other.getElapsed() != null + ? other.getElapsed() + : detailsForThis.getElapsedSinceLastStart(), getAsString( testStdOut ), getAsString( testStdErr ) ); + } + + private WrappedReportEntry wrapTestSet( ReportEntry other, ReportEntryType reportEntryType ) + { + return new WrappedReportEntry( other, reportEntryType, other.getElapsed() != null + ? other.getElapsed() + : detailsForThis.getElapsedSinceTestSetStart(), getAsString( testStdOut ), getAsString( testStdErr ) ); + } + + public void close() + { + if ( consoleOutputReceiver != null ) + { + consoleOutputReceiver.close(); + } + } +} diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestcycleConsoleOutputReceiver.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestcycleConsoleOutputReceiver.java index 09710e33a0..d2c59ff4e7 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestcycleConsoleOutputReceiver.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestcycleConsoleOutputReceiver.java @@ -1,38 +1,38 @@ -package org.apache.maven.plugin.surefire.report; - -/* - * 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. - */ - -import org.apache.maven.surefire.report.ConsoleOutputReceiver; -import org.apache.maven.surefire.report.ReportEntry; - -/** - * @author Kristian Rosenvold - */ -public interface TestcycleConsoleOutputReceiver - extends ConsoleOutputReceiver -{ - - void testSetStarting( ReportEntry reportEntry ); - - void testSetCompleted( ReportEntry report ); - - void close(); - -} +package org.apache.maven.plugin.surefire.report; + +/* + * 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. + */ + +import org.apache.maven.surefire.report.ConsoleOutputReceiver; +import org.apache.maven.surefire.report.ReportEntry; + +/** + * @author Kristian Rosenvold + */ +public interface TestcycleConsoleOutputReceiver + extends ConsoleOutputReceiver +{ + + void testSetStarting( ReportEntry reportEntry ); + + void testSetCompleted( ReportEntry report ); + + void close(); + +} diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java index 73fcaf1150..45c2a5a826 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/DirectoryScanner.java @@ -1,129 +1,129 @@ -package org.apache.maven.plugin.surefire.util; - -/* - * 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. - */ - -import java.io.File; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.apache.commons.lang3.StringUtils; -import org.apache.maven.surefire.util.DefaultScanResult; - -/** - * Scans directories looking for tests. - * - * @author Karl M. Davis - * @author Kristian Rosenvold - */ -public class DirectoryScanner -{ - - private static final String FS = System.getProperty( "file.separator" ); - - private static final String JAVA_SOURCE_FILE_EXTENSION = ".java"; - - private static final String JAVA_CLASS_FILE_EXTENSION = ".class"; - - private final File basedir; - - private final List includes; - - private final List excludes; - - private final List specificTests; - - public DirectoryScanner( File basedir, List includes, List excludes, List specificTests ) - { - this.basedir = basedir; - this.includes = includes; - this.excludes = excludes; - this.specificTests = specificTests; - } - - public DefaultScanResult scan() - { - String[] specific = specificTests == null ? new String[0] : processIncludesExcludes( specificTests ); - SpecificFileFilter specificTestFilter = new SpecificFileFilter( specific ); - - List result = new ArrayList(); - if ( basedir.exists() ) - { - org.apache.maven.shared.utils.io.DirectoryScanner scanner = - new org.apache.maven.shared.utils.io.DirectoryScanner(); - - scanner.setBasedir( basedir ); - - if ( includes != null ) - { - scanner.setIncludes( processIncludesExcludes( includes ) ); - } - - if ( excludes != null ) - { - scanner.setExcludes( processIncludesExcludes( excludes ) ); - } - - scanner.scan(); - for ( String test : scanner.getIncludedFiles() ) - { - if ( specificTestFilter.accept( stripBaseDir( basedir.getAbsolutePath(), test ) ) ) - { - result.add( convertToJavaClassName( test ) ); - } - } - } - return new DefaultScanResult( result ); - } - - private String convertToJavaClassName( String test ) - { - return StringUtils.removeEnd( test, ".class" ).replace( FS, "." ); - } - - private String stripBaseDir( String basedir, String test ) - { - return StringUtils.removeStart( test, basedir ); - } - - private static String[] processIncludesExcludes( List list ) - { - List newList = new ArrayList(); - for ( Object aList : list ) - { - String include = (String) aList; - String[] includes = include.split( "," ); - Collections.addAll( newList, includes ); - } - - String[] incs = new String[newList.size()]; - - for ( int i = 0; i < incs.length; i++ ) - { - String inc = newList.get( i ); - if ( inc.endsWith( JAVA_SOURCE_FILE_EXTENSION ) ) - { - inc = StringUtils.removeEnd( inc, JAVA_SOURCE_FILE_EXTENSION ) + JAVA_CLASS_FILE_EXTENSION; - } - incs[i] = inc; - - } - return incs; - } -} +package org.apache.maven.plugin.surefire.util; + +/* + * 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. + */ + +import java.io.File; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.apache.commons.lang3.StringUtils; +import org.apache.maven.surefire.util.DefaultScanResult; + +/** + * Scans directories looking for tests. + * + * @author Karl M. Davis + * @author Kristian Rosenvold + */ +public class DirectoryScanner +{ + + private static final String FS = System.getProperty( "file.separator" ); + + private static final String JAVA_SOURCE_FILE_EXTENSION = ".java"; + + private static final String JAVA_CLASS_FILE_EXTENSION = ".class"; + + private final File basedir; + + private final List includes; + + private final List excludes; + + private final List specificTests; + + public DirectoryScanner( File basedir, List includes, List excludes, List specificTests ) + { + this.basedir = basedir; + this.includes = includes; + this.excludes = excludes; + this.specificTests = specificTests; + } + + public DefaultScanResult scan() + { + String[] specific = specificTests == null ? new String[0] : processIncludesExcludes( specificTests ); + SpecificFileFilter specificTestFilter = new SpecificFileFilter( specific ); + + List result = new ArrayList(); + if ( basedir.exists() ) + { + org.apache.maven.shared.utils.io.DirectoryScanner scanner = + new org.apache.maven.shared.utils.io.DirectoryScanner(); + + scanner.setBasedir( basedir ); + + if ( includes != null ) + { + scanner.setIncludes( processIncludesExcludes( includes ) ); + } + + if ( excludes != null ) + { + scanner.setExcludes( processIncludesExcludes( excludes ) ); + } + + scanner.scan(); + for ( String test : scanner.getIncludedFiles() ) + { + if ( specificTestFilter.accept( stripBaseDir( basedir.getAbsolutePath(), test ) ) ) + { + result.add( convertToJavaClassName( test ) ); + } + } + } + return new DefaultScanResult( result ); + } + + private String convertToJavaClassName( String test ) + { + return StringUtils.removeEnd( test, ".class" ).replace( FS, "." ); + } + + private String stripBaseDir( String basedir, String test ) + { + return StringUtils.removeStart( test, basedir ); + } + + private static String[] processIncludesExcludes( List list ) + { + List newList = new ArrayList(); + for ( Object aList : list ) + { + String include = (String) aList; + String[] includes = include.split( "," ); + Collections.addAll( newList, includes ); + } + + String[] incs = new String[newList.size()]; + + for ( int i = 0; i < incs.length; i++ ) + { + String inc = newList.get( i ); + if ( inc.endsWith( JAVA_SOURCE_FILE_EXTENSION ) ) + { + inc = StringUtils.removeEnd( inc, JAVA_SOURCE_FILE_EXTENSION ) + JAVA_CLASS_FILE_EXTENSION; + } + incs[i] = inc; + + } + return incs; + } +} diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/SpecificFileFilter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/SpecificFileFilter.java index 0309ed82b8..7fe38ecfcd 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/SpecificFileFilter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/util/SpecificFileFilter.java @@ -1,67 +1,67 @@ -package org.apache.maven.plugin.surefire.util; - -/* - * 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. - */ - -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; -import org.apache.maven.shared.utils.io.SelectorUtils; - -public class SpecificFileFilter -{ - - private static final char FS = System.getProperty( "file.separator" ).charAt( 0 ); - - private Set names; - - public SpecificFileFilter( String[] classNames ) - { - if ( classNames != null && classNames.length > 0 ) - { - this.names = new HashSet(); - boolean isBackslashFs = '\\' == FS; - for ( String name : classNames ) - { - names.add( isBackslashFs ? name.replace( '/', FS ) : name ); - } - Collections.addAll( names, classNames ); - } - } - - public boolean accept( String className ) - { - // If the tests enumeration is empty, allow anything. - if ( names != null && !names.isEmpty() ) - { - for ( String pattern : names ) - { - // This is the same utility used under the covers in the plexus DirectoryScanner, and - // therefore in the surefire DefaultDirectoryScanner implementation. - if ( SelectorUtils.matchPath( pattern, className, true ) ) - { - return true; - } - } - return false; - } - return true; - } - -} +package org.apache.maven.plugin.surefire.util; + +/* + * 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. + */ + +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; +import org.apache.maven.shared.utils.io.SelectorUtils; + +public class SpecificFileFilter +{ + + private static final char FS = System.getProperty( "file.separator" ).charAt( 0 ); + + private Set names; + + public SpecificFileFilter( String[] classNames ) + { + if ( classNames != null && classNames.length > 0 ) + { + this.names = new HashSet(); + boolean isBackslashFs = '\\' == FS; + for ( String name : classNames ) + { + names.add( isBackslashFs ? name.replace( '/', FS ) : name ); + } + Collections.addAll( names, classNames ); + } + } + + public boolean accept( String className ) + { + // If the tests enumeration is empty, allow anything. + if ( names != null && !names.isEmpty() ) + { + for ( String pattern : names ) + { + // This is the same utility used under the covers in the plexus DirectoryScanner, and + // therefore in the surefire DefaultDirectoryScanner implementation. + if ( SelectorUtils.matchPath( pattern, className, true ) ) + { + return true; + } + } + return false; + } + return true; + } + +} diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java index f568fa82e2..0e34754dd9 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/WrappedReportEntryTest.java @@ -1,73 +1,73 @@ -package org.apache.maven.plugin.surefire.report; -/* - * 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. - */ - -import org.apache.maven.surefire.report.ReportEntry; -import org.apache.maven.surefire.report.SimpleReportEntry; - -import junit.framework.TestCase; - -/** - * @author Kristian Rosenvold - */ -public class WrappedReportEntryTest - extends TestCase -{ - - public void testClassNameOnly() - throws Exception - { - String category = "surefire.testcase.JunitParamsTest"; - WrappedReportEntry wr = - new WrappedReportEntry( new SimpleReportEntry( "fud", category ), null, 12, null, null ); - final String reportName = wr.getReportName(); - assertEquals( "surefire.testcase.JunitParamsTest", reportName ); - } - - public void testRegular() - { - ReportEntry reportEntry = new SimpleReportEntry( "fud", "testSum(surefire.testcase.NonJunitParamsTest)" ); - WrappedReportEntry wr = new WrappedReportEntry( reportEntry, null, 12, null, null ); - final String reportName = wr.getReportName(); - assertEquals( "testSum", reportName ); - } - - public void testGetReportNameWithParams() - throws Exception - { - String category = "[0] 1\u002C 2\u002C 3 (testSum)(surefire.testcase.JunitParamsTest)"; - ReportEntry reportEntry = new SimpleReportEntry( "fud", category ); - WrappedReportEntry wr = new WrappedReportEntry( reportEntry, null, 12, null, null ); - final String reportName = wr.getReportName(); - assertEquals( "[0] 1, 2, 3 (testSum)", reportName ); - } - - public void testElapsed() - throws Exception - { - String category = "[0] 1\u002C 2\u002C 3 (testSum)(surefire.testcase.JunitParamsTest)"; - ReportEntry reportEntry = new SimpleReportEntry( "fud", category ); - WrappedReportEntry wr = new WrappedReportEntry( reportEntry, null, 12, null, null ); - String elapsedTimeSummary = wr.getElapsedTimeSummary(); - assertEquals( "[0] 1, 2, 3 (testSum)(surefire.testcase.JunitParamsTest) Time elapsed: 0.012 sec", - elapsedTimeSummary ); - } - - -} +package org.apache.maven.plugin.surefire.report; +/* + * 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. + */ + +import org.apache.maven.surefire.report.ReportEntry; +import org.apache.maven.surefire.report.SimpleReportEntry; + +import junit.framework.TestCase; + +/** + * @author Kristian Rosenvold + */ +public class WrappedReportEntryTest + extends TestCase +{ + + public void testClassNameOnly() + throws Exception + { + String category = "surefire.testcase.JunitParamsTest"; + WrappedReportEntry wr = + new WrappedReportEntry( new SimpleReportEntry( "fud", category ), null, 12, null, null ); + final String reportName = wr.getReportName(); + assertEquals( "surefire.testcase.JunitParamsTest", reportName ); + } + + public void testRegular() + { + ReportEntry reportEntry = new SimpleReportEntry( "fud", "testSum(surefire.testcase.NonJunitParamsTest)" ); + WrappedReportEntry wr = new WrappedReportEntry( reportEntry, null, 12, null, null ); + final String reportName = wr.getReportName(); + assertEquals( "testSum", reportName ); + } + + public void testGetReportNameWithParams() + throws Exception + { + String category = "[0] 1\u002C 2\u002C 3 (testSum)(surefire.testcase.JunitParamsTest)"; + ReportEntry reportEntry = new SimpleReportEntry( "fud", category ); + WrappedReportEntry wr = new WrappedReportEntry( reportEntry, null, 12, null, null ); + final String reportName = wr.getReportName(); + assertEquals( "[0] 1, 2, 3 (testSum)", reportName ); + } + + public void testElapsed() + throws Exception + { + String category = "[0] 1\u002C 2\u002C 3 (testSum)(surefire.testcase.JunitParamsTest)"; + ReportEntry reportEntry = new SimpleReportEntry( "fud", category ); + WrappedReportEntry wr = new WrappedReportEntry( reportEntry, null, 12, null, null ); + String elapsedTimeSummary = wr.getElapsedTimeSummary(); + assertEquals( "[0] 1, 2, 3 (testSum)(surefire.testcase.JunitParamsTest) Time elapsed: 0.012 sec", + elapsedTimeSummary ); + } + + +} diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java index 232f28c0f8..bf3d383bf5 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/DirectoryScannerTest.java @@ -1,60 +1,60 @@ -package org.apache.maven.plugin.surefire.util; - -/* - * 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. - */ - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Properties; -import org.apache.maven.surefire.testset.TestSetFailedException; -import org.apache.maven.surefire.util.ScanResult; - -import junit.framework.TestCase; - -/** - * @author Kristian Rosenvold - */ -public class DirectoryScannerTest - extends TestCase -{ - public void testLocateTestClasses() - throws IOException, TestSetFailedException - { - // use target as people can configure ide to compile in an other place than maven - File baseDir = new File( new File( "target/test-classes" ).getCanonicalPath() ); - List include = new ArrayList(); - include.add( "**/*ZT*A.java" ); - List exclude = new ArrayList(); - - DirectoryScanner surefireDirectoryScanner = - new DirectoryScanner( baseDir, include, exclude, new ArrayList() ); - - ScanResult classNames = surefireDirectoryScanner.scan(); - assertNotNull( classNames ); - System.out.println( "classNames " + Arrays.asList( classNames ) ); - assertEquals( 3, classNames.size() ); - - Properties props = new Properties(); - classNames.writeTo( props ); - assertEquals( 3, props.size() ); - } -} +package org.apache.maven.plugin.surefire.util; + +/* + * 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. + */ + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Properties; +import org.apache.maven.surefire.testset.TestSetFailedException; +import org.apache.maven.surefire.util.ScanResult; + +import junit.framework.TestCase; + +/** + * @author Kristian Rosenvold + */ +public class DirectoryScannerTest + extends TestCase +{ + public void testLocateTestClasses() + throws IOException, TestSetFailedException + { + // use target as people can configure ide to compile in an other place than maven + File baseDir = new File( new File( "target/test-classes" ).getCanonicalPath() ); + List include = new ArrayList(); + include.add( "**/*ZT*A.java" ); + List exclude = new ArrayList(); + + DirectoryScanner surefireDirectoryScanner = + new DirectoryScanner( baseDir, include, exclude, new ArrayList() ); + + ScanResult classNames = surefireDirectoryScanner.scan(); + assertNotNull( classNames ); + System.out.println( "classNames " + Arrays.asList( classNames ) ); + assertEquals( 3, classNames.size() ); + + Properties props = new Properties(); + classNames.writeTo( props ); + assertEquals( 3, props.size() ); + } +} diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/SpecificFileFilterTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/SpecificFileFilterTest.java index dd7fcd30b5..98d1509d5f 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/SpecificFileFilterTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/util/SpecificFileFilterTest.java @@ -1,63 +1,63 @@ -package org.apache.maven.plugin.surefire.util; - -/* - * 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. - */ - -import junit.framework.TestCase; - -/** - * @author Kristian Rosenvold - */ -public class SpecificFileFilterTest - extends TestCase -{ - public void testMatchSingleCharacterWildcard() - { - SpecificFileFilter filter = createFileFilter( "org/apache/maven/surefire/?pecificTestClassFilter.class" ); - assertTrue( filter.accept( getFile() ) ); - } - - public void testMatchSingleSegmentWordWildcard() - { - SpecificFileFilter filter = createFileFilter( "org/apache/maven/surefire/*TestClassFilter.class" ); - assertTrue( filter.accept( getFile() ) ); - } - - public void testMatchMultiSegmentWildcard() - { - SpecificFileFilter filter = createFileFilter( "org/**/SpecificTestClassFilter.class" ); - assertTrue( filter.accept( getFile() ) ); - } - - public void testMatchSingleSegmentWildcard() - { - SpecificFileFilter filter = createFileFilter( "org/*/maven/surefire/SpecificTestClassFilter.class" ); - assertTrue( filter.accept( getFile() ) ); - } - - private SpecificFileFilter createFileFilter( String s ) - { - return new SpecificFileFilter( new String[]{ s } ); - } - - private String getFile() - { - return "org/apache/maven/surefire/SpecificTestClassFilter.class"; - } -} +package org.apache.maven.plugin.surefire.util; + +/* + * 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. + */ + +import junit.framework.TestCase; + +/** + * @author Kristian Rosenvold + */ +public class SpecificFileFilterTest + extends TestCase +{ + public void testMatchSingleCharacterWildcard() + { + SpecificFileFilter filter = createFileFilter( "org/apache/maven/surefire/?pecificTestClassFilter.class" ); + assertTrue( filter.accept( getFile() ) ); + } + + public void testMatchSingleSegmentWordWildcard() + { + SpecificFileFilter filter = createFileFilter( "org/apache/maven/surefire/*TestClassFilter.class" ); + assertTrue( filter.accept( getFile() ) ); + } + + public void testMatchMultiSegmentWildcard() + { + SpecificFileFilter filter = createFileFilter( "org/**/SpecificTestClassFilter.class" ); + assertTrue( filter.accept( getFile() ) ); + } + + public void testMatchSingleSegmentWildcard() + { + SpecificFileFilter filter = createFileFilter( "org/*/maven/surefire/SpecificTestClassFilter.class" ); + assertTrue( filter.accept( getFile() ) ); + } + + private SpecificFileFilter createFileFilter( String s ) + { + return new SpecificFileFilter( new String[]{ s } ); + } + + private String getFile() + { + return "org/apache/maven/surefire/SpecificTestClassFilter.class"; + } +} diff --git a/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java b/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java index c0e4461987..ca6c4699b7 100644 --- a/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java +++ b/maven-surefire-common/src/test/java/org/apache/maven/surefire/report/RunStatisticsTest.java @@ -1,108 +1,108 @@ -package org.apache.maven.surefire.report; - -import java.util.Collection; - -import junit.framework.TestCase; - -/* - * Copyright 2002-2009 the original author or authors. - * - * Licensed 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. - * - */ - -public class RunStatisticsTest - extends TestCase -{ - private static final String Method = "AClass#AMethod"; - - private static final String DUMMY_ERROR_SOURCE = Method + " RuntimeException"; - - private static final String DUMMY_FAILURE_SOURCE = "dummy failure source"; - - private static final String DUMMY_MESSAGE = "foo"; - - public void testAddErrorSourceWithThrowableMessage() - { - RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE ); - RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable ); - assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE + " " + DUMMY_MESSAGE ); - } - - public void testAddErrorSourceWithoutThrowable() - { - RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( null ); - assertRunStatisticsHasErrorSource( statistics, Method ); - } - - public void testAddErrorSourceWithThrowableWithoutMessage() - { - RuntimeException throwable = new RuntimeException(); - RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable ); - assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE ); - } - - public void testAddFailureSourceWithThrowableMessage() - { - RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE ); - RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable ); - assertRunStatisticsHasFailureSource( statistics, DUMMY_ERROR_SOURCE + " " + DUMMY_MESSAGE ); - } - - public void testAddFailureSourceWithoutThrowable() - { - RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( null ); - assertRunStatisticsHasFailureSource( statistics, Method ); - } - - public void testAddFailureSourceWithThrowableWithoutMessage() - { - RuntimeException throwable = new RuntimeException(); - RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable ); - assertRunStatisticsHasFailureSource( statistics, DUMMY_ERROR_SOURCE ); - } - - private RunStatistics createRunStatisticsAndAddErrorSourceWithThrowable( Throwable throwable ) - { - StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter( "AClass", "AMethod", throwable ); - RunStatistics statistics = new RunStatistics(); - statistics.addErrorSource( stackTraceWriter ); - - return statistics; - } - - private RunStatistics createRunStatisticsAndAddFailureSourceWithThrowable( Throwable throwable ) - { - StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter( "AClass", "AMethod", throwable ); - RunStatistics statistics = new RunStatistics(); - statistics.addFailureSource( stackTraceWriter ); - - return statistics; - } - - private void assertRunStatisticsHasErrorSource( RunStatistics statistics, String expectedErrorSource ) - { - Collection errorSources = statistics.getErrorSources(); - assertNotNull( "No error sources.", errorSources ); - assertEquals( "Wrong number of error sources.", 1, errorSources.size() ); - assertEquals( "Wrong error sources.", expectedErrorSource, errorSources.iterator().next() ); - } - - private void assertRunStatisticsHasFailureSource( RunStatistics statistics, String expectedFailureSource ) - { - Collection failureSources = statistics.getFailureSources(); - assertNotNull( "No failure sources.", failureSources ); - assertEquals( "Wrong number of failure sources.", 1, failureSources.size() ); - assertEquals( "Wrong failure sources.", expectedFailureSource, failureSources.iterator().next() ); - } -} +package org.apache.maven.surefire.report; + +import java.util.Collection; + +import junit.framework.TestCase; + +/* + * Copyright 2002-2009 the original author or authors. + * + * Licensed 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. + * + */ + +public class RunStatisticsTest + extends TestCase +{ + private static final String Method = "AClass#AMethod"; + + private static final String DUMMY_ERROR_SOURCE = Method + " RuntimeException"; + + private static final String DUMMY_FAILURE_SOURCE = "dummy failure source"; + + private static final String DUMMY_MESSAGE = "foo"; + + public void testAddErrorSourceWithThrowableMessage() + { + RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE ); + RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable ); + assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE + " " + DUMMY_MESSAGE ); + } + + public void testAddErrorSourceWithoutThrowable() + { + RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( null ); + assertRunStatisticsHasErrorSource( statistics, Method ); + } + + public void testAddErrorSourceWithThrowableWithoutMessage() + { + RuntimeException throwable = new RuntimeException(); + RunStatistics statistics = createRunStatisticsAndAddErrorSourceWithThrowable( throwable ); + assertRunStatisticsHasErrorSource( statistics, DUMMY_ERROR_SOURCE ); + } + + public void testAddFailureSourceWithThrowableMessage() + { + RuntimeException throwable = new RuntimeException( DUMMY_MESSAGE ); + RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable ); + assertRunStatisticsHasFailureSource( statistics, DUMMY_ERROR_SOURCE + " " + DUMMY_MESSAGE ); + } + + public void testAddFailureSourceWithoutThrowable() + { + RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( null ); + assertRunStatisticsHasFailureSource( statistics, Method ); + } + + public void testAddFailureSourceWithThrowableWithoutMessage() + { + RuntimeException throwable = new RuntimeException(); + RunStatistics statistics = createRunStatisticsAndAddFailureSourceWithThrowable( throwable ); + assertRunStatisticsHasFailureSource( statistics, DUMMY_ERROR_SOURCE ); + } + + private RunStatistics createRunStatisticsAndAddErrorSourceWithThrowable( Throwable throwable ) + { + StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter( "AClass", "AMethod", throwable ); + RunStatistics statistics = new RunStatistics(); + statistics.addErrorSource( stackTraceWriter ); + + return statistics; + } + + private RunStatistics createRunStatisticsAndAddFailureSourceWithThrowable( Throwable throwable ) + { + StackTraceWriter stackTraceWriter = new LegacyPojoStackTraceWriter( "AClass", "AMethod", throwable ); + RunStatistics statistics = new RunStatistics(); + statistics.addFailureSource( stackTraceWriter ); + + return statistics; + } + + private void assertRunStatisticsHasErrorSource( RunStatistics statistics, String expectedErrorSource ) + { + Collection errorSources = statistics.getErrorSources(); + assertNotNull( "No error sources.", errorSources ); + assertEquals( "Wrong number of error sources.", 1, errorSources.size() ); + assertEquals( "Wrong error sources.", expectedErrorSource, errorSources.iterator().next() ); + } + + private void assertRunStatisticsHasFailureSource( RunStatistics statistics, String expectedFailureSource ) + { + Collection failureSources = statistics.getFailureSources(); + assertNotNull( "No failure sources.", failureSources ); + assertEquals( "Wrong number of failure sources.", 1, failureSources.size() ); + assertEquals( "Wrong failure sources.", expectedFailureSource, failureSources.iterator().next() ); + } +} diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleReporter.java b/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleReporter.java index edb733ff36..6c5c850c05 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleReporter.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleReporter.java @@ -1,41 +1,41 @@ -package org.apache.maven.surefire.report; - -/* - * 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. - */ - -import java.io.PrintStream; - -/** - * @author Kristian Rosenvold - */ -public class DefaultConsoleReporter - implements ConsoleLogger -{ - private final PrintStream systemOut; - - public DefaultConsoleReporter( PrintStream systemOut ) - { - this.systemOut = systemOut; - } - - public void info( String message ) - { - systemOut.println( message ); - } -} +package org.apache.maven.surefire.report; + +/* + * 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. + */ + +import java.io.PrintStream; + +/** + * @author Kristian Rosenvold + */ +public class DefaultConsoleReporter + implements ConsoleLogger +{ + private final PrintStream systemOut; + + public DefaultConsoleReporter( PrintStream systemOut ) + { + this.systemOut = systemOut; + } + + public void info( String message ) + { + systemOut.println( message ); + } +} diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultDirectConsoleReporter.java b/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultDirectConsoleReporter.java index 3f341c3608..caee844d72 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultDirectConsoleReporter.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultDirectConsoleReporter.java @@ -1,40 +1,40 @@ -package org.apache.maven.surefire.report; -/* - * 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. - */ - -import java.io.PrintStream; - -/** - * @author Kristian Rosenvold - */ -public class DefaultDirectConsoleReporter - implements ConsoleLogger -{ - private final PrintStream systemOut; - - public DefaultDirectConsoleReporter( PrintStream systemOut ) - { - this.systemOut = systemOut; - } - - public void info( String message ) - { - systemOut.println( message ); - } -} +package org.apache.maven.surefire.report; +/* + * 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. + */ + +import java.io.PrintStream; + +/** + * @author Kristian Rosenvold + */ +public class DefaultDirectConsoleReporter + implements ConsoleLogger +{ + private final PrintStream systemOut; + + public DefaultDirectConsoleReporter( PrintStream systemOut ) + { + this.systemOut = systemOut; + } + + public void info( String message ) + { + systemOut.println( message ); + } +} diff --git a/surefire-integration-tests/src/test/resources/ant-ignore/.gitignore b/surefire-integration-tests/src/test/resources/ant-ignore/.gitignore index 1f82a8b6e4..2d7276b9ef 100644 --- a/surefire-integration-tests/src/test/resources/ant-ignore/.gitignore +++ b/surefire-integration-tests/src/test/resources/ant-ignore/.gitignore @@ -1,3 +1,3 @@ -*.jar -TEST* - +*.jar +TEST* + diff --git a/surefire-integration-tests/src/test/resources/ant-ignore/build.xml b/surefire-integration-tests/src/test/resources/ant-ignore/build.xml index 0ef0cfee4e..69795d002d 100644 --- a/surefire-integration-tests/src/test/resources/ant-ignore/build.xml +++ b/surefire-integration-tests/src/test/resources/ant-ignore/build.xml @@ -1,52 +1,52 @@ - - - simple example build file - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + simple example build file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/surefire-integration-tests/src/test/resources/ant-ignore/ivy.xml b/surefire-integration-tests/src/test/resources/ant-ignore/ivy.xml index d350225f6d..64df19cf19 100644 --- a/surefire-integration-tests/src/test/resources/ant-ignore/ivy.xml +++ b/surefire-integration-tests/src/test/resources/ant-ignore/ivy.xml @@ -1,6 +1,6 @@ - - - - - - + + + + + + diff --git a/surefire-integration-tests/src/test/resources/ant-ignore/src/ivy.xml b/surefire-integration-tests/src/test/resources/ant-ignore/src/ivy.xml index d350225f6d..64df19cf19 100644 --- a/surefire-integration-tests/src/test/resources/ant-ignore/src/ivy.xml +++ b/surefire-integration-tests/src/test/resources/ant-ignore/src/ivy.xml @@ -1,6 +1,6 @@ - - - - - - + + + + + + diff --git a/surefire-integration-tests/src/test/resources/failingBuilds/src/test/java/failingbuilds/ExceptionsTest.java b/surefire-integration-tests/src/test/resources/failingBuilds/src/test/java/failingbuilds/ExceptionsTest.java index 1cfdd9199c..ede031b491 100644 --- a/surefire-integration-tests/src/test/resources/failingBuilds/src/test/java/failingbuilds/ExceptionsTest.java +++ b/surefire-integration-tests/src/test/resources/failingBuilds/src/test/java/failingbuilds/ExceptionsTest.java @@ -1,19 +1,19 @@ -package failingbuilds; - -import org.junit.Test; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assume.*; - -import junit.framework.TestCase; - -public class ExceptionsTest - extends TestCase -{ - public void testWithMultiLineExceptionBeingThrown() - { - throw new RuntimeException( "A very very long exception message indeed, which is to demonstrate truncation. It will be truncated somewhere\nA cat\nAnd a dog\nTried to make a\nParrot swim" ); - } +package failingbuilds; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assume.*; + +import junit.framework.TestCase; + +public class ExceptionsTest + extends TestCase +{ + public void testWithMultiLineExceptionBeingThrown() + { + throw new RuntimeException( "A very very long exception message indeed, which is to demonstrate truncation. It will be truncated somewhere\nA cat\nAnd a dog\nTried to make a\nParrot swim" ); + } } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeClassError.java b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeClassError.java index 7791734292..0e80332ea3 100644 --- a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeClassError.java +++ b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeClassError.java @@ -1,43 +1,43 @@ -package failureresultcounting; -/* - * 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. - */ - - -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * @author Kristian Rosenvold - */ -public class BeforeClassError -{ - - @BeforeClass - public static void beforeClassError() - { - throw new RuntimeException( "Exception in beforeclass" ); - } - - @Test - public void ok() - { - System.out.println( "beforeClassError run !!" ); - } - +package failureresultcounting; +/* + * 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. + */ + + +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @author Kristian Rosenvold + */ +public class BeforeClassError +{ + + @BeforeClass + public static void beforeClassError() + { + throw new RuntimeException( "Exception in beforeclass" ); + } + + @Test + public void ok() + { + System.out.println( "beforeClassError run !!" ); + } + } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeClassFailure.java b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeClassFailure.java index 5ef3f16db5..62d51acc20 100644 --- a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeClassFailure.java +++ b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeClassFailure.java @@ -1,43 +1,43 @@ -package failureresultcounting; -/* - * 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. - */ - -import junit.framework.Assert; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * @author Kristian Rosenvold - */ -public class BeforeClassFailure -{ - - @BeforeClass - public static void failInBeforeClass() - { - Assert.fail( "Failing in @BeforeClass" ); - } - - @Test - public void ok() - { - System.out.println( "failInBeforeClass run !!"); - } - +package failureresultcounting; +/* + * 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. + */ + +import junit.framework.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * @author Kristian Rosenvold + */ +public class BeforeClassFailure +{ + + @BeforeClass + public static void failInBeforeClass() + { + Assert.fail( "Failing in @BeforeClass" ); + } + + @Test + public void ok() + { + System.out.println( "failInBeforeClass run !!"); + } + } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeError.java b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeError.java index 1422580b49..0798c80c51 100644 --- a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeError.java +++ b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeError.java @@ -1,48 +1,48 @@ -package failureresultcounting; -/* - * 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. - */ - -import org.junit.Before; -import org.junit.Test; - -/** - * @author Kristian Rosenvold - */ -public class BeforeError -{ - - @Before - public void exceptionInBefore() - { - throw new RuntimeException( "Exception in @before" ); - } - - @Test - public void ok() - { - System.out.println( "exceptionInBefore run!!"); - } - - /*@Test - public void ok2() - { - System.out.println( "exceptionInBefore2 run!!"); - } */ - +package failureresultcounting; +/* + * 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. + */ + +import org.junit.Before; +import org.junit.Test; + +/** + * @author Kristian Rosenvold + */ +public class BeforeError +{ + + @Before + public void exceptionInBefore() + { + throw new RuntimeException( "Exception in @before" ); + } + + @Test + public void ok() + { + System.out.println( "exceptionInBefore run!!"); + } + + /*@Test + public void ok2() + { + System.out.println( "exceptionInBefore2 run!!"); + } */ + } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeFailure.java b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeFailure.java index 379827f9d1..174a448928 100644 --- a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeFailure.java +++ b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/BeforeFailure.java @@ -1,43 +1,43 @@ -package failureresultcounting; -/* - * 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. - */ - -import junit.framework.Assert; -import org.junit.Before; -import org.junit.Test; - -/** - * @author Kristian Rosenvold - */ -public class BeforeFailure -{ - - @Before - public void failInBEfore() - { - Assert.fail( "Failing in @before" ); - } - - @Test - public void ok() - { - System.out.println( "failInBEfore run !!"); - } - +package failureresultcounting; +/* + * 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. + */ + +import junit.framework.Assert; +import org.junit.Before; +import org.junit.Test; + +/** + * @author Kristian Rosenvold + */ +public class BeforeFailure +{ + + @Before + public void failInBEfore() + { + Assert.fail( "Failing in @before" ); + } + + @Test + public void ok() + { + System.out.println( "failInBEfore run !!"); + } + } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/NoErrors.java b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/NoErrors.java index dd6f79ae13..245c9a65b6 100644 --- a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/NoErrors.java +++ b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/NoErrors.java @@ -1,43 +1,43 @@ -package failureresultcounting; -/* - * 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. - */ - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -/** - * @author Kristian Rosenvold - */ -public class NoErrors -{ - - @Test - @Ignore - public void allOk1() - { - } - - @Test - @Ignore - public void allOk2() - { - } - +package failureresultcounting; +/* + * 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. + */ + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; + +/** + * @author Kristian Rosenvold + */ +public class NoErrors +{ + + @Test + @Ignore + public void allOk1() + { + } + + @Test + @Ignore + public void allOk2() + { + } + } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/OrdinaryError.java b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/OrdinaryError.java index d79d145105..7e6387aa8b 100644 --- a/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/OrdinaryError.java +++ b/surefire-integration-tests/src/test/resources/failure-result-counting/src/test/java/failureresultcounting/OrdinaryError.java @@ -1,42 +1,42 @@ -package failureresultcounting; -/* - * 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. - */ - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author Kristian Rosenvold - */ -public class OrdinaryError -{ - - @Test - public void ordinaryEror() - { - throw new RuntimeException( "Exception in @before" ); - } - - @Test - public void ordinaryFailure() - { - Assert.fail(); - } - +package failureresultcounting; +/* + * 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. + */ + +import org.junit.Assert; +import org.junit.Test; + +/** + * @author Kristian Rosenvold + */ +public class OrdinaryError +{ + + @Test + public void ordinaryEror() + { + throw new RuntimeException( "Exception in @before" ); + } + + @Test + public void ordinaryFailure() + { + Assert.fail(); + } + } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest1.java b/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest1.java index cab285eafe..0e0794598e 100644 --- a/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest1.java +++ b/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest1.java @@ -1,24 +1,24 @@ -package resultcounting; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class MySuiteTest1 extends TestCase { - - public static Test suite () { - TestSuite suite = new TestSuite(); - - suite.addTest (new MySuiteTest1("testMe" )); - - return suite; - } - - public MySuiteTest1( String name ) { - super (name); - } - - public void testMe() { - assertTrue (true); - } -} +package resultcounting; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class MySuiteTest1 extends TestCase { + + public static Test suite () { + TestSuite suite = new TestSuite(); + + suite.addTest (new MySuiteTest1("testMe" )); + + return suite; + } + + public MySuiteTest1( String name ) { + super (name); + } + + public void testMe() { + assertTrue (true); + } +} diff --git a/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest2.java b/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest2.java index ae71b47425..0c44f044c7 100644 --- a/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest2.java +++ b/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest2.java @@ -1,25 +1,25 @@ -package resultcounting; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class MySuiteTest2 extends TestCase { - - public static Test suite () { - TestSuite suite = new TestSuite(); - - suite.addTest (new MySuiteTest2("testMe" )); - suite.addTest (new MySuiteTest2("testMe" )); - - return suite; - } - - public MySuiteTest2( String name ) { - super (name); - } - - public void testMe() { - assertTrue (true); - } -} +package resultcounting; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class MySuiteTest2 extends TestCase { + + public static Test suite () { + TestSuite suite = new TestSuite(); + + suite.addTest (new MySuiteTest2("testMe" )); + suite.addTest (new MySuiteTest2("testMe" )); + + return suite; + } + + public MySuiteTest2( String name ) { + super (name); + } + + public void testMe() { + assertTrue (true); + } +} diff --git a/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest3.java b/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest3.java index a60993adaf..4c08224661 100644 --- a/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest3.java +++ b/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/MySuiteTest3.java @@ -1,26 +1,26 @@ -package resultcounting; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class MySuiteTest3 extends TestCase { - - public static Test suite () { - TestSuite suite = new TestSuite(); - - suite.addTest (new MySuiteTest3("testMe" )); - suite.addTest (new MySuiteTest3("testMe" )); - suite.addTest (new MySuiteTest3("testMe" )); - - return suite; - } - - public MySuiteTest3( String name ) { - super (name); - } - - public void testMe() { - assertTrue (true); - } -} +package resultcounting; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class MySuiteTest3 extends TestCase { + + public static Test suite () { + TestSuite suite = new TestSuite(); + + suite.addTest (new MySuiteTest3("testMe" )); + suite.addTest (new MySuiteTest3("testMe" )); + suite.addTest (new MySuiteTest3("testMe" )); + + return suite; + } + + public MySuiteTest3( String name ) { + super (name); + } + + public void testMe() { + assertTrue (true); + } +} diff --git a/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/Test1.java b/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/Test1.java index 6833e0ecdc..c3283d2be6 100644 --- a/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/Test1.java +++ b/surefire-integration-tests/src/test/resources/result-counting/src/test/java/resultcounting/Test1.java @@ -1,76 +1,76 @@ -package resultcounting; -/* - * 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. - */ - -import org.junit.Test; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assume.*; -import junit.framework.TestCase; - -public class Test1 extends TestCase -{ - public void testWithFailingAssumption1() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption2() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption3() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption4() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption5() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption6() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption7() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption8() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption9() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption10() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption11() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption12() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption13() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption14() { - assumeThat( 2, is(3)); - } - public void testWithFailingAssumption15() { - assumeThat( 2, is(3)); - } +package resultcounting; +/* + * 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. + */ + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.hamcrest.CoreMatchers.*; +import static org.junit.Assume.*; +import junit.framework.TestCase; + +public class Test1 extends TestCase +{ + public void testWithFailingAssumption1() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption2() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption3() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption4() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption5() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption6() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption7() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption8() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption9() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption10() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption11() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption12() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption13() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption14() { + assumeThat( 2, is(3)); + } + public void testWithFailingAssumption15() { + assumeThat( 2, is(3)); + } } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test1.java b/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test1.java index 8a0fd3d521..66c7337dc3 100644 --- a/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test1.java +++ b/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test1.java @@ -1,47 +1,47 @@ -package smallresultcounting; - -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assume.assumeThat; - -public class Test1 -{ - @Test - public void testWithFailingAssumption1() - { - assumeThat( 2, is( 3 ) ); - } - - @Test - public void testWithFailingAssumption2() - { - try - { - Thread.sleep( 150 ); - } - catch ( InterruptedException ignore ) - { - } - - assumeThat( 2, is( 3 ) ); - } - - @Test - public void testWithFailingAssumption3() - { - assumeThat( 2, is( 3 ) ); - } - - @Test - public void testWithFailingAssumption4() - { - assumeThat( 2, is( 3 ) ); - } - - @Test - public void testWithFailingAssumption5() - { - assumeThat( 2, is( 3 ) ); - } +package smallresultcounting; + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assume.assumeThat; + +public class Test1 +{ + @Test + public void testWithFailingAssumption1() + { + assumeThat( 2, is( 3 ) ); + } + + @Test + public void testWithFailingAssumption2() + { + try + { + Thread.sleep( 150 ); + } + catch ( InterruptedException ignore ) + { + } + + assumeThat( 2, is( 3 ) ); + } + + @Test + public void testWithFailingAssumption3() + { + assumeThat( 2, is( 3 ) ); + } + + @Test + public void testWithFailingAssumption4() + { + assumeThat( 2, is( 3 ) ); + } + + @Test + public void testWithFailingAssumption5() + { + assumeThat( 2, is( 3 ) ); + } } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test2.java b/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test2.java index 5f7459f944..dbacce7d84 100644 --- a/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test2.java +++ b/surefire-integration-tests/src/test/resources/small-result-counting/src/test/java/smallresultcounting/Test2.java @@ -1,88 +1,88 @@ -package smallresultcounting; - -import org.junit.Ignore; -import org.junit.Test; - -import static junit.framework.Assert.fail; - -/** - * @author Kristian Rosenvold - */ -public class Test2 -{ - @Test - public void testiWithFail1() - { - fail( "We excpect this1" ); - } - - @Test - public void testWithException1() - { - System.out.println( "testWithException1 to stdout" ); - System.err.println( "testWithException1 to stderr" ); - throw new RuntimeException( "We expect this1-1" ); - } - - @Test - public void testWithException2() - { - throw new RuntimeException( "We expect this1-2" ); - } - - - @Ignore( "We do this for a reason1" ) - @Test - public void testWithIgnore1() - { - } - - @Ignore( "We do this for a reason2" ) - @Test - public void testWithIgnore2() - { - } - - @Ignore - @Test - public void testWithIgnore3() - { - } - - @Test - public void testAllok1() - { - System.out.println( "testAllok1 to stdout" ); - System.err.println( "testAllok1 to stderr" ); - try - { - Thread.sleep( 100 ); - } - catch ( InterruptedException ignore ) - { - } - } - - @Test - public void testAllok2() - { - } - - @Test - public void testAllok3() - { - try - { - Thread.sleep( 250 ); - } - catch ( InterruptedException ignore ) - { - } - } - - @Test - public void testAllok4() - { - } - +package smallresultcounting; + +import org.junit.Ignore; +import org.junit.Test; + +import static junit.framework.Assert.fail; + +/** + * @author Kristian Rosenvold + */ +public class Test2 +{ + @Test + public void testiWithFail1() + { + fail( "We excpect this1" ); + } + + @Test + public void testWithException1() + { + System.out.println( "testWithException1 to stdout" ); + System.err.println( "testWithException1 to stderr" ); + throw new RuntimeException( "We expect this1-1" ); + } + + @Test + public void testWithException2() + { + throw new RuntimeException( "We expect this1-2" ); + } + + + @Ignore( "We do this for a reason1" ) + @Test + public void testWithIgnore1() + { + } + + @Ignore( "We do this for a reason2" ) + @Test + public void testWithIgnore2() + { + } + + @Ignore + @Test + public void testWithIgnore3() + { + } + + @Test + public void testAllok1() + { + System.out.println( "testAllok1 to stdout" ); + System.err.println( "testAllok1 to stderr" ); + try + { + Thread.sleep( 100 ); + } + catch ( InterruptedException ignore ) + { + } + } + + @Test + public void testAllok2() + { + } + + @Test + public void testAllok3() + { + try + { + Thread.sleep( 250 ); + } + catch ( InterruptedException ignore ) + { + } + } + + @Test + public void testAllok4() + { + } + } \ No newline at end of file diff --git a/surefire-integration-tests/src/test/resources/surefire-500-puzzling-error/src/test/java/surefire500/PassingTest.java b/surefire-integration-tests/src/test/resources/surefire-500-puzzling-error/src/test/java/surefire500/PassingTest.java index a87f46d2b6..ea15f449da 100644 --- a/surefire-integration-tests/src/test/resources/surefire-500-puzzling-error/src/test/java/surefire500/PassingTest.java +++ b/surefire-integration-tests/src/test/resources/surefire-500-puzzling-error/src/test/java/surefire500/PassingTest.java @@ -1,33 +1,33 @@ -package surefire500; - -import org.junit.Test; - -import static org.junit.Assert.assertTrue; - -public class PassingTest { - - @Test - public void testOne() - { - assertTrue(true); - } - - @Test - public void testTwo() - { - assertTrue(true); - } - - @Test - public void testThree() - { - assertTrue(true); - } - - @Test - public void testFour() - { - assertTrue(true); - } - -} +package surefire500; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class PassingTest { + + @Test + public void testOne() + { + assertTrue(true); + } + + @Test + public void testTwo() + { + assertTrue(true); + } + + @Test + public void testThree() + { + assertTrue(true); + } + + @Test + public void testFour() + { + assertTrue(true); + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-500-puzzling-error/src/test/java/surefire500/Suite.java b/surefire-integration-tests/src/test/resources/surefire-500-puzzling-error/src/test/java/surefire500/Suite.java index d039713487..59e5a428d6 100644 --- a/surefire-integration-tests/src/test/resources/surefire-500-puzzling-error/src/test/java/surefire500/Suite.java +++ b/surefire-integration-tests/src/test/resources/surefire-500-puzzling-error/src/test/java/surefire500/Suite.java @@ -1,10 +1,10 @@ -package surefire500; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite.SuiteClasses; - -@RunWith(org.junit.runners.Suite.class) -@SuiteClasses(value={ExplodingTest.class, PassingTest.class}) -public class Suite { - -} +package surefire500; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite.SuiteClasses; + +@RunWith(org.junit.runners.Suite.class) +@SuiteClasses(value={ExplodingTest.class, PassingTest.class}) +public class Suite { + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest1.java b/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest1.java index a3fde44977..f836baaa43 100644 --- a/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest1.java +++ b/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest1.java @@ -1,29 +1,29 @@ -package mho; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - - -public class MySuiteTest1 extends TestCase { - - public static Test suite () { - TestSuite suite = new TestSuite(); - - suite.addTest (new MySuiteTest1("testMe", 1)); - - return suite; - } - - private final int number; - - public MySuiteTest1(String name, int number) { - super (name); - this.number = number; - } - - public void testMe() { - System.out.println ("### "+ this.getClass().getName()+":"+this.getName()+" - number "+number); - assertTrue (true); - } -} +package mho; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + + +public class MySuiteTest1 extends TestCase { + + public static Test suite () { + TestSuite suite = new TestSuite(); + + suite.addTest (new MySuiteTest1("testMe", 1)); + + return suite; + } + + private final int number; + + public MySuiteTest1(String name, int number) { + super (name); + this.number = number; + } + + public void testMe() { + System.out.println ("### "+ this.getClass().getName()+":"+this.getName()+" - number "+number); + assertTrue (true); + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest2.java b/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest2.java index 79875694f9..09644db32c 100644 --- a/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest2.java +++ b/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest2.java @@ -1,30 +1,30 @@ -package mho; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - - -public class MySuiteTest2 extends TestCase { - - public static Test suite () { - TestSuite suite = new TestSuite(); - - suite.addTest (new MySuiteTest2("testMe", 1)); - suite.addTest (new MySuiteTest2("testMe", 2)); - - return suite; - } - - private final int number; - - public MySuiteTest2(String name, int number) { - super (name); - this.number = number; - } - - public void testMe() { - System.out.println ("### "+ this.getClass().getName()+":"+this.getName()+" - number "+number); - assertTrue (true); - } -} +package mho; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + + +public class MySuiteTest2 extends TestCase { + + public static Test suite () { + TestSuite suite = new TestSuite(); + + suite.addTest (new MySuiteTest2("testMe", 1)); + suite.addTest (new MySuiteTest2("testMe", 2)); + + return suite; + } + + private final int number; + + public MySuiteTest2(String name, int number) { + super (name); + this.number = number; + } + + public void testMe() { + System.out.println ("### "+ this.getClass().getName()+":"+this.getName()+" - number "+number); + assertTrue (true); + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest3.java b/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest3.java index aa979b492e..39ca6e323f 100644 --- a/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest3.java +++ b/surefire-integration-tests/src/test/resources/surefire-621-testCounting-junit3-in-parallel/src/it/java/mho/MySuiteTest3.java @@ -1,30 +1,30 @@ -package mho; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class MySuiteTest3 extends TestCase { - - public static Test suite () { - TestSuite suite = new TestSuite(); - - suite.addTest (new MySuiteTest3("testMe", 1)); - suite.addTest (new MySuiteTest3("testMe", 2)); - suite.addTest (new MySuiteTest3("testMe", 3)); - - return suite; - } - - private final int number; - - public MySuiteTest3(String name, int number) { - super (name); - this.number = number; - } - - public void testMe() { - System.out.println ("### "+ this.getClass().getName()+":"+this.getName()+" - number "+number); - assertTrue (true); - } -} +package mho; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class MySuiteTest3 extends TestCase { + + public static Test suite () { + TestSuite suite = new TestSuite(); + + suite.addTest (new MySuiteTest3("testMe", 1)); + suite.addTest (new MySuiteTest3("testMe", 2)); + suite.addTest (new MySuiteTest3("testMe", 3)); + + return suite; + } + + private final int number; + + public MySuiteTest3(String name, int number) { + super (name); + this.number = number; + } + + public void testMe() { + System.out.println ("### "+ this.getClass().getName()+":"+this.getName()+" - number "+number); + assertTrue (true); + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestA.java b/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestA.java index aaee6f7289..b34e4100a0 100644 --- a/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestA.java +++ b/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestA.java @@ -1,29 +1,29 @@ -package surefire685; -/* - * 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. - */ - -import junit.framework.TestCase; - - -public class TestA - extends TestCase -{ - public void testTwo() { - } -} +package surefire685; +/* + * 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. + */ + +import junit.framework.TestCase; + + +public class TestA + extends TestCase +{ + public void testTwo() { + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestB.java b/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestB.java index 43cf56d98e..6e272d709d 100644 --- a/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestB.java +++ b/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestB.java @@ -1,29 +1,29 @@ -package surefire685; -/* - * 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. - */ - -import junit.framework.TestCase; - - -public class TestB - extends TestCase -{ - public void testTwo() { - } -} +package surefire685; +/* + * 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. + */ + +import junit.framework.TestCase; + + +public class TestB + extends TestCase +{ + public void testTwo() { + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestC.java b/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestC.java index 35e246d6ef..68bd647eae 100644 --- a/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestC.java +++ b/surefire-integration-tests/src/test/resources/surefire-685-commaseparatedIncludes/src/test/java/surefire685/TestC.java @@ -1,29 +1,29 @@ -package surefire685; -/* - * 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. - */ - -import junit.framework.TestCase; - - -public class TestC - extends TestCase -{ - public void testTwo() { - } -} +package surefire685; +/* + * 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. + */ + +import junit.framework.TestCase; + + +public class TestC + extends TestCase +{ + public void testTwo() { + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/pom.xml b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/pom.xml index 6a5dde5340..08768f7575 100644 --- a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/pom.xml +++ b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/pom.xml @@ -1,37 +1,37 @@ - - 4.0.0 - test - cyril - 0.0.1-SNAPSHOT - cyril - - - - junit - junit - 4.4 - test - - - jmock - jmock - 1.1.0 - test - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.5.1 - - - maven-surefire-plugin - ${surefire.version} - - - - + + 4.0.0 + test + cyril + 0.0.1-SNAPSHOT + cyril + + + + junit + junit + 4.4 + test + + + jmock + jmock + 1.1.0 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.5.1 + + + maven-surefire-plugin + ${surefire.version} + + + + diff --git a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/FirstTest.java b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/FirstTest.java index 12d305c919..12cb23efed 100644 --- a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/FirstTest.java +++ b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/FirstTest.java @@ -1,36 +1,36 @@ -package cyril.test; - - -import org.jmock.Mock; -import org.jmock.MockObjectTestCase; -import org.junit.Test; - - -public class FirstTest - extends MockObjectTestCase -{ - - private Mock myServiceMock; - - @Override - protected void setUp() - throws Exception - { - myServiceMock = mock( MyService.class ); - } - - - @Test - public void test() - { - - Message myMessage = new Message( "MyMessage" ); - // Expectations - myServiceMock.expects( once() ).method( "writeMessage" ).with( eq( myMessage ) ).will( - returnValue( myMessage ) ); - - ( (MyService) myServiceMock.proxy() ).writeMessage( null ); - - } - -} +package cyril.test; + + +import org.jmock.Mock; +import org.jmock.MockObjectTestCase; +import org.junit.Test; + + +public class FirstTest + extends MockObjectTestCase +{ + + private Mock myServiceMock; + + @Override + protected void setUp() + throws Exception + { + myServiceMock = mock( MyService.class ); + } + + + @Test + public void test() + { + + Message myMessage = new Message( "MyMessage" ); + // Expectations + myServiceMock.expects( once() ).method( "writeMessage" ).with( eq( myMessage ) ).will( + returnValue( myMessage ) ); + + ( (MyService) myServiceMock.proxy() ).writeMessage( null ); + + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/IgnoredTest.java b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/IgnoredTest.java index 80ff3120a2..02250ee924 100644 --- a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/IgnoredTest.java +++ b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/IgnoredTest.java @@ -1,16 +1,16 @@ -package cyril.test; - -import org.junit.Test; - - -public class IgnoredTest -{ - - - @Test - public void test() - { - System.out.println( "My test is running fine" ); - } - -} +package cyril.test; + +import org.junit.Test; + + +public class IgnoredTest +{ + + + @Test + public void test() + { + System.out.println( "My test is running fine" ); + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/Message.java b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/Message.java index c3e4249ae1..0c08805154 100644 --- a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/Message.java +++ b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/Message.java @@ -1,18 +1,18 @@ -package cyril.test; - -public class Message -{ - - private String content; - - public Message( String content ) - { - this.content = content; - } - - public int hashCode() - { - throw new NullPointerException(); - } - -} +package cyril.test; + +public class Message +{ + + private String content; + + public Message( String content ) + { + this.content = content; + } + + public int hashCode() + { + throw new NullPointerException(); + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/MyService.java b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/MyService.java index 892351f8d8..8fa59f709c 100644 --- a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/MyService.java +++ b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/MyService.java @@ -1,8 +1,8 @@ -package cyril.test; - -public interface MyService -{ - - public Message writeMessage( Message aMessage ); - -} +package cyril.test; + +public interface MyService +{ + + public Message writeMessage( Message aMessage ); + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/MyServiceImpl.java b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/MyServiceImpl.java index fc7f2b9ef1..f390ade5a3 100644 --- a/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/MyServiceImpl.java +++ b/surefire-integration-tests/src/test/resources/surefire-818-ignored-tests-on-npe/src/test/java/cyril/test/MyServiceImpl.java @@ -1,12 +1,12 @@ -package cyril.test; - -public class MyServiceImpl - implements MyService -{ - - public Message writeMessage( Message aMessage ) - { - return aMessage; - } - -} +package cyril.test; + +public class MyServiceImpl + implements MyService +{ + + public Message writeMessage( Message aMessage ) + { + return aMessage; + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-822-legal-JUnit4-descriptions/src/test/java/surefire/testcase/JunitParamsTest.java b/surefire-integration-tests/src/test/resources/surefire-822-legal-JUnit4-descriptions/src/test/java/surefire/testcase/JunitParamsTest.java index 42f59519ba..3ccd814296 100644 --- a/surefire-integration-tests/src/test/resources/surefire-822-legal-JUnit4-descriptions/src/test/java/surefire/testcase/JunitParamsTest.java +++ b/surefire-integration-tests/src/test/resources/surefire-822-legal-JUnit4-descriptions/src/test/java/surefire/testcase/JunitParamsTest.java @@ -1,51 +1,51 @@ -package surefire.testcase; -/* - * 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. - */ - -import java.util.Arrays; -import java.util.Collection; - -import junitparams.JUnitParamsRunner; -import junitparams.Parameters; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -/** - * Surefire JunitParams test. - */ -@RunWith( JUnitParamsRunner.class ) -public class JunitParamsTest -{ - - @Parameters( method = "parameters" ) - @Test - public void testSum( int a, int b, int expected ) - { - assertThat( a + b, equalTo( expected ) ); - } - - public Collection parameters() - { - Integer[][] parameters = { { 1, 2, 3 }, { 2, 3, 5 }, { 3, 4, 7 }, }; - return Arrays.asList( parameters ); - } -} +package surefire.testcase; +/* + * 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. + */ + +import java.util.Arrays; +import java.util.Collection; + +import junitparams.JUnitParamsRunner; +import junitparams.Parameters; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +/** + * Surefire JunitParams test. + */ +@RunWith( JUnitParamsRunner.class ) +public class JunitParamsTest +{ + + @Parameters( method = "parameters" ) + @Test + public void testSum( int a, int b, int expected ) + { + assertThat( a + b, equalTo( expected ) ); + } + + public Collection parameters() + { + Integer[][] parameters = { { 1, 2, 3 }, { 2, 3, 5 }, { 3, 4, 7 }, }; + return Arrays.asList( parameters ); + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-822-legal-JUnit4-descriptions/src/test/java/surefire/testcase/NonJunitParamsTest.java b/surefire-integration-tests/src/test/resources/surefire-822-legal-JUnit4-descriptions/src/test/java/surefire/testcase/NonJunitParamsTest.java index fc70b2e44c..6cffeeb6a8 100644 --- a/surefire-integration-tests/src/test/resources/surefire-822-legal-JUnit4-descriptions/src/test/java/surefire/testcase/NonJunitParamsTest.java +++ b/surefire-integration-tests/src/test/resources/surefire-822-legal-JUnit4-descriptions/src/test/java/surefire/testcase/NonJunitParamsTest.java @@ -1,37 +1,37 @@ -package surefire.testcase; -/* - * 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. - */ - -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.equalTo; -import static org.junit.Assert.assertThat; - -/** - * Surefire non-JunitParams test. - */ -public class NonJunitParamsTest -{ - - @Test - public void testSum() - { - assertThat( 1 + 2, equalTo( 3 ) ); - } -} +package surefire.testcase; +/* + * 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. + */ + +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.junit.Assert.assertThat; + +/** + * Surefire non-JunitParams test. + */ +public class NonJunitParamsTest +{ + + @Test + public void testSum() + { + assertThat( 1 + 2, equalTo( 3 ) ); + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-847-testngfail/pom.xml b/surefire-integration-tests/src/test/resources/surefire-847-testngfail/pom.xml index 0b9b8826b5..c321c6ecb5 100644 --- a/surefire-integration-tests/src/test/resources/surefire-847-testngfail/pom.xml +++ b/surefire-integration-tests/src/test/resources/surefire-847-testngfail/pom.xml @@ -1,67 +1,67 @@ - - - - 4.0.0 - org.codehaus.jira - surefire-847 - 0.0.1-SNAPSHOT - - - com.google.inject - guice - 3.0 - no_aop - test - - - org.testng - testng - 6.5.1 - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.5 - 1.5 - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.version} - - false - ${project.build.directory}/test-classes - - - - - - - ${basedir}/src/test/resources/suite.xml - - + + + + 4.0.0 + org.codehaus.jira + surefire-847 + 0.0.1-SNAPSHOT + + + com.google.inject + guice + 3.0 + no_aop + test + + + org.testng + testng + 6.5.1 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + false + ${project.build.directory}/test-classes + + + + + + + ${basedir}/src/test/resources/suite.xml + + diff --git a/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/pom.xml b/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/pom.xml index eb634e723d..ecafe113e2 100644 --- a/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/pom.xml +++ b/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/pom.xml @@ -1,41 +1,41 @@ - - 4.0.0 - groupId - artifactId - 1.0-SNAPSHOT - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.version} - - - org.apache.maven.surefire - surefire-testng - ${surefire.version} - - - org.apache.maven.surefire - surefire-junit47 - ${surefire.version} - - - - - - - - junit - junit - 4.10 - test - - - org.testng - testng - 6.8 - test - - - + + 4.0.0 + groupId + artifactId + 1.0-SNAPSHOT + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + org.apache.maven.surefire + surefire-testng + ${surefire.version} + + + org.apache.maven.surefire + surefire-junit47 + ${surefire.version} + + + + + + + + junit + junit + 4.10 + test + + + org.testng + testng + 6.8 + test + + + diff --git a/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/src/test/java/com/company/JUnitTest.java b/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/src/test/java/com/company/JUnitTest.java index 434a95c438..29d84a0756 100644 --- a/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/src/test/java/com/company/JUnitTest.java +++ b/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/src/test/java/com/company/JUnitTest.java @@ -1,12 +1,12 @@ -package com.company; - -import org.junit.Assert; -import org.junit.Test; - -public class JUnitTest { - @Test - public void test() { - //Assert.assertTrue(true); - Assert.assertTrue(false); - } -} +package com.company; + +import org.junit.Assert; +import org.junit.Test; + +public class JUnitTest { + @Test + public void test() { + //Assert.assertTrue(true); + Assert.assertTrue(false); + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/src/test/java/com/company/TestNGTest.java b/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/src/test/java/com/company/TestNGTest.java index 480372d451..5d70f9f3ea 100644 --- a/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/src/test/java/com/company/TestNGTest.java +++ b/surefire-integration-tests/src/test/resources/surefire-926-2-provider-failure/src/test/java/com/company/TestNGTest.java @@ -1,12 +1,12 @@ -package com.company; - -import org.testng.Assert; -import org.testng.annotations.Test; - -public class TestNGTest { - @Test - public void test() { - Assert.assertTrue(true); - //Assert.assertTrue(false); - } -} +package com.company; + +import org.testng.Assert; +import org.testng.annotations.Test; + +public class TestNGTest { + @Test + public void test() { + Assert.assertTrue(true); + //Assert.assertTrue(false); + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/pom.xml b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/pom.xml index baff4b4f03..8f34a4302f 100644 --- a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/pom.xml +++ b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/pom.xml @@ -1,48 +1,48 @@ - - 4.0.0 - - com.mycompany - TestFailed - 1.0-SNAPSHOT - jar - - TestFailed - http://maven.apache.org - - - UTF-8 - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-surefire-plugin - ${surefire.version} - - - - - - - junit - junit - 3.8.1 - test - - - org.testng - testng - 6.8 - - - + + 4.0.0 + + com.mycompany + TestFailed + 1.0-SNAPSHOT + jar + + TestFailed + http://maven.apache.org + + + UTF-8 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.version} + + + + + + + junit + junit + 3.8.1 + test + + + org.testng + testng + 6.8 + + + diff --git a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/main/java/com/mycompany/testfailed/App.java b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/main/java/com/mycompany/testfailed/App.java index 4562c1afdb..f5544af47b 100644 --- a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/main/java/com/mycompany/testfailed/App.java +++ b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/main/java/com/mycompany/testfailed/App.java @@ -1,13 +1,13 @@ -package com.mycompany.testfailed; - -/** - * Hello world! - * - */ -public class App -{ - public static void main( String[] args ) - { - System.out.println( "Hello World!" ); - } -} +package com.mycompany.testfailed; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/test/java/com/mycompany/testfailed/AppTest.java b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/test/java/com/mycompany/testfailed/AppTest.java index 492f8333fc..57c0d927ae 100644 --- a/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/test/java/com/mycompany/testfailed/AppTest.java +++ b/surefire-integration-tests/src/test/resources/surefire-931-provider-failure/src/test/java/com/mycompany/testfailed/AppTest.java @@ -1,18 +1,18 @@ -package com.mycompany.testfailed; - -import junit.framework.TestCase; -import org.testng.annotations.Test; - - -/** - * Unit test for simple App. - */ -public class AppTest - extends TestCase -{ - @Test(groups = "deleteLocation", dependsOnGroups = - { - "postLocation", "getLocation" - }) - public void removeNonExistentLocation() {} -} +package com.mycompany.testfailed; + +import junit.framework.TestCase; +import org.testng.annotations.Test; + + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + @Test(groups = "deleteLocation", dependsOnGroups = + { + "postLocation", "getLocation" + }) + public void removeNonExistentLocation() {} +} diff --git a/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java b/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java index 4265116314..229ea8bbe2 100644 --- a/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java +++ b/surefire-providers/surefire-junit3/src/test/java/org/apache/maven/surefire/junit/JUnitTestSetTest.java @@ -1,120 +1,120 @@ -package org.apache.maven.surefire.junit; - -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.List; -import org.apache.maven.surefire.common.junit3.JUnit3Reflector; -import org.apache.maven.surefire.report.ReportEntry; -import org.apache.maven.surefire.report.RunListener; -import org.apache.maven.surefire.testset.TestSetFailedException; - -import junit.framework.Test; -import junit.framework.TestCase; -import junit.framework.TestSuite; - -public class JUnitTestSetTest - extends TestCase -{ - - public void testExecuteSuiteClass() - throws TestSetFailedException - { - ClassLoader testClassLoader = this.getClass().getClassLoader(); - JUnit3Reflector reflector = new JUnit3Reflector( testClassLoader ); - JUnitTestSet testSet = new JUnitTestSet( Suite.class, reflector ); - SuccessListener listener = new SuccessListener(); - testSet.execute( listener, testClassLoader ); - List succeededTests = listener.getSucceededTests(); - assertEquals( 1, succeededTests.size() ); - assertEquals( "testSuccess(org.apache.maven.surefire.junit.JUnitTestSetTest$AlwaysSucceeds)", - ( (ReportEntry) succeededTests.get( 0 ) ).getName() ); - } - - public static final class AlwaysSucceeds - extends TestCase - { - public void testSuccess() - { - assertTrue( true ); - } - } - - public static class SuccessListener - implements RunListener - { - - private List succeededTests = new ArrayList(); - - public void testSetStarting( ReportEntry report ) - { - } - - public void testSetCompleted( ReportEntry report ) - { - } - - public void testStarting( ReportEntry report ) - { - } - - public void testSucceeded( ReportEntry report ) - { - this.succeededTests.add( report ); - } - - public void testAssumptionFailure( ReportEntry report ) - { - throw new IllegalStateException(); - } - - public void testError( ReportEntry report ) - { - throw new IllegalStateException(); - } - - public void testFailed( ReportEntry report ) - { - throw new IllegalStateException(); - } - - public void testSkipped( ReportEntry report ) - { - throw new IllegalStateException(); - } - - public List getSucceededTests() - { - return succeededTests; - } - - } - - public static class Suite - { - - public static Test suite() - { - TestSuite suite = new TestSuite(); - suite.addTestSuite( AlwaysSucceeds.class ); - return suite; - } - } -} +package org.apache.maven.surefire.junit; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.List; +import org.apache.maven.surefire.common.junit3.JUnit3Reflector; +import org.apache.maven.surefire.report.ReportEntry; +import org.apache.maven.surefire.report.RunListener; +import org.apache.maven.surefire.testset.TestSetFailedException; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +public class JUnitTestSetTest + extends TestCase +{ + + public void testExecuteSuiteClass() + throws TestSetFailedException + { + ClassLoader testClassLoader = this.getClass().getClassLoader(); + JUnit3Reflector reflector = new JUnit3Reflector( testClassLoader ); + JUnitTestSet testSet = new JUnitTestSet( Suite.class, reflector ); + SuccessListener listener = new SuccessListener(); + testSet.execute( listener, testClassLoader ); + List succeededTests = listener.getSucceededTests(); + assertEquals( 1, succeededTests.size() ); + assertEquals( "testSuccess(org.apache.maven.surefire.junit.JUnitTestSetTest$AlwaysSucceeds)", + ( (ReportEntry) succeededTests.get( 0 ) ).getName() ); + } + + public static final class AlwaysSucceeds + extends TestCase + { + public void testSuccess() + { + assertTrue( true ); + } + } + + public static class SuccessListener + implements RunListener + { + + private List succeededTests = new ArrayList(); + + public void testSetStarting( ReportEntry report ) + { + } + + public void testSetCompleted( ReportEntry report ) + { + } + + public void testStarting( ReportEntry report ) + { + } + + public void testSucceeded( ReportEntry report ) + { + this.succeededTests.add( report ); + } + + public void testAssumptionFailure( ReportEntry report ) + { + throw new IllegalStateException(); + } + + public void testError( ReportEntry report ) + { + throw new IllegalStateException(); + } + + public void testFailed( ReportEntry report ) + { + throw new IllegalStateException(); + } + + public void testSkipped( ReportEntry report ) + { + throw new IllegalStateException(); + } + + public List getSucceededTests() + { + return succeededTests; + } + + } + + public static class Suite + { + + public static Test suite() + { + TestSuite suite = new TestSuite(); + suite.addTestSuite( AlwaysSucceeds.class ); + return suite; + } + } +} diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/AsynchronousRunner.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/AsynchronousRunner.java index fe6ef7568e..4d14d31810 100644 --- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/AsynchronousRunner.java +++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/AsynchronousRunner.java @@ -1,81 +1,81 @@ -package org.apache.maven.surefire.junitcore; - -/* - * 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. - */ - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import org.apache.maven.surefire.util.NestedRuntimeException; - -import org.junit.runners.model.RunnerScheduler; - -/** - * @author Kristian Rosenvold - */ -public class AsynchronousRunner - implements RunnerScheduler -{ - private final List> futures = Collections.synchronizedList( new ArrayList>() ); - - private final ExecutorService fService; - - public AsynchronousRunner( ExecutorService fService ) - { - this.fService = fService; - } - - public void schedule( final Runnable childStatement ) - { - futures.add( fService.submit( Executors.callable( childStatement ) ) ); - } - - - public void finished() - { - try - { - waitForCompletion(); - } - catch ( ExecutionException e ) - { - throw new NestedRuntimeException( e ); - } - } - - public void waitForCompletion() - throws ExecutionException - { - for ( Future each : futures ) - { - try - { - each.get(); - } - catch ( InterruptedException e ) - { - throw new NestedRuntimeException( e ); - } - } - } -} +package org.apache.maven.surefire.junitcore; + +/* + * 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. + */ + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import org.apache.maven.surefire.util.NestedRuntimeException; + +import org.junit.runners.model.RunnerScheduler; + +/** + * @author Kristian Rosenvold + */ +public class AsynchronousRunner + implements RunnerScheduler +{ + private final List> futures = Collections.synchronizedList( new ArrayList>() ); + + private final ExecutorService fService; + + public AsynchronousRunner( ExecutorService fService ) + { + this.fService = fService; + } + + public void schedule( final Runnable childStatement ) + { + futures.add( fService.submit( Executors.callable( childStatement ) ) ); + } + + + public void finished() + { + try + { + waitForCompletion(); + } + catch ( ExecutionException e ) + { + throw new NestedRuntimeException( e ); + } + } + + public void waitForCompletion() + throws ExecutionException + { + for ( Future each : futures ) + { + try + { + each.get(); + } + catch ( InterruptedException e ) + { + throw new NestedRuntimeException( e ); + } + } + } +} diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/SynchronousRunner.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/SynchronousRunner.java index 1abd7f74a4..5c14bfbd1b 100644 --- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/SynchronousRunner.java +++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/SynchronousRunner.java @@ -1,37 +1,37 @@ -package org.apache.maven.surefire.junitcore; -/* - * 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. - */ - -import org.junit.runners.model.RunnerScheduler; - -/** - * @author Kristian Rosenvold - */ -class SynchronousRunner - implements RunnerScheduler -{ - public void schedule( final Runnable childStatement ) - { - childStatement.run(); - } - - public void finished() - { - } -} +package org.apache.maven.surefire.junitcore; +/* + * 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. + */ + +import org.junit.runners.model.RunnerScheduler; + +/** + * @author Kristian Rosenvold + */ +class SynchronousRunner + implements RunnerScheduler +{ + public void schedule( final Runnable childStatement ) + { + childStatement.run(); + } + + public void finished() + { + } +} From 4c47f19af9918fabc42cfdb7ea62323a7f8279b6 Mon Sep 17 00:00:00 2001 From: Kristian Rosenvold Date: Wed, 9 Jan 2013 20:23:30 +0100 Subject: [PATCH 07/14] o Made volatile to get consistent synchronization --- .../booterclient/lazytestprovider/TestProvidingInputStream.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java index 730443559f..4f5f6a4120 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java @@ -48,7 +48,7 @@ public class TestProvidingInputStream private FlushReceiverProvider flushReceiverProvider; - private boolean closed = false; + private volatile boolean closed = false; /** * C'tor From 9cd2acb3ee667df3eeb8f46805ed2885190cf77d Mon Sep 17 00:00:00 2001 From: Kristian Rosenvold Date: Sun, 13 Jan 2013 15:01:38 +0100 Subject: [PATCH 08/14] o Apporto sidebar !! --- src/site/site.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/site.xml b/src/site/site.xml index db1de94611..3cff66b55e 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -39,7 +39,7 @@ true - false + true ${project.url} From e9f758471aa9ac967025209df004d426e49e1844 Mon Sep 17 00:00:00 2001 From: agudian Date: Sat, 5 Jan 2013 21:13:12 +0100 Subject: [PATCH 09/14] [SUREFIRE-946] prevent hanging main process if forked process was killed (softly) --- .../TestProvidingInputStream.java | 250 +++++++++--------- .../surefire/booter/ForkingRunListener.java | 2 +- .../maven/surefire/booter/ForkedBooter.java | 8 +- 3 files changed, 131 insertions(+), 129 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java index 4f5f6a4120..28d1705283 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java @@ -1,125 +1,127 @@ -package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; - -/* - * 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. - */ - -import java.io.IOException; -import java.io.InputStream; -import java.util.Queue; -import java.util.concurrent.Semaphore; - -/** - * An {@link InputStream} that, when read, provides test class names out of a queue. - *

- * The Stream provides only one test at a time, but only after {@link #provideNewTest()} has been invoked. - *

- * After providing each test class name, followed by a newline character, a flush is performed on the - * {@link FlushReceiver} provided by the {@link FlushReceiverProvider} that can be set using - * {@link #setFlushReceiverProvider(FlushReceiverProvider)}. - * - * @author Andreas Gudian - */ -public class TestProvidingInputStream - extends InputStream -{ - private final Queue testItemQueue; - - private byte[] currentBuffer; - - private int currentPos; - - private Semaphore semaphore = new Semaphore( 0 ); - - private FlushReceiverProvider flushReceiverProvider; - - private volatile boolean closed = false; - - /** - * C'tor - * - * @param testItemQueue source of the tests to be read from this stream - */ - public TestProvidingInputStream( Queue testItemQueue ) - { - this.testItemQueue = testItemQueue; - } - - /** - * @param flushReceiverProvider the provider for a flush receiver. - */ - public void setFlushReceiverProvider( FlushReceiverProvider flushReceiverProvider ) - { - this.flushReceiverProvider = flushReceiverProvider; - } - - @Override - public synchronized int read() - throws IOException - { - if ( null == currentBuffer ) - { - if ( null != flushReceiverProvider && null != flushReceiverProvider.getFlushReceiver() ) - { - flushReceiverProvider.getFlushReceiver().flush(); - } - - semaphore.acquireUninterruptibly(); - - if ( closed ) - { - return -1; - } - - String currentElement = testItemQueue.poll(); - if ( null != currentElement ) - { - currentBuffer = currentElement.getBytes(); - currentPos = 0; - } - else - { - return -1; - } - } - - if ( currentPos < currentBuffer.length ) - { - return ( currentBuffer[currentPos++] & 0xff ); - } - else - { - currentBuffer = null; - return ( '\n' & 0xff ); - } - } - - /** - * Signal that a new test is to be provided. - */ - public void provideNewTest() - { - semaphore.release(); - } - - public void close() - { - closed = true; - semaphore.release(); - } +package org.apache.maven.plugin.surefire.booterclient.lazytestprovider; + +/* + * 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. + */ + +import java.io.IOException; +import java.io.InputStream; +import java.util.Queue; +import java.util.concurrent.Semaphore; + +/** + * An {@link InputStream} that, when read, provides test class names out of + * a queue. + *

+ * The Stream provides only one test at a time, but only after {@link #provideNewTest()} + * has been invoked. + *

+ * After providing each test class name, followed by a newline character, a flush is + * performed on the {@link FlushReceiver} provided by the {@link FlushReceiverProvider} + * that can be set using {@link #setFlushReceiverProvider(FlushReceiverProvider)}. + * + * @author Andreas Gudian + */ +public class TestProvidingInputStream + extends InputStream +{ + private final Queue testItemQueue; + + private byte[] currentBuffer; + + private int currentPos; + + private Semaphore semaphore = new Semaphore( 0 ); + + private FlushReceiverProvider flushReceiverProvider; + + private boolean closed = false; + + /** + * C'tor + * + * @param testItemQueue source of the tests to be read from this stream + */ + public TestProvidingInputStream( Queue testItemQueue ) + { + this.testItemQueue = testItemQueue; + } + + /** + * @param flushReceiverProvider the provider for a flush receiver. + */ + public void setFlushReceiverProvider( FlushReceiverProvider flushReceiverProvider ) + { + this.flushReceiverProvider = flushReceiverProvider; + } + + @Override + public synchronized int read() + throws IOException + { + if ( null == currentBuffer ) + { + if ( null != flushReceiverProvider && null != flushReceiverProvider.getFlushReceiver() ) + { + flushReceiverProvider.getFlushReceiver().flush(); + } + + semaphore.acquireUninterruptibly(); + + if ( closed ) + { + return -1; + } + + String currentElement = testItemQueue.poll(); + if ( null != currentElement ) + { + currentBuffer = currentElement.getBytes(); + currentPos = 0; + } + else + { + return -1; + } + } + + if ( currentPos < currentBuffer.length ) + { + return ( currentBuffer[currentPos++] & 0xff ); + } + else + { + currentBuffer = null; + return ( '\n' & 0xff ); + } + } + + /** + * Signal that a new test is to be provided. + */ + public void provideNewTest() + { + semaphore.release(); + } + + public void close() + { + closed = true; + semaphore.release(); + } } \ No newline at end of file diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java index 6ec7223383..1940e7c78a 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java @@ -70,7 +70,7 @@ public class ForkingRunListener public static final byte BOOTERCODE_TEST_SKIPPED = (byte) '9'; public static final byte BOOTERCODE_CRASH = (byte) 'C'; - + public static final byte BOOTERCODE_TEST_ASSUMPTIONFAILURE = (byte) 'G'; public static final byte BOOTERCODE_CONSOLE = (byte) 'H'; diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java index 5f711f42d2..f9e912cb8b 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java @@ -52,7 +52,7 @@ public class ForkedBooter private static boolean sayGoodbye = false; - private static final class GoodbyeReporterAndStdStreamCloser + private static final class GoodbyReporterAndStdStreamCloser implements Runnable { @@ -60,7 +60,7 @@ private static final class GoodbyeReporterAndStdStreamCloser private PrintStream originalOut; - public GoodbyeReporterAndStdStreamCloser() + public GoodbyReporterAndStdStreamCloser() { this.originalIn = System.in; this.originalOut = System.out; @@ -72,7 +72,7 @@ public void run() { originalIn.close(); } - catch ( IOException ignore ) + catch ( IOException e ) { } @@ -104,7 +104,7 @@ public static void main( String[] args ) { final PrintStream originalOut = System.out; - Runtime.getRuntime().addShutdownHook( new Thread( new GoodbyeReporterAndStdStreamCloser() ) ); + Runtime.getRuntime().addShutdownHook( new Thread( new GoodbyReporterAndStdStreamCloser() ) ); try { From b32af3edadce6fd7b50a401b7362b039120ba33b Mon Sep 17 00:00:00 2001 From: agudian Date: Sat, 5 Jan 2013 22:08:53 +0100 Subject: [PATCH 10/14] Fix typo, format source --- .../TestProvidingInputStream.java | 24 +++++++++---------- .../surefire/booter/ForkingRunListener.java | 2 +- .../maven/surefire/booter/ForkedBooter.java | 6 ++--- 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java index 28d1705283..df14d3594f 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/lazytestprovider/TestProvidingInputStream.java @@ -25,16 +25,14 @@ import java.util.concurrent.Semaphore; /** - * An {@link InputStream} that, when read, provides test class names out of - * a queue. + * An {@link InputStream} that, when read, provides test class names out of a queue. *

- * The Stream provides only one test at a time, but only after {@link #provideNewTest()} - * has been invoked. + * The Stream provides only one test at a time, but only after {@link #provideNewTest()} has been invoked. *

- * After providing each test class name, followed by a newline character, a flush is - * performed on the {@link FlushReceiver} provided by the {@link FlushReceiverProvider} - * that can be set using {@link #setFlushReceiverProvider(FlushReceiverProvider)}. - * + * After providing each test class name, followed by a newline character, a flush is performed on the + * {@link FlushReceiver} provided by the {@link FlushReceiverProvider} that can be set using + * {@link #setFlushReceiverProvider(FlushReceiverProvider)}. + * * @author Andreas Gudian */ public class TestProvidingInputStream @@ -54,7 +52,7 @@ public class TestProvidingInputStream /** * C'tor - * + * * @param testItemQueue source of the tests to be read from this stream */ public TestProvidingInputStream( Queue testItemQueue ) @@ -87,7 +85,7 @@ public synchronized int read() { return -1; } - + String currentElement = testItemQueue.poll(); if ( null != currentElement ) { @@ -118,10 +116,10 @@ public void provideNewTest() { semaphore.release(); } - - public void close() + + public void close() { - closed = true; + closed = true; semaphore.release(); } } \ No newline at end of file diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java index 1940e7c78a..6ec7223383 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java @@ -70,7 +70,7 @@ public class ForkingRunListener public static final byte BOOTERCODE_TEST_SKIPPED = (byte) '9'; public static final byte BOOTERCODE_CRASH = (byte) 'C'; - + public static final byte BOOTERCODE_TEST_ASSUMPTIONFAILURE = (byte) 'G'; public static final byte BOOTERCODE_CONSOLE = (byte) 'H'; diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java index f9e912cb8b..4b04a99e6f 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java @@ -52,7 +52,7 @@ public class ForkedBooter private static boolean sayGoodbye = false; - private static final class GoodbyReporterAndStdStreamCloser + private static final class GoodbyeReporterAndStdStreamCloser implements Runnable { @@ -60,7 +60,7 @@ private static final class GoodbyReporterAndStdStreamCloser private PrintStream originalOut; - public GoodbyReporterAndStdStreamCloser() + public GoodbyeReporterAndStdStreamCloser() { this.originalIn = System.in; this.originalOut = System.out; @@ -104,7 +104,7 @@ public static void main( String[] args ) { final PrintStream originalOut = System.out; - Runtime.getRuntime().addShutdownHook( new Thread( new GoodbyReporterAndStdStreamCloser() ) ); + Runtime.getRuntime().addShutdownHook( new Thread( new GoodbyeReporterAndStdStreamCloser() ) ); try { From 16e544cf44c669981b1394a1e3e94734d74c6aac Mon Sep 17 00:00:00 2001 From: agudian Date: Wed, 9 Jan 2013 22:56:15 +0100 Subject: [PATCH 11/14] [SUREFIRE-946] fix crash-detection for reuseForks=true, now including hard crashes. * use a callback to close the TestProvidingInputStream after the forked process ended but before waiting on InputFeeder to finish * removed the shutdown hook in the forked VM again, removed BOOTERCODE_CRASH (also fixes the other ITs that broke before) * extend CrashDetectionIT for testing hard VM crashes * add IT for killed main process with reusable fork --- .../surefire/booterclient/ForkStarter.java | 20 ++--- .../booterclient/output/ForkClient.java | 12 --- pom.xml | 4 +- .../surefire/booter/ForkingRunListener.java | 2 - .../maven/surefire/booter/ForkedBooter.java | 74 ++++--------------- .../maven/surefire/its/CrashDetectionIT.java | 5 ++ .../surefire/its/fixture/MavenLauncher.java | 12 ++- .../its/fixture/SurefireLauncher.java | 13 +++- ...ire946KillMainProcessInReusableForkIT.java | 36 +++++++++ .../java/junit44/environment/BasicTest.java | 8 +- .../pom.xml | 57 ++++++++++++++ .../java/junit44/environment/BasicTest.java | 21 ++++++ 12 files changed, 176 insertions(+), 88 deletions(-) create mode 100644 surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire946KillMainProcessInReusableForkIT.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/pom.xml create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/BasicTest.java diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java index 892c6a9bc6..e4339bbb4f 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java @@ -86,7 +86,7 @@ public class ForkStarter * Closes an InputStream */ private final class InputStreamCloser - extends Thread + implements Runnable { private InputStream testProvidingInputStream; @@ -95,8 +95,7 @@ public InputStreamCloser( InputStream testProvidingInputStream ) this.testProvidingInputStream = testProvidingInputStream; } - @Override - public void run() + public synchronized void run() { if ( testProvidingInputStream != null ) { @@ -108,6 +107,7 @@ public void run() { // ignore } + testProvidingInputStream = null; } } } @@ -412,16 +412,18 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC startupConfiguration.getClassLoaderConfiguration(), startupConfiguration.isShadefire(), threadNumber ); - final InputStreamCloser inputStreamCloserHook; + final InputStreamCloser inputStreamCloser; + final Thread inputStreamCloserHook; if ( testProvidingInputStream != null ) { testProvidingInputStream.setFlushReceiverProvider( cli ); - - inputStreamCloserHook = new InputStreamCloser( testProvidingInputStream ); + inputStreamCloser = new InputStreamCloser( testProvidingInputStream ); + inputStreamCloserHook = new Thread( inputStreamCloser ); addShutDownHook( inputStreamCloserHook ); } else { + inputStreamCloser = null; inputStreamCloserHook = null; } @@ -446,7 +448,7 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC final int timeout = forkedProcessTimeoutInSeconds > 0 ? forkedProcessTimeoutInSeconds : 0; final int result = CommandLineUtils.executeCommandLine( cli, testProvidingInputStream, threadedStreamConsumer, - threadedStreamConsumer, timeout ); + threadedStreamConsumer, timeout, false, inputStreamCloser ); if ( result != RunResult.SUCCESS ) { throw new SurefireBooterForkException( "Error occurred in starting fork, check output in log" ); @@ -465,10 +467,10 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC finally { threadedStreamConsumer.close(); - if ( inputStreamCloserHook != null ) + if ( inputStreamCloser != null ) { + inputStreamCloser.run(); removeShutdownHook( inputStreamCloserHook ); - inputStreamCloserHook.run(); } if ( runResult == null ) { diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java index 932f148cc0..fa2f41d48e 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java @@ -156,11 +156,7 @@ public void consumeLine( String s ) case ForkingRunListener.BOOTERCODE_ERROR: errorInFork = deserializeStackStraceWriter( new StringTokenizer( remaining, "," ) ); break; - case ForkingRunListener.BOOTERCODE_CRASH: - closeTestProvidingInputStream(); - break; case ForkingRunListener.BOOTERCODE_BYE: - closeTestProvidingInputStream(); saidGoodBye = true; break; default: @@ -177,14 +173,6 @@ public void consumeLine( String s ) } } - private void closeTestProvidingInputStream() - { - if ( null != testProvidingInputStream ) - { - testProvidingInputStream.close(); - } - } - public void consumeMultiLineContent( String s ) throws IOException { diff --git a/pom.xml b/pom.xml index 0fda14a87b..2c04950cfc 100644 --- a/pom.xml +++ b/pom.xml @@ -241,12 +241,12 @@ org.apache.maven.shared maven-shared-utils - 0.2 + 0.3-SNAPSHOT org.apache.maven.shared maven-verifier - 1.4 + 1.5-SNAPSHOT jmock diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java index 6ec7223383..fa4e9cf449 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java @@ -69,8 +69,6 @@ public class ForkingRunListener public static final byte BOOTERCODE_TEST_SKIPPED = (byte) '9'; - public static final byte BOOTERCODE_CRASH = (byte) 'C'; - public static final byte BOOTERCODE_TEST_ASSUMPTIONFAILURE = (byte) 'G'; public static final byte BOOTERCODE_CONSOLE = (byte) 'H'; diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java index 4b04a99e6f..c06297aeef 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java @@ -21,7 +21,6 @@ import java.io.File; import java.io.FileInputStream; -import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.lang.reflect.InvocationTargetException; @@ -36,7 +35,7 @@ *

* Deals with deserialization of the booter wire-level protocol *

- * + * * @author Jason van Zyl * @author Emmanuel Venisse * @author Kristian Rosenvold @@ -44,58 +43,10 @@ public class ForkedBooter { - private final static long SYSTEM_EXIT_TIMEOUT = 30 * 1000; - - private final static String GOODBYE_MESSAGE = ( (char) ForkingRunListener.BOOTERCODE_BYE ) + ",0,BYE!"; - - private final static String CRASH_MESSAGE = ( (char) ForkingRunListener.BOOTERCODE_CRASH ) + ",0,F!"; - - private static boolean sayGoodbye = false; - - private static final class GoodbyeReporterAndStdStreamCloser - implements Runnable - { - - private InputStream originalIn; - - private PrintStream originalOut; - - public GoodbyeReporterAndStdStreamCloser() - { - this.originalIn = System.in; - this.originalOut = System.out; - } - - public void run() - { - try - { - originalIn.close(); - } - catch ( IOException e ) - { - } - - if ( sayGoodbye ) - { - originalOut.println( GOODBYE_MESSAGE ); - } - else - { - originalOut.println( CRASH_MESSAGE ); - } - - originalOut.flush(); - originalOut.close(); - } - } - /** * This method is invoked when Surefire is forked - this method parses and organizes the arguments passed to it and - * then calls the Surefire class' run method. - *

- * The system exit code will be 1 if an exception is thrown. - * + * then calls the Surefire class' run method.

The system exit code will be 1 if an exception is thrown. + * * @param args Commandline arguments * @throws Throwable Upon throwables */ @@ -103,9 +54,6 @@ public static void main( String[] args ) throws Throwable { final PrintStream originalOut = System.out; - - Runtime.getRuntime().addShutdownHook( new Thread( new GoodbyeReporterAndStdStreamCloser() ) ); - try { if ( args.length > 1 ) @@ -123,8 +71,8 @@ public static void main( String[] args ) boolean readTestsFromInputStream = providerConfiguration.isReadTestsFromInStream(); final ClasspathConfiguration classpathConfiguration = startupConfiguration.getClasspathConfiguration(); - final ClassLoader testClassLoader = - classpathConfiguration.createForkingTestClassLoader( startupConfiguration.isManifestOnlyJarRequestedAndUsable() ); + final ClassLoader testClassLoader = classpathConfiguration.createForkingTestClassLoader( + startupConfiguration.isManifestOnlyJarRequestedAndUsable() ); startupConfiguration.writeSurefireTestClasspathProperty(); @@ -144,7 +92,8 @@ else if ( readTestsFromInputStream ) try { - runSuitesInProcess( testSet, testClassLoader, startupConfiguration, providerConfiguration, originalOut ); + runSuitesInProcess( testSet, testClassLoader, startupConfiguration, providerConfiguration, + originalOut ); } catch ( InvocationTargetException t ) { @@ -162,8 +111,10 @@ else if ( readTestsFromInputStream ) ForkingRunListener.encode( stringBuffer, stackTraceWriter, false ); originalOut.println( ( (char) ForkingRunListener.BOOTERCODE_ERROR ) + ",0," + stringBuffer.toString() ); } - - sayGoodbye = true; + // Say bye. + originalOut.println( ( (char) ForkingRunListener.BOOTERCODE_BYE ) + ",0,BYE!" ); + originalOut.flush(); + // noinspection CallToSystemExit exit( 0 ); } catch ( Throwable t ) @@ -176,12 +127,15 @@ else if ( readTestsFromInputStream ) } } + private final static long SYSTEM_EXIT_TIMEOUT = 30 * 1000; + private static void exit( final int returnCode ) { launchLastDitchDaemonShutdownThread( returnCode ); System.exit( returnCode ); } + private static RunResult runSuitesInProcess( Object testSet, ClassLoader testsClassLoader, StartupConfiguration startupConfiguration, ProviderConfiguration providerConfiguration, diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CrashDetectionIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CrashDetectionIT.java index 31e3e01565..88e50f69fc 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CrashDetectionIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/CrashDetectionIT.java @@ -36,4 +36,9 @@ public void testCrashInReusableFork() { unpack( "crash-detection" ).forkOncePerThread().threadCount( 1 ).maven().withFailure().executeTest(); } + + public void testHardCrashInReusableFork() + { + unpack( "crash-detection" ).forkOncePerThread().threadCount( 1 ).addGoal( "-DkillHard=true" ).maven().withFailure().executeTest(); + } } diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java index bbf910c93f..90d291fb44 100755 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java @@ -377,6 +377,16 @@ public OutputValidator getValidator() return validator; } + public void setTimeoutInSeconds( int timeoutInSeconds ) + { + getVerifier().setForkTimeoutInSeconds( timeoutInSeconds ); + } + + public void setKillProcessAfterTimeout( boolean killProcessAfterTimeout ) + { + getVerifier().setKillForkAfterTimeout( killProcessAfterTimeout ); + } + private Verifier getVerifier() { if ( verifier == null ) @@ -392,7 +402,7 @@ private Verifier getVerifier() } return verifier; } - + private File simpleExtractResources( Class cl, String resourcePath ) { if ( !resourcePath.startsWith( "/" ) ) diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java index 84ea8b98ce..3c84d89994 100755 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java @@ -370,10 +370,21 @@ private String getReportPluginGoal( String goal ) return "org.apache.maven.plugins:maven-surefire-report-plugin:" + getSurefireVersion() + ":" + goal; } - public SurefireLauncher setTestToRun( String basicTest ) { mavenLauncher.sysProp( "test", basicTest ); return this; } + + public SurefireLauncher setTimeoutInSeconds( int timeoutInSeconds ) + { + mavenLauncher.setTimeoutInSeconds( timeoutInSeconds ); + return this; + } + + public SurefireLauncher setKillProcessAfterTimeout( boolean killProcessAfterTimeout ) + { + mavenLauncher.setKillProcessAfterTimeout( killProcessAfterTimeout ); + return this; + } } diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire946KillMainProcessInReusableForkIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire946KillMainProcessInReusableForkIT.java new file mode 100644 index 0000000000..56309d6eeb --- /dev/null +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire946KillMainProcessInReusableForkIT.java @@ -0,0 +1,36 @@ +package org.apache.maven.surefire.its.jiras; + +/* + * 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. + */ + +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.junit.Test; + +public class Surefire946KillMainProcessInReusableForkIT + extends SurefireJUnit4IntegrationTestCase +{ + + @Test( timeout = 30000 ) + public void test() + throws Exception + { + unpack( "surefire-946-killMainProcessInReusableFork" ).setTimeoutInSeconds( 10 ).setKillProcessAfterTimeout( true ).forkOncePerThread().threadCount( 1 ).maven().withFailure().executeTest(); + } + +} diff --git a/surefire-integration-tests/src/test/resources/crash-detection/src/test/java/junit44/environment/BasicTest.java b/surefire-integration-tests/src/test/resources/crash-detection/src/test/java/junit44/environment/BasicTest.java index d6f0155f8f..c2157dcda0 100644 --- a/surefire-integration-tests/src/test/resources/crash-detection/src/test/java/junit44/environment/BasicTest.java +++ b/surefire-integration-tests/src/test/resources/crash-detection/src/test/java/junit44/environment/BasicTest.java @@ -15,7 +15,13 @@ public void testNothing() @AfterClass public static void killTheVm(){ - System.exit( 0 ); + if ( Boolean.getBoolean( "killHard" )) + { + Runtime.getRuntime().halt( 0 ); + } + else { + System.exit( 0 ); + } } } diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/pom.xml b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/pom.xml new file mode 100644 index 0000000000..6b8657faf2 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/pom.xml @@ -0,0 +1,57 @@ + + + + + 4.0.0 + + org.apache.maven.plugins.surefire + surefire-946 + 1.0-SNAPSHOT + Tests killing the main maven process when using reusable forks + + + + junit + junit + 4.4 + test + + + + + + + maven-surefire-plugin + ${surefire.version} + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + + diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/BasicTest.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/BasicTest.java new file mode 100644 index 0000000000..9f716518b5 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/BasicTest.java @@ -0,0 +1,21 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + + +public class BasicTest +{ + + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround(){ + Thread.sleep( 60000 ); + } + +} From 652aab9f0315bd7d065c2ec57f6e6299d46c23be Mon Sep 17 00:00:00 2001 From: agudian Date: Fri, 11 Jan 2013 23:11:55 +0100 Subject: [PATCH 12/14] [SUREFIRE-946] reset verifier version to 1.4, update ForkStarter to latest m-s-u snapshot. --- .../plugin/surefire/booterclient/ForkStarter.java | 2 +- pom.xml | 2 +- .../maven/surefire/its/fixture/MavenLauncher.java | 10 ++-------- .../maven/surefire/its/fixture/SurefireLauncher.java | 10 ++-------- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java index e4339bbb4f..164f8c7ba7 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java @@ -448,7 +448,7 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC final int timeout = forkedProcessTimeoutInSeconds > 0 ? forkedProcessTimeoutInSeconds : 0; final int result = CommandLineUtils.executeCommandLine( cli, testProvidingInputStream, threadedStreamConsumer, - threadedStreamConsumer, timeout, false, inputStreamCloser ); + threadedStreamConsumer, timeout, inputStreamCloser ); if ( result != RunResult.SUCCESS ) { throw new SurefireBooterForkException( "Error occurred in starting fork, check output in log" ); diff --git a/pom.xml b/pom.xml index 2c04950cfc..22ab63612b 100644 --- a/pom.xml +++ b/pom.xml @@ -246,7 +246,7 @@ org.apache.maven.shared maven-verifier - 1.5-SNAPSHOT + 1.4 jmock diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java index 90d291fb44..cc745de65d 100755 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/MavenLauncher.java @@ -377,14 +377,8 @@ public OutputValidator getValidator() return validator; } - public void setTimeoutInSeconds( int timeoutInSeconds ) - { - getVerifier().setForkTimeoutInSeconds( timeoutInSeconds ); - } - - public void setKillProcessAfterTimeout( boolean killProcessAfterTimeout ) - { - getVerifier().setKillForkAfterTimeout( killProcessAfterTimeout ); + public void setForkJvm( boolean forkJvm ) { + getVerifier().setForkJvm( forkJvm ); } private Verifier getVerifier() diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java index 3c84d89994..135216e18d 100755 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/fixture/SurefireLauncher.java @@ -376,15 +376,9 @@ public SurefireLauncher setTestToRun( String basicTest ) return this; } - public SurefireLauncher setTimeoutInSeconds( int timeoutInSeconds ) + public SurefireLauncher setForkJvm( boolean forkJvm ) { - mavenLauncher.setTimeoutInSeconds( timeoutInSeconds ); - return this; - } - - public SurefireLauncher setKillProcessAfterTimeout( boolean killProcessAfterTimeout ) - { - mavenLauncher.setKillProcessAfterTimeout( killProcessAfterTimeout ); + mavenLauncher.setForkJvm( true ); return this; } } From 3c342a606a11ff72c21577132906dbf5ecd133d6 Mon Sep 17 00:00:00 2001 From: agudian Date: Fri, 11 Jan 2013 23:20:22 +0100 Subject: [PATCH 13/14] [SUREFIRE-946] Fix the IT - now it actually tests the reported problem. --- ...ire946KillMainProcessInReusableForkIT.java | 39 ++++- .../pom.xml | 73 +++++---- .../java/junit44/environment/Basic01Test.java | 26 ++++ .../java/junit44/environment/Basic02Test.java | 26 ++++ .../java/junit44/environment/Basic03Test.java | 26 ++++ .../java/junit44/environment/Basic04Test.java | 26 ++++ .../java/junit44/environment/Basic05Test.java | 26 ++++ .../java/junit44/environment/Basic06Test.java | 26 ++++ .../java/junit44/environment/Basic07Test.java | 26 ++++ .../java/junit44/environment/Basic08Test.java | 26 ++++ .../java/junit44/environment/Basic09Test.java | 26 ++++ .../java/junit44/environment/Basic10Test.java | 26 ++++ .../java/junit44/environment/BasicTest.java | 21 --- .../surefire-946-self-destruct-plugin/pom.xml | 51 +++++++ .../selfdestruct/SelfDestructMojo.java | 142 ++++++++++++++++++ 15 files changed, 530 insertions(+), 56 deletions(-) create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic01Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic02Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic03Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic04Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic05Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic06Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic07Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic08Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic09Test.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic10Test.java delete mode 100644 surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/BasicTest.java create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-self-destruct-plugin/pom.xml create mode 100644 surefire-integration-tests/src/test/resources/surefire-946-self-destruct-plugin/src/main/java/org/apache/maven/plugins/surefire/selfdestruct/SelfDestructMojo.java diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire946KillMainProcessInReusableForkIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire946KillMainProcessInReusableForkIT.java index 56309d6eeb..60bcfb7a1b 100644 --- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire946KillMainProcessInReusableForkIT.java +++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/jiras/Surefire946KillMainProcessInReusableForkIT.java @@ -20,17 +20,52 @@ */ import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; +import org.junit.BeforeClass; import org.junit.Test; public class Surefire946KillMainProcessInReusableForkIT extends SurefireJUnit4IntegrationTestCase { + // there are 10 test classes that each would wait 2 seconds. + private static final int TEST_SLEEP_TIME = 2000; + + @BeforeClass + public static void installSelfdestructPlugin() + throws Exception + { + unpack( Surefire946KillMainProcessInReusableForkIT.class, "surefire-946-self-destruct-plugin", "plugin" ).executeInstall(); + } + @Test( timeout = 30000 ) - public void test() + public void testHalt() throws Exception { - unpack( "surefire-946-killMainProcessInReusableFork" ).setTimeoutInSeconds( 10 ).setKillProcessAfterTimeout( true ).forkOncePerThread().threadCount( 1 ).maven().withFailure().executeTest(); + doTest( "halt" ); } + @Test( timeout = 30000 ) + public void testExit() + throws Exception + { + doTest( "exit" ); + } + + @Test( timeout = 30000 ) + public void testInterrupt() + throws Exception + { + doTest( "interrupt" ); + } + + private void doTest( String method ) + { + unpack( "surefire-946-killMainProcessInReusableFork" ) + .sysProp( "selfdestruct.timeoutInMillis", "5000" ) + .sysProp( "selfdestruct.method", method ) + .sysProp( "testSleepTime", String.valueOf( TEST_SLEEP_TIME ) ) + .addGoal( "org.apache.maven.plugins.surefire:maven-selfdestruct-plugin:selfdestruct" ) + .setForkJvm( true ) + .forkOncePerThread().threadCount( 1 ).maven().withFailure().executeTest(); + } } diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/pom.xml b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/pom.xml index 6b8657faf2..eb0fe599d9 100644 --- a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/pom.xml +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/pom.xml @@ -17,41 +17,48 @@ ~ specific language governing permissions and limitations ~ under the License. --> + + 4.0.0 - - 4.0.0 + org.apache.maven.plugins.surefire + surefire-946 + 1.0-SNAPSHOT + Tests killing the main maven process when using reusable forks - org.apache.maven.plugins.surefire - surefire-946 - 1.0-SNAPSHOT - Tests killing the main maven process when using reusable forks + + + junit + junit + 4.4 + test + + - - - junit - junit - 4.4 - test - - - - - - - maven-surefire-plugin - ${surefire.version} - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.5 - 1.5 - - - - + + + + org.apache.maven.plugins.surefire + maven-selfdestruct-plugin + 0.1 + + ${selfdestruct.timeoutInMillis} + ${selfdestruct.method} + + + + maven-surefire-plugin + ${surefire.version} + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic01Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic01Test.java new file mode 100644 index 0000000000..efc294f286 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic01Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic01Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic02Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic02Test.java new file mode 100644 index 0000000000..6bc29c7df8 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic02Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic02Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic03Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic03Test.java new file mode 100644 index 0000000000..6d4941be2c --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic03Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic03Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic04Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic04Test.java new file mode 100644 index 0000000000..d3b947c3ad --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic04Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic04Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic05Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic05Test.java new file mode 100644 index 0000000000..a3b604e689 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic05Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic05Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic06Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic06Test.java new file mode 100644 index 0000000000..ea5b951030 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic06Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic06Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic07Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic07Test.java new file mode 100644 index 0000000000..715bc9356a --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic07Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic07Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic08Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic08Test.java new file mode 100644 index 0000000000..fbb8e005c2 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic08Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic08Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic09Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic09Test.java new file mode 100644 index 0000000000..89fb37bdfd --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic09Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic09Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic10Test.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic10Test.java new file mode 100644 index 0000000000..e54edf00dc --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/Basic10Test.java @@ -0,0 +1,26 @@ +package junit44.environment; + +import org.junit.AfterClass; +import org.junit.Test; + +public class Basic10Test +{ + + @Test + public void testNothing() + { + } + + @AfterClass + public static void waitSomeTimeAround() + { + try + { + Thread.sleep( Integer.getInteger( "testSleepTime", 2000 ) ); + } + catch ( InterruptedException ignored ) + { + } + } + +} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/BasicTest.java b/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/BasicTest.java deleted file mode 100644 index 9f716518b5..0000000000 --- a/surefire-integration-tests/src/test/resources/surefire-946-killMainProcessInReusableFork/src/test/java/junit44/environment/BasicTest.java +++ /dev/null @@ -1,21 +0,0 @@ -package junit44.environment; - -import org.junit.AfterClass; -import org.junit.Test; - - -public class BasicTest -{ - - - @Test - public void testNothing() - { - } - - @AfterClass - public static void waitSomeTimeAround(){ - Thread.sleep( 60000 ); - } - -} diff --git a/surefire-integration-tests/src/test/resources/surefire-946-self-destruct-plugin/pom.xml b/surefire-integration-tests/src/test/resources/surefire-946-self-destruct-plugin/pom.xml new file mode 100644 index 0000000000..91823a79d8 --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-self-destruct-plugin/pom.xml @@ -0,0 +1,51 @@ + + 4.0.0 + + org.apache.maven.plugins.surefire + maven-selfdestruct-plugin + 0.1 + maven-plugin + + maven-selfdestruct-plugin Maven Plugin + http://maven.apache.org + + + UTF-8 + + + + + org.apache.maven + maven-plugin-api + 2.0 + + + junit + junit + 3.8.1 + test + + + + + + + org.apache.maven.plugins + maven-plugin-plugin + 2.5.1 + + maven-selfdestruct-plugin + + + + generated-helpmojo + + helpmojo + + + + + + + diff --git a/surefire-integration-tests/src/test/resources/surefire-946-self-destruct-plugin/src/main/java/org/apache/maven/plugins/surefire/selfdestruct/SelfDestructMojo.java b/surefire-integration-tests/src/test/resources/surefire-946-self-destruct-plugin/src/main/java/org/apache/maven/plugins/surefire/selfdestruct/SelfDestructMojo.java new file mode 100644 index 0000000000..33cd5880ca --- /dev/null +++ b/surefire-integration-tests/src/test/resources/surefire-946-self-destruct-plugin/src/main/java/org/apache/maven/plugins/surefire/selfdestruct/SelfDestructMojo.java @@ -0,0 +1,142 @@ +package org.apache.maven.plugins.surefire.selfdestruct; + +/* + * Copyright 2001-2005 The Apache Software Foundation. + * + * Licensed 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. + */ + +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.util.ArrayList; +import java.util.List; +import java.util.Timer; +import java.util.TimerTask; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; + +/** + * Goal which terminates the maven process it is executed in after a timeout. + * + * @goal selfdestruct + * @phase test + */ +public class SelfDestructMojo + extends AbstractMojo +{ + private enum DestructMethod + { + exit, halt, interrupt; + } + + /** + * Timeout in milliseconds + * + * @parameter + */ + private long timeoutInMillis = 0; + + /** + * Method of self-destruction: 'exit' will use System.exit (default), 'halt' will use Runtime.halt, 'interrupt' will + * try to call 'taskkill' (windows) or 'kill -INT' (others) + * + * @parameter + */ + private String method = "exit"; + + public void execute() + throws MojoExecutionException + { + + DestructMethod destructMethod = DestructMethod.valueOf( method ); + + if ( timeoutInMillis > 0 ) + { + getLog().warn( "Self-Destruct in " + timeoutInMillis + " millis using " + destructMethod ); + Timer timer = new Timer( "", true ); + timer.schedule( new SelfDestructionTask( destructMethod ), timeoutInMillis ); + } + else + { + new SelfDestructionTask( destructMethod ).run(); + } + } + + private void selfDestruct( DestructMethod destructMethod ) + { + getLog().warn( "Self-Destructing NOW." ); + switch ( destructMethod ) + { + case exit: + System.exit( 1 ); + case halt: + Runtime.getRuntime().halt( 1 ); + case interrupt: + String name = ManagementFactory.getRuntimeMXBean().getName(); + int indexOfAt = name.indexOf( '@' ); + if ( indexOfAt > 0 ) + { + String pid = name.substring( 0, indexOfAt ); + getLog().warn( "Going to kill process with PID " + pid ); + + List args = new ArrayList(); + if ( System.getProperty( "os.name" ).startsWith( "Windows" ) ) + { + args.add( "taskkill" ); + args.add( "/PID" ); + } + else + { + args.add( "kill" ); + args.add( "-INT" ); + } + args.add( pid ); + + try + { + new ProcessBuilder( args ).start(); + } + catch ( IOException e ) + { + getLog().error( "Unable to spawn process. Killing with System.exit.", e ); + } + } + else + { + getLog().warn( "Unable to determine my PID... Using System.exit" ); + } + } + + System.exit( 1 ); + } + + private class SelfDestructionTask + extends TimerTask + { + + private DestructMethod destructMethod; + + public SelfDestructionTask( DestructMethod destructMethod ) + { + this.destructMethod = destructMethod; + } + + @Override + public void run() + { + selfDestruct( destructMethod ); + } + + } +} From e27b083ba7b01e4ac6e6b94a10382287f51ae12d Mon Sep 17 00:00:00 2001 From: agudian Date: Sun, 13 Jan 2013 17:16:56 +0100 Subject: [PATCH 14/14] Use ShutdownHookUtils --- .../surefire/booterclient/ForkStarter.java | 39 ++----------------- 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java index 164f8c7ba7..6a2adeaac7 100644 --- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java +++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java @@ -51,6 +51,7 @@ import org.apache.maven.shared.utils.cli.CommandLineException; import org.apache.maven.shared.utils.cli.CommandLineTimeOutException; import org.apache.maven.shared.utils.cli.CommandLineUtils; +import org.apache.maven.shared.utils.cli.ShutdownHookUtils; import org.apache.maven.surefire.booter.Classpath; import org.apache.maven.surefire.booter.ClasspathConfiguration; import org.apache.maven.surefire.booter.KeyValueSource; @@ -419,7 +420,7 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC testProvidingInputStream.setFlushReceiverProvider( cli ); inputStreamCloser = new InputStreamCloser( testProvidingInputStream ); inputStreamCloserHook = new Thread( inputStreamCloser ); - addShutDownHook( inputStreamCloserHook ); + ShutdownHookUtils.addShutDownHook( inputStreamCloserHook ); } else { @@ -470,7 +471,7 @@ private RunResult fork( Object testSet, KeyValueSource providerProperties, ForkC if ( inputStreamCloser != null ) { inputStreamCloser.run(); - removeShutdownHook( inputStreamCloserHook ); + ShutdownHookUtils.removeShutdownHook( inputStreamCloserHook ); } if ( runResult == null ) { @@ -524,38 +525,4 @@ private Iterator> getSuitesIterator() throw new SurefireBooterForkException( "Unable to create classloader to find test suites", e ); } } - - // TODO use ShutdownHookUtils, once it's public again - public static void addShutDownHook( Thread hook ) - { - try - { - Runtime.getRuntime().addShutdownHook( hook ); - } - catch ( IllegalStateException ignore ) - { - // ignore - } - catch ( AccessControlException ignore ) - { - // ignore - } - } - - // TODO use ShutdownHookUtils, once it's public again - public static void removeShutdownHook( Thread hook ) - { - try - { - Runtime.getRuntime().removeShutdownHook( hook ); - } - catch ( IllegalStateException ignore ) - { - // ignore - } - catch ( AccessControlException ignore ) - { - // ignore - } - } }