Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Properties.overrideParameters to work correctly. #463

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions src/main/scala/org/scalacheck/ScalaCheckFramework.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ private abstract class ScalaCheckRunner extends Runner {

def deserializeTask(task: String, deserializer: String => TaskDef): BaseTask = {
val taskDef = deserializer(task)
val countTestSelectors = taskDef.selectors.toSeq.count {
case _:TestSelector => true
case _ => false
}
if (countTestSelectors == 0) rootTask(taskDef)
if (taskDef.selectors.isEmpty) rootTask(taskDef)
else checkPropTask(taskDef, single = true)
}

Expand All @@ -42,34 +38,37 @@ private abstract class ScalaCheckRunner extends Runner {

def tasks(taskDefs: Array[TaskDef]): Array[Task] = {
val isForked = taskDefs.exists(_.fingerprint().getClass.getName.contains("ForkMain"))
taskDefs.map { taskDef =>
if (isForked) checkPropTask(taskDef, single = false)
else rootTask(taskDef)
}
taskDefs.map(t => if (isForked) checkPropTask(t, single = false) else rootTask(t))
}

abstract class BaseTask(override val taskDef: TaskDef) extends Task {
val tags: Array[String] = Array()

val props: collection.Seq[(String,Prop)] = {
val loaded: Either[Prop, Properties] = {
val fp = taskDef.fingerprint.asInstanceOf[SubclassFingerprint]
val obj = if (fp.isModule) Platform.loadModule(taskDef.fullyQualifiedName,loader)
else Platform.newInstance(taskDef.fullyQualifiedName, loader, Seq())(Seq())
obj match {
case props: Properties => props.properties
case prop: Prop => Seq("" -> prop)
case props: Properties => Right(props)
case prop: Prop => Left(prop)
}
}

// TODO copypasted from props val
val properties: Option[Properties] = {
val fp = taskDef.fingerprint.asInstanceOf[SubclassFingerprint]
val obj = if (fp.isModule) Platform.loadModule(taskDef.fullyQualifiedName,loader)
else Platform.newInstance(taskDef.fullyQualifiedName, loader, Seq())(Seq())
obj match {
case props: Properties => Some(props)
case prop: Prop => None
}
val props: collection.Seq[(String,Prop)] = loaded match {
case Right(ps) => ps.properties
case Left(prop) => Seq("" -> prop)
}

val properties: Option[Properties] =
loaded.right.toOption

val params: Parameters = {
// apply global parameters first, then allow properties to
// override them. the other order does not work because
// applyCmdParams will unconditionally set parameters to default
// values, even when they were overridden.
val ps = applyCmdParams(Parameters.default)
properties.fold(ps)(_.overrideParameters(ps))
}

def log(loggers: Array[Logger], ok: Boolean, msg: String) =
Expand All @@ -94,23 +93,25 @@ private abstract class ScalaCheckRunner extends Runner {
}
}

def checkPropTask(taskDef: TaskDef, single: Boolean) = new BaseTask(taskDef) {
def checkPropTask(taskDef: TaskDef, single: Boolean): BaseTask = new BaseTask(taskDef) {
def execute(handler: EventHandler, loggers: Array[Logger]): Array[Task] = {
val params = applyCmdParams(properties.foldLeft(Parameters.default)((params, props) => props.overrideParameters(params)))
val propertyFilter = params.propFilter.map(_.r)

if (single) {
val names = taskDef.selectors flatMap {
case ts: TestSelector => Array(ts.testName)
case _ => Array.empty[String]
}
names foreach { name =>
for ((`name`, prop) <- props)
executeInternal(prop, name, handler, loggers, propertyFilter)
val mprops: Map[String, Prop] = props.toMap
taskDef.selectors.foreach {
case ts: TestSelector =>
val name = ts.testName
mprops.get(name).foreach { prop =>
executeInternal(prop, name, handler, loggers, propertyFilter)
}
case _ =>
()
}
} else {
for ((name, prop) <- props)
props.foreach { case (name, prop) =>
executeInternal(prop, name, handler, loggers, propertyFilter)
}
}
Array.empty[Task]
}
Expand All @@ -119,7 +120,6 @@ private abstract class ScalaCheckRunner extends Runner {
if (propertyFilter.isEmpty || propertyFilter.exists(matchPropFilter(name, _))) {

import util.Pretty.{pretty, Params}
val params = applyCmdParams(properties.foldLeft(Parameters.default)((params, props) => props.overrideParameters(params)))
val result = Test.check(params, prop)

val event = new Event {
Expand Down Expand Up @@ -236,7 +236,6 @@ final class ScalaCheckFramework extends Framework {
send(s"d$testCount,$successCount,$failureCount,$errorCount")
""
}

}

}