You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jd...@apache.org on 2012/01/24 20:05:34 UTC

svn commit: r1235416 - in /maven/surefire/trunk: maven-surefire-common/src/main/javacc/ maven-surefire-common/src/test/java/org/apache/maven/surefire/group/parse/ surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/

Author: jdcasey
Date: Tue Jan 24 19:05:34 2012
New Revision: 1235416

URL: http://svn.apache.org/viewvc?rev=1235416&view=rev
Log:
[SUREFIRE-809] process comma-separated lists with the expression parser, as OR chains

Modified:
    maven/surefire/trunk/maven-surefire-common/src/main/javacc/category-expression.jj
    maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/group/parse/GroupMatcherParserTest.java
    maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java

Modified: maven/surefire/trunk/maven-surefire-common/src/main/javacc/category-expression.jj
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/javacc/category-expression.jj?rev=1235416&r1=1235415&r2=1235416&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/main/javacc/category-expression.jj (original)
+++ maven/surefire/trunk/maven-surefire-common/src/main/javacc/category-expression.jj Tue Jan 24 19:05:34 2012
@@ -78,6 +78,7 @@ TOKEN:
 | <OR:  (["O","o"] ["R", "r"]) >
 | <AMP2: "&&">
 | <PIPE2: "||">
+| <COMMA: ",">
 | <NOT:   "NOT">
 | <BANG:  "!">
 | <LPAREN: "(">
@@ -185,6 +186,8 @@ Op op() :
   {o=Op.AND;}
 | <PIPE2>
   {o=Op.OR;}
+| <COMMA>
+  {o=Op.OR;}
 )  
   {return o;}
 }

Modified: maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/group/parse/GroupMatcherParserTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/group/parse/GroupMatcherParserTest.java?rev=1235416&r1=1235415&r2=1235416&view=diff
==============================================================================
--- maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/group/parse/GroupMatcherParserTest.java (original)
+++ maven/surefire/trunk/maven-surefire-common/src/test/java/org/apache/maven/surefire/group/parse/GroupMatcherParserTest.java Tue Jan 24 19:05:34 2012
@@ -50,6 +50,17 @@ public class GroupMatcherParserTest
         assertTrue( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
     }
 
+    public void testBareCommaSeparatedORedPair()
+        throws ParseException
+    {
+        GroupMatcher matcher =
+            new GroupMatcherParser( GroupMatcherParser.class.getName() + ", " + SingleGroupMatcher.class.getName() ).parse();
+
+        assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof OrGroupMatcher );
+        assertTrue( matcher.enabled( GroupMatcherParser.class ) );
+        assertTrue( matcher.enabled( GroupMatcherParser.class, SingleGroupMatcher.class ) );
+    }
+
     public void testParseGroupedANDedPair()
         throws ParseException
     {
@@ -110,7 +121,6 @@ public class GroupMatcherParserTest
         throws ParseException
     {
         GroupMatcher matcher = new GroupMatcherParser( SingleGroupMatcher.class.getSimpleName() ).parse();
-        System.out.println( matcher );
         assertTrue( "Wrong matcher type: " + matcher.getClass().getName(), matcher instanceof SingleGroupMatcher );
         assertTrue( matcher.enabled( SingleGroupMatcher.class ) );
     }

Modified: maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java?rev=1235416&r1=1235415&r2=1235416&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java (original)
+++ maven/surefire/trunk/surefire-providers/common-junit48/src/main/java/org/apache/maven/surefire/common/junit48/FilterFactory.java Tue Jan 24 19:05:34 2012
@@ -32,7 +32,6 @@ import org.apache.maven.surefire.booter.
 import org.apache.maven.surefire.group.match.AndGroupMatcher;
 import org.apache.maven.surefire.group.match.GroupMatcher;
 import org.apache.maven.surefire.group.match.InverseGroupMatcher;
-import org.apache.maven.surefire.group.match.OrGroupMatcher;
 import org.apache.maven.surefire.group.parse.GroupMatcherParser;
 import org.apache.maven.surefire.group.parse.ParseException;
 import org.codehaus.plexus.util.SelectorUtils;
@@ -56,8 +55,37 @@ public class FilterFactory
     {
         String groups = providerProperties.getProperty( ProviderParameterNames.TESTNG_GROUPS_PROP );
         String excludedGroups = providerProperties.getProperty( ProviderParameterNames.TESTNG_EXCLUDEDGROUPS_PROP );
-        GroupMatcher included = commaSeparatedListToFilters( groups );
-        GroupMatcher excluded = commaSeparatedListToFilters( excludedGroups );
+
+        GroupMatcher included = null;
+        if ( groups != null )
+        {
+            try
+            {
+                included = new GroupMatcherParser( groups ).parse();
+            }
+            catch ( ParseException e )
+            {
+                throw new IllegalArgumentException( "Invalid group expression: '" + groups + "'. Reason: "
+                    + e.getMessage(), e );
+            }
+        }
+
+        GroupMatcher excluded = null;
+        if ( excludedGroups != null )
+        {
+            try
+            {
+                excluded = new GroupMatcherParser( excludedGroups ).parse();
+            }
+            catch ( ParseException e )
+            {
+                throw new IllegalArgumentException( "Invalid group expression: '" + excludedGroups + "'. Reason: "
+                    + e.getMessage(), e );
+            }
+        }
+
+        // GroupMatcher included = commaSeparatedListToFilters( groups );
+        // GroupMatcher excluded = commaSeparatedListToFilters( excludedGroups );
 
         if ( included != null && testClassLoader != null )
         {
@@ -72,37 +100,37 @@ public class FilterFactory
         return new GroupMatcherCategoryFilter( included, excluded );
     }
 
-    private GroupMatcher commaSeparatedListToFilters( String str )
-    {
-        List<GroupMatcher> included = new ArrayList<GroupMatcher>();
-        if ( str != null )
-        {
-            for ( String group : str.split( "," ) )
-            {
-                group = group.trim();
-                if ( group == null || group.length() == 0)
-                {
-                    continue;
-                }
-
-                try
-                {
-                    GroupMatcher matcher = new GroupMatcherParser( group ).parse();
-                    included.add( matcher );
-                }
-                catch ( ParseException e )
-                {
-                    throw new IllegalArgumentException( "Invalid group expression: '" + group + "'. Reason: "
-                        + e.getMessage(), e );
-                }
-
-                // Class<?> categoryType = classloadCategory( group );
-                // included.add( Categories.CategoryFilter.include( categoryType ) );
-            }
-        }
-
-        return included.isEmpty() ? null : new OrGroupMatcher( included );
-    }
+    // private GroupMatcher commaSeparatedListToFilters( String str )
+    // {
+    // List<GroupMatcher> included = new ArrayList<GroupMatcher>();
+    // if ( str != null )
+    // {
+    // for ( String group : str.split( "," ) )
+    // {
+    // group = group.trim();
+    // if ( group == null || group.length() == 0)
+    // {
+    // continue;
+    // }
+    //
+    // try
+    // {
+    // GroupMatcher matcher = new GroupMatcherParser( group ).parse();
+    // included.add( matcher );
+    // }
+    // catch ( ParseException e )
+    // {
+    // throw new IllegalArgumentException( "Invalid group expression: '" + group + "'. Reason: "
+    // + e.getMessage(), e );
+    // }
+    //
+    // // Class<?> categoryType = classloadCategory( group );
+    // // included.add( Categories.CategoryFilter.include( categoryType ) );
+    // }
+    // }
+    //
+    // return included.isEmpty() ? null : new OrGroupMatcher( included );
+    // }
 
     public Filter createMethodFilter( String requestedTestMethod )
     {