maven-surefire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From steph...@apache.org
Subject svn commit: r898206 - in /maven/surefire/trunk: maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/ surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/ surefire-integration-tests/src/test/resources/concurrentjunit4...
Date Tue, 12 Jan 2010 07:39:50 GMT
Author: stephenc
Date: Tue Jan 12 07:39:49 2010
New Revision: 898206

URL: http://svn.apache.org/viewvc?rev=898206&view=rev
Log:
[SUREFIRE-596] Applied patch version 2 unchanged
Submitted by: Kristian Rosenvold

o Files applied: junit2.diff, junit2.zip

Added:
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47concurrencyIT.java
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/pom.xml
  (with props)
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/
    maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/BasicTest.java
  (with props)
Modified:
    maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
    maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4VersionsIT.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
    maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSetReporter.java

Modified: maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java?rev=898206&r1=898205&r2=898206&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
(original)
+++ maven/surefire/trunk/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
Tue Jan 12 07:39:49 2010
@@ -445,7 +445,7 @@
      * methods that depend on each other, which will be run in the same thread in order to
respect their order of
      * execution.
      *
-     * In JUnit 4.6 the values are classes/methods/both to run in separate threads, as controlled
by threadCount.
+     * In JUnit 4.7 the values are classes/methods/both to run in separate threads, as controlled
by threadCount.
      *
      * @parameter expression="${parallel}"
      * @todo test how this works with forking, and console/file output parallelism
@@ -681,6 +681,10 @@
         }
     }
 
+    private boolean isAnyConcurrencySelected(){
+       return this.parallel != null && this.parallel.trim().length() > 0; 
+    }
+    
     /**
      * Converts old TestNG configuration parameters over to new properties based configuration
      * method. (if any are defined the old way)
@@ -717,8 +721,8 @@
         return isWithinVersionSpec(artifact, "[4.7,)");
     }
 
-    private boolean isJunit40to46(Artifact artifact)  throws MojoExecutionException {
-        return isWithinVersionSpec(artifact, "[4.0,4.7)");
+    private boolean isAnyJunit4(Artifact artifact)  throws MojoExecutionException {
+        return isWithinVersionSpec(artifact, "[4.0,)");
     }
 
     private boolean isWithinVersionSpec(Artifact artifact, String versionSpec) throws MojoExecutionException
{
@@ -800,15 +804,13 @@
                 // The plugin uses a JDK based profile to select the right testng. We might
be explicity using a
                 // different one since its based on the source level, not the JVM. Prune
using the filter.
                 addProvider( surefireBooter, "surefire-testng", surefireArtifact.getBaseVersion(),
testNgArtifact );
-            }
-            else if ( junitArtifact != null && isJunit47Compatible( junitArtifact
) )
-            {
-                convertJunitCoreParameters();
-                addProvider( surefireBooter, "surefire-junit47", surefireArtifact.getBaseVersion(),
null );
-            }
-            else if ( junitArtifact != null && isJunit40to46( junitArtifact ) )
-            {
-                addProvider( surefireBooter, "surefire-junit4", surefireArtifact.getBaseVersion(),
null );
+            } else if (junitArtifact != null && isAnyJunit4( junitArtifact)){
+                    if ( isAnyConcurrencySelected() && isJunit47Compatible( junitArtifact
) ){
+                        convertJunitCoreParameters();
+                        addProvider( surefireBooter, "surefire-junit47", surefireArtifact.getBaseVersion(),
null );
+                    } else {
+                        addProvider( surefireBooter, "surefire-junit4", surefireArtifact.getBaseVersion(),
null );
+                    }
             }
             else
             {
@@ -907,16 +909,16 @@
             else
             {
                 String junitDirectoryTestSuite;
-                if ( isJunit47Compatible( junitArtifact ) )
+                if (  isAnyConcurrencySelected() && isJunit47Compatible( junitArtifact
) )
                 {
                     junitDirectoryTestSuite = "org.apache.maven.surefire.junitcore.JUnitCoreDirectoryTestSuite";
-                    getLog().warn( "Props are" + properties.toString() );
+                    getLog().info( "Concurrency config is " + properties.toString() );
                     surefireBooter.addTestSuite( junitDirectoryTestSuite,
                                                  new Object[]{testClassesDirectory, includes,
excludes, properties} );
                 }
                 else
                 {
-                    if ( isJunit40to46( junitArtifact ) )
+                    if ( isAnyJunit4( junitArtifact ) )
                     {
                         junitDirectoryTestSuite = "org.apache.maven.surefire.junit4.JUnit4DirectoryTestSuite";
                     }

Added: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47concurrencyIT.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47concurrencyIT.java?rev=898206&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47concurrencyIT.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47concurrencyIT.java
Tue Jan 12 07:39:49 2010
@@ -0,0 +1,46 @@
+package org.apache.maven.surefire.its;
+
+
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.util.List;
+
+/**
+ * Basic suite test using all known versions of JUnit 4.x
+ *
+ * @author <a href="mailto:kristian.rosenvold@gmail.com">Kristian Rosenvold</a>
+ *
+ */
+public class Junit47concurrencyIT
+    extends AbstractSurefireIntegrationTestClass
+{
+
+
+    public void test47 () throws Exception
+    {
+        runJUnitTest();
+    }
+
+
+    public void runJUnitTest ()
+        throws Exception
+    {
+        File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/concurrentjunit47"
);
+
+        Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+        List arguments = this.getInitialGoals();
+        arguments.add( "test" );
+        // DGF we have to pass in the version as a command line argument
+        // and NOT as a system property; otherwise our setting will be ignored
+        arguments.add( "-DjunitVersion=4.7");
+        verifier.executeGoals( arguments );
+
+        verifier.verifyErrorFreeLog();
+        verifier.resetStreams();
+
+        IntegrationTestSuiteResults suite = HelperAssertions.parseTestResults( new File[]
{ testDir } );
+        HelperAssertions.assertTestSuiteResults( 1, 0, 0, 0, suite );
+    }
+}
\ No newline at end of file

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47concurrencyIT.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47concurrencyIT.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit47concurrencyIT.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4VersionsIT.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4VersionsIT.java?rev=898206&r1=898205&r2=898206&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4VersionsIT.java
(original)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Junit4VersionsIT.java
Tue Jan 12 07:39:49 2010
@@ -46,6 +46,22 @@
     {
         runJUnitTest( "4.4" );
     }
+
+    public void test45 () throws Exception
+    {
+        runJUnitTest( "4.5" );
+    }
+
+    public void test46 () throws Exception
+    {
+        runJUnitTest( "4.6" );
+    }
+
+    public void test47 () throws Exception
+    {
+        runJUnitTest( "4.7" );
+    }
+
     
     public void runJUnitTest (String version)
         throws Exception

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/pom.xml?rev=898206&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/pom.xml
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/pom.xml
Tue Jan 12 07:39:49 2010
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <groupId>org.apache.maven.plugins.surefire</groupId>
+  <artifactId>junit47</artifactId>
+  <version>1.0-SNAPSHOT</version>
+  <name>Test for JUnit 4.7</name>
+
+
+  <properties>
+    <junitVersion>4.7</junitVersion>
+  </properties>
+
+  <dependencies>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>${junitVersion}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-compiler-plugin</artifactId>
+        <configuration>
+          <source>1.5</source>
+          <target>1.5</target>
+        </configuration>
+      </plugin>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <version>${surefire.version}</version>
+          <configuration>
+              <parallel>methods</parallel>
+              <threadCount>2</threadCount>
+          </configuration>
+      </plugin>
+    </plugins>
+  </build>
+
+</project>

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/pom.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/BasicTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/BasicTest.java?rev=898206&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/BasicTest.java
(added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/BasicTest.java
Tue Jan 12 07:39:49 2010
@@ -0,0 +1,41 @@
+package concurrentjunit47.src.test.java.junit47;
+
+import org.junit.*;
+
+
+public class BasicTest
+{
+
+    private boolean setUpCalled = false;
+
+    private static boolean tearDownCalled = false;
+
+    @Before
+    public void setUp()
+    {
+        setUpCalled = true;
+        tearDownCalled = false;
+        System.out.println( "Called setUp" );
+    }
+
+    @After
+    public void tearDown()
+    {
+        setUpCalled = false;
+        tearDownCalled = true;
+        System.out.println( "Called tearDown" );
+    }
+
+    @Test
+    public void testSetUp()
+    {
+        Assert.assertTrue( "setUp was not called", setUpCalled );
+    }
+
+    @AfterClass
+    public static void oneTimeTearDown()
+    {
+
+    }
+
+}
\ No newline at end of file

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/BasicTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/BasicTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/concurrentjunit47/src/test/java/junit47/BasicTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java?rev=898206&r1=898205&r2=898206&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSet.java
Tue Jan 12 07:39:49 2010
@@ -79,10 +79,8 @@
 
     public static void execute(Class[] classes, ReporterManager reportManager, JUnitCoreParameters
jUnitCoreParameters)
             throws TestSetFailedException {
-        RunListener listener = new JUnitCoreTestSetReporter(reportManager);
-        if (jUnitCoreParameters.isAnyParallelitySelected()) {
-            listener = createRunListener(listener, jUnitCoreParameters.isConfigurableParallelComputerPresent());
-        }
+        RunListener realTarget = new JUnitCoreTestSetReporter(reportManager);
+        RunListener listener = createRunListener(realTarget, jUnitCoreParameters.isConfigurableParallelComputerPresent());
         Computer computer = getComputer(jUnitCoreParameters);
         try {
             runJunitCore(classes, computer, listener);
@@ -94,7 +92,9 @@
 
     private static RunListener createRunListener(RunListener realTarget, boolean configurableParallelComputerPresent)
             throws TestSetFailedException {
-        if (!configurableParallelComputerPresent) return new DemultiplexingRunListener(realTarget);
+        if (!configurableParallelComputerPresent) {
+            return new DemultiplexingRunListener(realTarget);
+        }
         try {
             Class<?> cpcClass = Class.forName(demuxerClassName);
             Constructor constructor = cpcClass.getConstructor(RunListener.class);

Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSetReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSetReporter.java?rev=898206&r1=898205&r2=898206&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSetReporter.java
(original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreTestSetReporter.java
Tue Jan 12 07:39:49 2010
@@ -21,6 +21,8 @@
 
 
 import java.util.ResourceBundle;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.maven.surefire.Surefire;
 import org.apache.maven.surefire.report.ReportEntry;
@@ -33,10 +35,21 @@
 class JUnitCoreTestSetReporter
     extends RunListener
 {
+
+    private static final Pattern PARENS = Pattern.compile(
+            "^" +
+            "[^\\(\\)]+" + //non-parens
+            "\\((" + // then an open-paren (start matching a group)
+            "[^\\\\(\\\\)]+" + //non-parens
+            ")\\)" +
+            "$" ); // then a close-paren (end group match)
+
     // Constants
     private static ResourceBundle bundle = ResourceBundle.getBundle( Surefire.SUREFIRE_BUNDLE_NAME
);
 
 
+    private Description currentRunStart;
+    private String currentClassName;
     private ReporterManager reportMgr;
 
     /**
@@ -63,8 +76,10 @@
         throws Exception
     {
         String rawString = bundle.getString( "testSetStarting" );
-        ReportEntry report = new ReportEntry( description.getClassName(), description.getDisplayName(),
rawString );
+        currentClassName = extractClassName(description);
+        currentRunStart = description;
 
+        ReportEntry report = new ReportEntry( description.getClassName(), currentClassName,
rawString );
         this.reportMgr.testSetStarting( report );
     }
 
@@ -77,7 +92,7 @@
         throws Exception
     {
         String rawString = bundle.getString( "testSetCompletedNormally" );
-        ReportEntry report = new ReportEntry( result.getClass().getCanonicalName(), result.getClass().getName(),
rawString );
+        ReportEntry report = new ReportEntry( currentRunStart.getClassName(), currentClassName,
rawString );
         this.reportMgr.testSetCompleted( report );
         this.reportMgr.reset();
     }
@@ -152,4 +167,13 @@
             this.reportMgr.testSucceeded( report );
         }
     }
+
+    private String extractClassName( Description description )
+    {
+        String displayName = description.getDisplayName();
+        Matcher m = PARENS.matcher( displayName );
+        if (!m.find()) return displayName;
+        return m.group( 1 );
+    }
+
 }



Mime
View raw message