Skip to content

Commit

Permalink
[SUREFIRE-1964] Support for method filtering on excludesFile and incl…
Browse files Browse the repository at this point in the history
…udesFile

committers: Ildefonso Montero, Tibor Digaňa
Add the implementation and integration tests
Add some unit tests
Add some javadoc to includesFile and excludesFile
  • Loading branch information
imonteroperez authored and Tibor17 committed Mar 17, 2022
1 parent 064d554 commit d3e1fcb
Show file tree
Hide file tree
Showing 12 changed files with 440 additions and 58 deletions.
Expand Up @@ -364,6 +364,11 @@ public class IntegrationTestMojo
* **{@literal /}NotIncludedByDefault.java
* %regex[.*IT.*|.*Not.*]
* </code></pre>
* <br>
* Since 3.0.0-M6, method filtering support is provided in the inclusions file as well, example:
* <pre><code>
* pkg.SomeIT#testMethod
* </code></pre>
*
* @since 2.13
*/
Expand All @@ -379,6 +384,11 @@ public class IntegrationTestMojo
* **{@literal /}DontRunIT.*
* %regex[.*IT.*|.*Not.*]
* </code></pre>
* <br>
* Since 3.0.0-M6, method filtering support is provided in the exclusions file as well, example:
* <pre><code>
* pkg.SomeIT#testMethod
* </code></pre>
*
* @since 2.13
*/
Expand Down
Expand Up @@ -2194,78 +2194,110 @@ private boolean isSpecificTestSpecified()
}
}

private void maybeAppendList( List<String> base, List<String> list )
@Nonnull
private List<String> getExcludedScanList()
throws MojoFailureException
{
if ( list != null )
{
base.addAll( list );
}
return getExcludeList( true );
}

@Nonnull private List<String> getExcludeList()
@Nonnull
private List<String> getExcludeList()
throws MojoFailureException
{
return getExcludeList( false );
}

/**
* Computes a merge list of test exclusions.
* Used only in {@link #getExcludeList()} and {@link #getExcludedScanList()}.
* @param asScanList true if dependency or directory scanner
* @return list of patterns
* @throws MojoFailureException if the excludes breaks a pattern format
*/
@Nonnull
private List<String> getExcludeList( boolean asScanList )
throws MojoFailureException
{
List<String> actualExcludes = null;
List<String> excludes;
if ( isSpecificTestSpecified() )
{
actualExcludes = Collections.emptyList();
excludes = Collections.emptyList();
}
else
{
if ( getExcludesFile() != null )
excludes = new ArrayList<>();
if ( asScanList )
{
actualExcludes = readListFromFile( getExcludesFile() );
if ( getExcludes() != null )
{
excludes.addAll( getExcludes() );
}
checkMethodFilterInIncludesExcludes( excludes );
}

if ( actualExcludes == null )
{
actualExcludes = getExcludes();
}
else
if ( getExcludesFile() != null )
{
maybeAppendList( actualExcludes, getExcludes() );
excludes.addAll( readListFromFile( getExcludesFile() ) );
}

checkMethodFilterInIncludesExcludes( actualExcludes );

if ( actualExcludes == null || actualExcludes.isEmpty() )
if ( asScanList && excludes.isEmpty() )
{
actualExcludes = Collections.singletonList( getDefaultExcludes() );
excludes = Collections.singletonList( getDefaultExcludes() );
}
}
return filterNulls( actualExcludes );
return filterNulls( excludes );
}

@Nonnull
private List<String> getIncludedScanList()
throws MojoFailureException
{
return getIncludeList( true );
}

@Nonnull
private List<String> getIncludeList()
throws MojoFailureException
{
List<String> includes = null;
return getIncludeList( false );
}

/**
* Computes a merge list of test inclusions.
* Used only in {@link #getIncludeList()} and {@link #getIncludedScanList()}.
* @param asScanList true if dependency or directory scanner
* @return list of patterns
* @throws MojoFailureException if the includes breaks a pattern format
*/
@Nonnull
private List<String> getIncludeList( boolean asScanList )
throws MojoFailureException
{
final List<String> includes = new ArrayList<>();
if ( isSpecificTestSpecified() )
{
includes = new ArrayList<>();
addAll( includes, split( getTest(), "," ) );
}
else
{
if ( getIncludesFile() != null )
if ( asScanList )
{
includes = readListFromFile( getIncludesFile() );
if ( getIncludes() != null )
{
includes.addAll( getIncludes() );
}
checkMethodFilterInIncludesExcludes( includes );
}

if ( includes == null )
{
includes = getIncludes();
}
else
if ( getIncludesFile() != null )
{
maybeAppendList( includes, getIncludes() );
includes.addAll( readListFromFile( getIncludesFile() ) );
}

checkMethodFilterInIncludesExcludes( includes );

if ( includes == null || includes.isEmpty() )
if ( asScanList && includes.isEmpty() )
{
includes = asList( getDefaultIncludes() );
addAll( includes, getDefaultIncludes() );
}
}

Expand All @@ -2275,16 +2307,12 @@ private List<String> getIncludeList()
private void checkMethodFilterInIncludesExcludes( Iterable<String> patterns )
throws MojoFailureException
{
if ( patterns != null )
for ( String pattern : patterns )
{
for ( String pattern : patterns )
if ( pattern != null && pattern.contains( "#" ) )
{
if ( pattern != null && pattern.contains( "#" ) )
{
throw new MojoFailureException( "Method filter prohibited in "
+ "includes|excludes|includesFile|excludesFile parameter: "
+ pattern );
}
throw new MojoFailureException( "Method filter prohibited in includes|excludes parameter: "
+ pattern );
}
}
}
Expand All @@ -2294,16 +2322,18 @@ private TestListResolver getIncludedAndExcludedTests()
{
if ( includedExcludedTests == null )
{
includedExcludedTests = new TestListResolver( getIncludeList(), getExcludeList() );
includedExcludedTests = new TestListResolver( getIncludedScanList(), getExcludedScanList() );
getConsoleLogger().debug( "Resolved included and excluded patterns: " + includedExcludedTests );
}
return includedExcludedTests;
}

public TestListResolver getSpecificTests()
throws MojoFailureException
{
if ( specificTests == null )
{
specificTests = new TestListResolver( getTest() );
specificTests = new TestListResolver( getIncludeList(), getExcludeList() );
}
return specificTests;
}
Expand Down

0 comments on commit d3e1fcb

Please sign in to comment.