You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2014/02/10 21:36:44 UTC

git commit: [SUREFIRE-1058] allow (very) simple regular-expressions in group parameter (only has an effect with TestNG)

Updated Branches:
  refs/heads/master 2fa201d31 -> 6edfdf756


[SUREFIRE-1058] allow (very) simple regular-expressions in group parameter (only has an effect with TestNG)


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/6edfdf75
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/6edfdf75
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/6edfdf75

Branch: refs/heads/master
Commit: 6edfdf756dd3ba7f6831e2093946616e38a52099
Parents: 2fa201d
Author: Andreas Gudian <ag...@apache.org>
Authored: Mon Feb 10 21:32:59 2014 +0100
Committer: Andreas Gudian <ag...@apache.org>
Committed: Mon Feb 10 21:32:59 2014 +0100

----------------------------------------------------------------------
 .../group/match/SingleGroupMatcher.java         | 20 +++++-
 .../src/main/javacc/category-expression.jj      | 20 +++---
 .../maven/surefire/its/TestNgGroupsIT.java      | 23 ++++--
 .../src/test/resources/testng-groups/pom.xml    | 10 +--
 .../java/testng/groups/TestNGGroupTest.java     | 76 ++++++++++++++++++++
 .../java/testng/jdk14/TestNGJavadocTest.java    | 74 -------------------
 6 files changed, 123 insertions(+), 100 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6edfdf75/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java
----------------------------------------------------------------------
diff --git a/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java b/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java
index 7de0a74..86021c9 100644
--- a/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java
+++ b/surefire-grouper/src/main/java/org/apache/maven/surefire/group/match/SingleGroupMatcher.java
@@ -1,4 +1,5 @@
 package org.apache.maven.surefire.group.match;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -17,7 +18,8 @@ package org.apache.maven.surefire.group.match;
  * specific language governing permissions and limitations
  * under the License.
  */
-
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
 
 public class SingleGroupMatcher
     implements GroupMatcher
@@ -27,9 +29,20 @@ public class SingleGroupMatcher
 
     private Class<?> enabledClass;
 
+    private Pattern pattern;
+
     public SingleGroupMatcher( String enabled )
     {
         this.enabled = enabled.endsWith( ".class" ) ? enabled.substring( 0, enabled.length() - 6 ) : enabled;
+
+        try
+        {
+            this.pattern = Pattern.compile( enabled );
+        }
+        catch ( PatternSyntaxException pse )
+        {
+            // ignore
+        }
     }
 
     @Override
@@ -118,6 +131,11 @@ public class SingleGroupMatcher
             {
                 return true;
             }
+
+            if ( pattern != null && pattern.matcher( cat ).matches() )
+            {
+                return true;
+            }
         }
 
         return false;

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6edfdf75/surefire-grouper/src/main/javacc/category-expression.jj
----------------------------------------------------------------------
diff --git a/surefire-grouper/src/main/javacc/category-expression.jj b/surefire-grouper/src/main/javacc/category-expression.jj
index ab1589e..955ed4f 100644
--- a/surefire-grouper/src/main/javacc/category-expression.jj
+++ b/surefire-grouper/src/main/javacc/category-expression.jj
@@ -35,12 +35,12 @@ public class GroupMatcherParser
         }
         }
     }
-    
+
     public GroupMatcherParser( String expression )
     {
         this( (Reader)(new StringReader( expression ) ) );
     }
-    
+
     private GroupMatcher getMatcher( Op op, GroupMatcher...matchers )
     {
       GroupMatcher matcher = null;
@@ -52,10 +52,10 @@ public class GroupMatcherParser
       {
         matcher = new OrGroupMatcher( matchers );
       }
-      
+
       return matcher;
     }
-    
+
     public enum Op
     {
       AND, OR;
@@ -83,7 +83,7 @@ TOKEN:
 | <BANG:  "!">
 | <LPAREN: "(">
 | <RPAREN: ")">
-| <STRING: (["A"-"Z", "a"-"z", "-", "0"-"9", "_", "$", "#", "."])+ >
+| <STRING: (["A"-"Z", "a"-"z", "-", "0"-"9", "_", "$", "#", ".", "*", "\\"])+ >
 | <CLS:    ".class">
 }
 
@@ -122,7 +122,7 @@ Op op=null;
     {
       matcher = getMatcher( op, lhs, rhs );
     }
-    
+
     return matcher;
   }
 }
@@ -153,7 +153,7 @@ Op op=null;
     {
       matcher = getMatcher( op, lhs, rhs );
     }
-    
+
     return inverted ? new InverseGroupMatcher( matcher ) : matcher;
   }
 }
@@ -180,15 +180,15 @@ Op op() :
 (
   <AND>
   {o=Op.AND;}
-| <OR> 
+| <OR>
   {o=Op.OR;}
-| <AMP2> 
+| <AMP2>
   {o=Op.AND;}
 | <PIPE2>
   {o=Op.OR;}
 | <COMMA>
   {o=Op.OR;}
-)  
+)
   {return o;}
 }
 

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6edfdf75/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgGroupsIT.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgGroupsIT.java b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgGroupsIT.java
index 1849d79..74771c8 100644
--- a/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgGroupsIT.java
+++ b/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/TestNgGroupsIT.java
@@ -25,29 +25,40 @@ import org.apache.maven.surefire.its.fixture.SurefireLauncher;
 import org.junit.Test;
 
 /**
- * Test that TestNG's @Test(threadPoolSize = n, invocationCount=n) causes tests to be run in parallel.
+ * Test the group filter for TestNG
  *
- * @author <a href="mailto:spam.haikal@gmail.com">Haikal Saadh</a>
  */
 public class TestNgGroupsIT
     extends SurefireJUnit4IntegrationTestCase
 {
     @Test
-    public void testNgGroupThreadParallel()
+    public void testExclusion()
     {
-        unpack().setExcludedGroups( "notincluded" ).executeTest().verifyErrorFree( 1 );
+        unpack().setExcludedGroups( "notincluded" ).executeTest().verifyErrorFree( 5 );
     }
 
     @Test
-    public void groups()
+    public void testOnlyGroups()
     {
         unpack().setGroups( "functional" ).executeTest().verifyErrorFree( 2 );
     }
 
     @Test
+    public void testGroupsAndExclusion()
+    {
+        unpack().setGroups( "functional" ).setExcludedGroups( "notincluded" ).executeTest().verifyErrorFree( 1 );
+    }
+
+    @Test
     public void groupsWithDash()
     {
-        unpack().setGroups( "abc-def" ).executeTest().verifyErrorFree( 0 );
+        unpack().setGroups( "abc-def" ).executeTest().verifyErrorFree( 1 );
+    }
+
+    @Test
+    public void groupsBySimpleRegex()
+    {
+        unpack().setGroups( "foo\\..*" ).executeTest().verifyErrorFree( 2 );
     }
 
     public SurefireLauncher unpack()

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6edfdf75/surefire-integration-tests/src/test/resources/testng-groups/pom.xml
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/testng-groups/pom.xml b/surefire-integration-tests/src/test/resources/testng-groups/pom.xml
index ab91f7c..bfb205e 100644
--- a/surefire-integration-tests/src/test/resources/testng-groups/pom.xml
+++ b/surefire-integration-tests/src/test/resources/testng-groups/pom.xml
@@ -30,22 +30,14 @@
 
   <dependencies>
     <dependency>
-      <groupId>junit</groupId>
-      <artifactId>junit</artifactId>
-      <version>3.8.1</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
       <groupId>org.testng</groupId>
       <artifactId>testng</artifactId>
-      <version>5.7</version>
-      <classifier>jdk14</classifier>
+      <version>6.8.7</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
 
   <build>
-    <testSourceDirectory>src/test/java</testSourceDirectory>
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6edfdf75/surefire-integration-tests/src/test/resources/testng-groups/src/test/java/testng/groups/TestNGGroupTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/testng-groups/src/test/java/testng/groups/TestNGGroupTest.java b/surefire-integration-tests/src/test/resources/testng-groups/src/test/java/testng/groups/TestNGGroupTest.java
new file mode 100644
index 0000000..5d84bba
--- /dev/null
+++ b/surefire-integration-tests/src/test/resources/testng-groups/src/test/java/testng/groups/TestNGGroupTest.java
@@ -0,0 +1,76 @@
+package testng.groups;
+
+/*
+ * 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.testng.Assert;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+/**
+ * Tests grouping
+ */
+public class TestNGGroupTest
+{
+    private Object testObject;
+
+    @BeforeClass( groups = "functional" )
+    public void configureTest()
+    {
+        testObject = new Object();
+    }
+
+    @Test( groups = { "functional" } )
+    public void isFunctional()
+    {
+        Assert.assertNotNull( testObject, "testObject is null" );
+    }
+
+    @Test( groups = { "functional", "notincluded" } )
+    public void isFunctionalAndNotincluded()
+    {
+        Assert.assertNotNull( testObject, "testObject is null" );
+    }
+
+    @Test( groups = "notincluded" )
+    public void isNotIncluded()
+    {
+        Assert.assertTrue( false );
+    }
+
+    @Test( groups = "abc-def" )
+    public void isDashedGroup()
+    {
+    }
+
+    @Test( groups = "foo.bar" )
+    public void isFooBar()
+    {
+    }
+
+    @Test( groups = "foo.zap" )
+    public void isFooZap()
+    {
+    }
+
+    @Test
+    public void noGroup()
+    {
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/6edfdf75/surefire-integration-tests/src/test/resources/testng-groups/src/test/java/testng/jdk14/TestNGJavadocTest.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/testng-groups/src/test/java/testng/jdk14/TestNGJavadocTest.java b/surefire-integration-tests/src/test/resources/testng-groups/src/test/java/testng/jdk14/TestNGJavadocTest.java
deleted file mode 100644
index 0a7284d..0000000
--- a/surefire-integration-tests/src/test/resources/testng-groups/src/test/java/testng/jdk14/TestNGJavadocTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package testng.jdk14;
-
-/*
- * 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.testng.Assert;
-
-
-/**
- * Tests that forcing testng to run tests via the <code>"${maven.test.forcetestng}"</code>
- * configuration option works.
- *
- * @author jkuhnert
- */
-public class TestNGJavadocTest
-{
-
-    /**
-     * Sets up testObject
-     *
-     * @testng.configuration beforeTestClass = "true" groups = "functional"
-     */
-    public void configureTest()
-    {
-        testObject = new Object();
-    }
-
-    Object testObject;
-
-    /**
-     * Tests reporting an error
-     *
-     * @testng.test groups = "functional, notincluded"
-     */
-    public void isTestObjectNull()
-    {
-        Assert.assertNotNull( testObject, "testObject is null" );
-    }
-
-    /**
-     * Sample method that shouldn't be run by test suite.
-     *
-     * @testng.test groups = "notincluded"
-     */
-    public void shouldNotRun()
-    {
-        Assert.assertTrue( false, "Group specified by test shouldnt be run." );
-    }
-
-    /**
-     * Sample method that shouldn't be run by test suite.
-     * @testng.test groups = "functional"
-     */
-    public void noGroup()
-    {
-    }
-
-}