|
| 1 | +/* |
| 2 | + * ScalaCheck |
| 3 | + * Copyright (c) 2007-2021 Rickard Nilsson. All rights reserved. |
| 4 | + * http://www.scalacheck.org |
| 5 | + * |
| 6 | + * This software is released under the terms of the Revised BSD License. |
| 7 | + * There is NO WARRANTY. See the file LICENSE for the full text. |
| 8 | + */ |
| 9 | + |
| 10 | +package org.scalacheck |
| 11 | + |
| 12 | +import org.scalacheck.Prop.proved |
| 13 | +import sbt.testing.{Selector, SuiteSelector, TaskDef, TestSelector} |
| 14 | + |
| 15 | +object ScalaCheckFrameworkSpecification extends Properties("ScalaCheckFramework") { |
| 16 | + |
| 17 | + private val firstProp = "ScalaCheckFrameworkHelper.first prop" |
| 18 | + private val secondProp = "ScalaCheckFrameworkHelper.second prop" |
| 19 | + private val thirdProp = "ScalaCheckFrameworkHelper.third prop" |
| 20 | + |
| 21 | + |
| 22 | + property("all props with SuiteSelector") = { |
| 23 | + getPropNamesForSelectors(List(new SuiteSelector)) == List(firstProp, secondProp, thirdProp) |
| 24 | + getPropNamesForSelectors(List(new SuiteSelector, new TestSelector(firstProp))) == List(firstProp, secondProp, thirdProp) |
| 25 | + getPropNamesForSelectors(List(new SuiteSelector, new TestSelector("no matches"))) == List(firstProp, secondProp, thirdProp) |
| 26 | + } |
| 27 | + |
| 28 | + property("only matching props with TestSelector") = { |
| 29 | + getPropNamesForSelectors(List(new TestSelector(firstProp))) == List(firstProp) |
| 30 | + getPropNamesForSelectors(List(new TestSelector(secondProp))) == List(secondProp) |
| 31 | + getPropNamesForSelectors(List(new TestSelector(firstProp), new TestSelector(thirdProp))) == List(firstProp, thirdProp) |
| 32 | + getPropNamesForSelectors(List(new TestSelector("no matches"))) == Nil |
| 33 | + } |
| 34 | + |
| 35 | + private def getPropNamesForSelectors(selectors: List[Selector]): List[String] = { |
| 36 | + val framework = new ScalaCheckFramework() |
| 37 | + val runner = framework.runner(Array.empty, Array.empty, getClass.getClassLoader).asInstanceOf[ScalaCheckRunner] |
| 38 | + val taskDef = new TaskDef(classOf[ScalaCheckFrameworkSpecificationHelper].getName, framework.fingerprints()(0), true, selectors.toArray) |
| 39 | + val baseTask = runner.rootTask(taskDef) |
| 40 | + val newTasks = baseTask.execute(null, null) |
| 41 | + val propNames = for { |
| 42 | + task <- newTasks |
| 43 | + selector <- task.taskDef().selectors() |
| 44 | + } yield selector.asInstanceOf[TestSelector].testName() |
| 45 | + propNames.toList |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +class ScalaCheckFrameworkSpecificationHelper extends Properties("ScalaCheckFrameworkHelper") { |
| 50 | + property("first prop") = proved |
| 51 | + property("second prop") = proved |
| 52 | + property("third prop") = proved |
| 53 | +} |
0 commit comments