Skip to content

Commit

Permalink
Allow overriding of Test.Parameters in Properties
Browse files Browse the repository at this point in the history
  • Loading branch information
sid-kap committed Aug 5, 2015
1 parent 24aa825 commit f2a8031
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
15 changes: 12 additions & 3 deletions src/main/scala/org/scalacheck/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ class Properties(val name: String) {

private val props = new scala.collection.mutable.ListBuffer[(String,Prop)]

/**
* Changes to the test parameters that are specific to this class.
* Can be used to set custom parameter values for this test.
*/
def overrideParameters(p: Test.Parameters): Test.Parameters = p

/** Returns all properties of this collection in a list of name/property
* pairs. */
def properties: Seq[(String,Prop)] = props
Expand All @@ -44,9 +50,12 @@ class Properties(val name: String) {
* If you need to get the results
* from the test use the `check` methods in [[org.scalacheck.Test]]
* instead. */
def check(prms: Test.Parameters = Test.Parameters.default): Unit = Test.checkProperties(
prms.withTestCallback(ConsoleReporter(1) chain prms.testCallback), this
)
def check(prms: Test.Parameters = Test.Parameters.default): Unit = {
val params = overrideParameters(prms)
Test.checkProperties(
params.withTestCallback(ConsoleReporter(1) chain params.testCallback), this
)
}

/** Convenience method that makes it possible to use this property collection
* as an application that checks itself on execution. Calls `System.exit`
Expand Down
10 changes: 6 additions & 4 deletions src/main/scala/org/scalacheck/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,17 @@ object Test {
}

/** Check a set of properties. */
def checkProperties(prms: Parameters, ps: Properties): Seq[(String,Result)] =
def checkProperties(prms: Parameters, ps: Properties): Seq[(String,Result)] = {
val params = ps.overrideParameters(prms)
ps.properties.map { case (name,p) =>
val testCallback = new TestCallback {
override def onPropEval(n: String, t: Int, s: Int, d: Int) =
prms.testCallback.onPropEval(name,t,s,d)
params.testCallback.onPropEval(name,t,s,d)
override def onTestResult(n: String, r: Result) =
prms.testCallback.onTestResult(name,r)
params.testCallback.onTestResult(name,r)
}
val res = check(prms.withTestCallback(testCallback), p)
val res = check(params.withTestCallback(testCallback), p)
(name,res)
}
}
}

0 comments on commit f2a8031

Please sign in to comment.