Permalink
Browse files

the classpath for tests can now be limited to those classes not commi…

…ng from jars.
  • Loading branch information...
1 parent 2b59a5a commit 5e70d0bcb7c2250c99038f5499c1050a9e3f1128 @schauder committed Jan 15, 2014
View
10 src/main/scala/de/schauderhaft/degraph/check/ConstraintBuilder.scala
@@ -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,
View
25 src/test/scala/de/schauderhaft/degraph/check/ConstraintBuilderTest.scala
@@ -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
@@ -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.