You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2022/03/02 13:50:21 UTC

[maven-surefire] branch inc-exc-files updated (505d862 -> 9c7c0d7)

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a change to branch inc-exc-files
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git.


    from 505d862  added ITs
     new 3fce813  Add some javadoc to includesFile and excludesFile
     new 9c7c0d7  unit tests

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../plugin/surefire/AbstractSurefireMojoTest.java  | 105 ++++++++++++++++++++-
 .../maven/plugin/surefire/SurefirePlugin.java      |  12 +++
 2 files changed, 112 insertions(+), 5 deletions(-)

[maven-surefire] 01/02: Add some javadoc to includesFile and excludesFile

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch inc-exc-files
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 3fce8130ac25188780a6a747319f115a61257313
Author: imonteroperez <im...@cloudbees.com>
AuthorDate: Tue Feb 8 18:14:04 2022 +0100

    Add some javadoc to includesFile and excludesFile
---
 .../org/apache/maven/plugin/surefire/SurefirePlugin.java     | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
index 0e3d850..6e983cb 100644
--- a/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
+++ b/maven-surefire-plugin/src/main/java/org/apache/maven/plugin/surefire/SurefirePlugin.java
@@ -326,6 +326,12 @@ public class SurefirePlugin
      * **{@literal /}NotIncludedByDefault.java
      * %regex[.*Test.*|.*Not.*]
      * </code></pre>
+     * 
+     * Since 3.0.0-M6, method filtering support is provided in includes file. Example:
+     * <pre><code>
+     * foo.bar.SomeTest#test
+     * com.test.Test#testMethod
+     * </code></pre>
      *
      * @since 2.13
      */
@@ -341,6 +347,12 @@ public class SurefirePlugin
      * %regex[.*Test.*|.*Not.*]
      * </code></pre>
      *
+     * Since 3.0.0-M6, method filtering support is provided in excludes file. Example:
+     * <pre><code>
+     * foo.bar.SomeTest#test
+     * com.test.Test#testMethod
+     * </code></pre>
+     *
      * @since 2.13
      */
     @Parameter( property = "surefire.excludesFile" )

[maven-surefire] 02/02: unit tests

Posted by ti...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch inc-exc-files
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 9c7c0d7b0bc5956ab59e95a16a21eadaf9040a66
Author: tibordigana <ti...@apache.org>
AuthorDate: Wed Mar 2 14:50:12 2022 +0100

    unit tests
---
 .../plugin/surefire/AbstractSurefireMojoTest.java  | 105 ++++++++++++++++++++-
 1 file changed, 100 insertions(+), 5 deletions(-)

diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
index b1afb7f..954dc8c 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/AbstractSurefireMojoTest.java
@@ -30,14 +30,17 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.LinkedHashSet;
+import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.DefaultArtifact;
 import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
 import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
@@ -84,6 +87,7 @@ import org.powermock.core.classloader.annotations.PrepareForTest;
 import org.powermock.modules.junit4.PowerMockRunner;
 
 import static java.io.File.separatorChar;
+import static java.nio.charset.StandardCharsets.UTF_8;
 import static java.nio.file.Files.write;
 import static java.util.Arrays.asList;
 import static java.util.Collections.emptyList;
@@ -95,8 +99,8 @@ import static org.apache.maven.artifact.versioning.VersionRange.createFromVersio
 import static org.apache.maven.surefire.shared.lang3.JavaVersion.JAVA_9;
 import static org.apache.maven.surefire.shared.lang3.JavaVersion.JAVA_RECENT;
 import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
-import static org.codehaus.plexus.languages.java.jpms.ModuleNameSource.MODULEDESCRIPTOR;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.codehaus.plexus.languages.java.jpms.ModuleNameSource.MODULEDESCRIPTOR;
 import static org.junit.Assert.fail;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.ArgumentMatchers.anyString;
@@ -1990,6 +1994,11 @@ public class AbstractSurefireMojoTest
         private int failOnFlakeCount;
         private String[] includeJUnit5Engines;
         private String[] excludeJUnit5Engines;
+        private List<Artifact> projectTestArtifacts;
+        private File includesFile;
+        private File excludesFile;
+        private List<String> includes;
+        private List<String> excludes;
 
         private JUnitPlatformProviderInfo createJUnitPlatformProviderInfo( Artifact junitPlatformArtifact,
                                                                            TestClassPath testClasspathWrapper )
@@ -1997,6 +2006,17 @@ public class AbstractSurefireMojoTest
             return new JUnitPlatformProviderInfo( junitPlatformArtifact, testClasspathWrapper );
         }
 
+        void setProjectTestArtifacts( List<Artifact> projectTestArtifacts )
+        {
+            this.projectTestArtifacts = projectTestArtifacts;
+        }
+
+        @Override
+        List<Artifact> getProjectTestArtifacts()
+        {
+            return projectTestArtifacts;
+        }
+
         @Override
         protected void logDebugOrCliShowErrors( String s )
         {
@@ -2126,19 +2146,24 @@ public class AbstractSurefireMojoTest
         @Override
         public List<String> getIncludes()
         {
-            return null;
+            return includes;
+        }
+
+        void setIncludesFile( File includesFile )
+        {
+            this.includesFile = includesFile;
         }
 
         @Override
         public File getIncludesFile()
         {
-            return null;
+            return includesFile;
         }
 
         @Override
         public void setIncludes( List<String> includes )
         {
-
+            this.includes = includes;
         }
 
         @Override
@@ -2297,10 +2322,15 @@ public class AbstractSurefireMojoTest
             return null;
         }
 
+        void setExcludesFile( File excludesFile )
+        {
+            this.excludesFile = excludesFile;
+        }
+
         @Override
         public File getExcludesFile()
         {
-            return null;
+            return excludesFile;
         }
 
         @Override
@@ -2471,6 +2501,71 @@ public class AbstractSurefireMojoTest
         }
     }
 
+    @Test
+    public void shouldNotPerformMethodFilteringOnIncludes() throws Exception
+    {
+        Mojo plugin = new Mojo();
+
+        File includesExcludes = File.createTempFile( "surefire", "-includes" );
+        FileUtils.write( includesExcludes, "AnotherTest#method" , UTF_8 );
+        plugin.setIncludesFile( includesExcludes );
+
+        List<String> includes = new LinkedList<>();
+        includes.add( "AnotherTest#method " );
+        plugin.setIncludes( includes );
+
+        VersionRange version = VersionRange.createFromVersion( "1.0" );
+        ArtifactHandler handler = new DefaultArtifactHandler();
+        Artifact testDeps = new DefaultArtifact( "g", "a", version, "compile", "jar", null, handler );
+        File artifactFile = File.createTempFile( "surefire", ".jar" );
+        artifactFile.deleteOnExit();
+        testDeps.setFile( artifactFile );
+        plugin.setProjectTestArtifacts( singletonList( testDeps ) );
+        plugin.setDependenciesToScan( new String[] { "g:a" } );
+
+        try
+        {
+            plugin.scanDependencies();
+            fail( "MojoFailureException expected" );
+        }
+        catch ( MojoFailureException e )
+        {
+            assertThat( e.getLocalizedMessage() )
+                .isEqualTo( "Method filter prohibited in includes|excludes parameter: AnotherTest#method " );
+        }
+    }
+
+    @Test
+    public void shouldPerformMethodFilteringOnIncludesExcludesFile() throws Exception
+    {
+        Mojo plugin = new Mojo();
+
+        plugin.setLogger( mock( Logger.class ) );
+
+        File includesExcludes = File.createTempFile( "surefire", "-includes" );
+        FileUtils.write( includesExcludes, "AnotherTest#method" , UTF_8 );
+        plugin.setIncludesFile( includesExcludes );
+        plugin.setExcludesFile( includesExcludes );
+
+        VersionRange version = VersionRange.createFromVersion( "1.0" );
+        ArtifactHandler handler = new DefaultArtifactHandler();
+        Artifact testDeps = new DefaultArtifact( "g", "a", version, "compile", "test-jar", null, handler );
+        File artifactFile = File.createTempFile( "surefire", "-classes" );
+        String classDir = artifactFile.getCanonicalPath();
+        assertThat( artifactFile.delete() ).isTrue();
+        File classes = new File( classDir );
+        assertThat( classes.mkdir() ).isTrue();
+        testDeps.setFile( classes );
+        assertThat( new File( classes, "AnotherTest.class" ).createNewFile() )
+            .isTrue();
+        plugin.setProjectTestArtifacts( singletonList( testDeps ) );
+        plugin.setDependenciesToScan( new String[] { "g:a" } );
+
+        DefaultScanResult result = plugin.scanDependencies();
+        assertThat ( result.getClasses() ).hasSize( 1 );
+        assertThat ( result.getClasses().iterator().next() ).isEqualTo( "AnotherTest" );
+    }
+
     private static File mockFile( String absolutePath )
     {
         File f = mock( File.class );