|
| 1 | +package org.scalacheck |
| 2 | + |
| 3 | +import sbt.testing.{Event, EventHandler, Framework, Selector, SuiteSelector, Task, TaskDef, TestSelector, TestWildcardSelector} |
| 4 | + |
| 5 | +object SbtFixture extends Properties("SbtFixture") { |
| 6 | + property("success") = Prop.passed |
| 7 | +} |
| 8 | + |
| 9 | +object SbtNestingFixture extends Properties("SbtNestingFixture") { |
| 10 | + include(SbtFixture) |
| 11 | +} |
| 12 | + |
| 13 | +object SbtSpecification extends Properties("Sbt") { |
| 14 | + property("suite") = run(Array(new SuiteSelector)) == List("SbtFixture.success") |
| 15 | + |
| 16 | + property("exact" ) = run(Array(new TestSelector("success" ))) == List("SbtFixture.success") |
| 17 | + property("exactFull" ) = run(Array(new TestSelector("SbtFixture.success"))) == List("SbtFixture.success") |
| 18 | + property("exactMissing") = run(Array(new TestSelector("nonexistent"))) == List.empty |
| 19 | + |
| 20 | + property("wildcard" ) = run(Array(new TestWildcardSelector("succ" ))) == List("SbtFixture.success") |
| 21 | + property("wildcardFull") = run(Array(new TestWildcardSelector("xture.succ"))) == List("SbtFixture.success") |
| 22 | + property("wildcardMissing") = run(Array(new TestWildcardSelector("prev"))) == List.empty |
| 23 | + |
| 24 | + // Since ScalaCheck does not keep track what class/object a property belongs to, |
| 25 | + // the following two issues concerning nested properties can not be fixed: |
| 26 | + // |
| 27 | + // When `explicitlySpecified = true`, properties from objects other than the one being run |
| 28 | + // should *not* run (and the outcome should be `List.empty`) - but they do. |
| 29 | + // |
| 30 | + // When a property from an object other than the one being run *does* run, |
| 31 | + // its status should be reported with a `NestedTestSelector` |
| 32 | + // where `suiteId` names the object that the property belongs to - |
| 33 | + // but it is reported with a `TestSelector`. |
| 34 | + |
| 35 | + property("nestedShouldRun") = run( |
| 36 | + Array(new SuiteSelector), |
| 37 | + fullyQualifiedName = "org.scalacheck.SbtNestingFixture", |
| 38 | + explicitlySpecified = false |
| 39 | + ) == List("SbtNestingFixture.SbtFixture.success") |
| 40 | + |
| 41 | + property("nestedShouldNotRun") = run( |
| 42 | + Array(new SuiteSelector), |
| 43 | + fullyQualifiedName = "org.scalacheck.SbtNestingFixture", |
| 44 | + explicitlySpecified = true |
| 45 | + ) == List("SbtNestingFixture.SbtFixture.success") |
| 46 | + |
| 47 | + // run using SBT Test Interface |
| 48 | + def run( |
| 49 | + selectors: Array[Selector], |
| 50 | + fullyQualifiedName: String = "org.scalacheck.SbtFixture", |
| 51 | + explicitlySpecified: Boolean = false |
| 52 | + ): List[String] = { |
| 53 | + val framework: Framework = new ScalaCheckFramework |
| 54 | + var ran: List[String] = List.empty |
| 55 | + val eventHandler: EventHandler = (event: Event) => ran = ran.appended(event.selector().asInstanceOf[TestSelector].testName()) |
| 56 | + def execute(tasks: Array[Task]): Unit = tasks.foreach(task => execute(task.execute(eventHandler, Array.empty))) |
| 57 | + execute(framework.runner(Array.empty, Array.empty, Platform.getClassLoader).tasks(Array(new TaskDef( |
| 58 | + fullyQualifiedName, |
| 59 | + framework.fingerprints()(2), // object ... extends org.scalacheck.Properties |
| 60 | + explicitlySpecified, |
| 61 | + selectors |
| 62 | + )))) |
| 63 | + ran |
| 64 | + } |
| 65 | +} |
0 commit comments