corrected exclusion logic, added more unit tests & scripted tests

This commit is contained in:
Matthew Farwell 2015-04-17 09:28:58 +02:00
parent 0e56878534
commit d4cffdddd9
4 changed files with 28 additions and 12 deletions

View File

@ -566,17 +566,19 @@ object Defaults extends BuildCommon {
def selectedFilter(args: Seq[String]): Seq[String => Boolean] =
{
val (excludeArgs, includeArgs) = args.partition(s => s.startsWith("-"))
def matches(nfs: Seq[NameFilter], s: String) = nfs.exists(_.accept(s))
val (excludeArgs, includeArgs) = args.partition(_.startsWith("-"))
val includeFilters = includeArgs map GlobFilter.apply
val excludeFilters = excludeArgs.map(_.substring(1)).map(GlobFilter.apply)
if (includeFilters.isEmpty && excludeArgs.isEmpty)
if (includeFilters.isEmpty && excludeArgs.isEmpty) {
Seq(const(true))
else if (includeFilters.isEmpty) {
excludeFilters.map { f => (s: String) => !f.accept(s) }
} else if (includeFilters.isEmpty) {
Seq({ (s: String) => !matches(excludeFilters, s) })
} else {
includeFilters.map { f => (s: String) => (f.accept(s) && !excludeFilters.exists(x => x.accept(s))) }
includeFilters.map { f => (s: String) => (f.accept(s) && !matches(excludeFilters, s)) }
}
}
def detectTests: Initialize[Task[Seq[TestDefinition]]] = (loadedTestFrameworks, compile, streams) map { (frameworkMap, analysis, s) =>

View File

@ -5,13 +5,13 @@ import java.io._
import org.specs2.mutable.Specification
object DefaultsTest extends Specification {
private def assertFiltered(filter: List[String], expected: Map[String, Boolean]) = {
val actual = expected.map(t => (t._1, Defaults.selectedFilter(filter).exists(fn => fn(t._1))))
actual must be equalTo (expected)
}
"`selectedFilter`" should {
def assertFiltered(filter: List[String], expected: Map[String, Boolean]) = {
val actual = expected.map(t => (t._1, Defaults.selectedFilter(filter).exists(fn => fn(t._1))))
actual must be equalTo (expected)
}
"return all tests for an empty list" in {
assertFiltered(List(), Map("Test1" -> true, "Test2" -> true))
}
@ -39,6 +39,14 @@ object DefaultsTest extends Specification {
"cope with multiple filters" in {
assertFiltered(List("T*1", "T*2", "-F*"), Map("Test1" -> true, "Test2" -> true, "Foo" -> false))
}
"cope with multiple exclusion filters, no includes" in {
assertFiltered(List("-A*", "-F*"), Map("Test1" -> true, "Test2" -> true, "AAA" -> false, "Foo" -> false))
}
"cope with multiple exclusion filters with includes" in {
assertFiltered(List("T*", "-T*1", "-T*2"), Map("Test1" -> false, "Test2" -> false, "Test3" -> true))
}
}
}

View File

@ -259,7 +259,7 @@ abstract class MavenRepositoryResolver(settings: IvySettings) extends AbstractRe
// Here we add in additional artifact requests, which ALLWAYS have to be explicit since
// Maven/Aether doesn't include all known artifacts in a pom.xml
// TODO - This does not appear to be working correctly.
if (dd.getAllDependencyArtifacts.isEmpty) {
if (dd.getAllDependencyArtifacts.isEmpty) {
val artifactId = s"${drid.getName}-${drid.getRevision}"
// Add the artifacts we know about the module
packaging match {

View File

@ -53,3 +53,9 @@ $ delete target/Test2.run
> test-only -Test*
-$ exists target/Test1.run
-$ exists target/Test2.run
# with only glob exclusion
> test-only -T*1 -T*2
-$ exists target/Test1.run
-$ exists target/Test2.run