Skip to content

Commit

Permalink
the classpath for tests can now be limited to those classes not commi…
Browse files Browse the repository at this point in the history
…ng from jars.
  • Loading branch information
schauder committed Jan 15, 2014
1 parent 2b59a5a commit 5e70d0b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Expand Up @@ -63,10 +63,12 @@ case class ConstraintBuilder(

def noJars: ConstraintBuilder = copy(config = config.copy(classpath = config.classpath.map(noJars(_))))

private def noJars(s: String) = if (s.endsWith(".jar"))
""
else
s
private def noJars(s: String) = {
def isJar(s: String) = s.endsWith(".jar")
val sep = System.getProperty("path.separator")
val elements = s.split(sep)
elements.filterNot(isJar).mkString(sep)
}

def configuration = config.copy(
categories = slicings,
Expand Down
Expand Up @@ -7,9 +7,13 @@ import org.scalatest.FunSuite
import de.schauderhaft.degraph.configuration.UnnamedPattern
import de.schauderhaft.degraph.configuration.NamedPattern
import de.schauderhaft.degraph.configuration.Configuration
import java.util.Collections
import scala.util.Random
import org.scalatest.prop.Tables.Table
import org.scalatest.prop.TableDrivenPropertyChecks

@RunWith(classOf[JUnitRunner])
class ConstraintBuilderTest extends FunSuite {
class ConstraintBuilderTest extends FunSuite with TableDrivenPropertyChecks {

test("simple Pattern ends up In Configuration") {
val conf = ConstraintBuilder().withSlicing("x", "a.(*).**").configuration
Expand All @@ -35,8 +39,27 @@ class ConstraintBuilderTest extends FunSuite {
val cb = ConstraintBuilder(config = new Configuration(classpath = Some("x/")))
cb.noJars.configuration.classpath should be(Some("x/"))
}

test("noJars configuration contains only directory based entries, single path gets preserved when path ends in backslash") {
val cb = ConstraintBuilder(config = new Configuration(classpath = Some("""x\""")))
cb.noJars.configuration.classpath should be(Some("""x\"""))
}

test("noJars configuration contains only directory based entries, path entries from multiple entries get preserved") {

val pathSeperator = System.getProperty("path.separator")
val r = new Random(0)

val pathElements = Table("alpha", "beta/gamma", """x\y""")
val jarElements = Table("this.jar", "beta/SomeOther.jar")
val path = r.shuffle(pathElements ++ jarElements).mkString(pathSeperator)

val cb = ConstraintBuilder(config = new Configuration(classpath = Some(path)))
forAll(pathElements) { p =>
cb.noJars.configuration.classpath.get should include(p)
}
forAll(jarElements) { p =>
cb.noJars.configuration.classpath.get should not include (p)
}
}
}

0 comments on commit 5e70d0b

Please sign in to comment.