Return-Path: X-Original-To: apmail-maven-commits-archive@www.apache.org Delivered-To: apmail-maven-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6DC091018B for ; Mon, 10 Feb 2014 20:36:47 +0000 (UTC) Received: (qmail 79188 invoked by uid 500); 10 Feb 2014 20:36:45 -0000 Delivered-To: apmail-maven-commits-archive@maven.apache.org Received: (qmail 79135 invoked by uid 500); 10 Feb 2014 20:36:45 -0000 Mailing-List: contact commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@maven.apache.org Delivered-To: mailing list commits@maven.apache.org Received: (qmail 79128 invoked by uid 99); 10 Feb 2014 20:36:45 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Feb 2014 20:36:45 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id E010A9227F2; Mon, 10 Feb 2014 20:36:44 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agudian@apache.org To: commits@maven.apache.org Message-Id: <1c2eb559ca634d21b9cb6d24398b5f5a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: [SUREFIRE-1058] allow (very) simple regular-expressions in group parameter (only has an effect with TestNG) Date: Mon, 10 Feb 2014 20:36:44 +0000 (UTC) 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 Authored: Mon Feb 10 21:32:59 2014 +0100 Committer: Andreas Gudian 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: | | | -| +| | } @@ -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() : ( {o=Op.AND;} -| +| {o=Op.OR;} -| +| {o=Op.AND;} | {o=Op.OR;} | {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 Haikal Saadh */ 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 @@ - junit - junit - 3.8.1 - test - - org.testng testng - 5.7 - jdk14 + 6.8.7 test - src/test/java org.apache.maven.plugins 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 "${maven.test.forcetestng}" - * 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() - { - } - -}