-
Notifications
You must be signed in to change notification settings - Fork 14
/
Discipline.scala
71 lines (63 loc) · 2.96 KB
/
Discipline.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package org.typelevel.discipline
package scalatest
import org.scalactic.Prettifier
import org.scalactic.source.Position
import org.scalatest.flatspec.AnyFlatSpecLike
import org.scalatest.funspec.AnyFunSpecLike
import org.scalatest.funsuite.AnyFunSuiteLike
import org.scalatest.prop.Configuration
import org.scalatestplus.scalacheck.Checkers
trait Discipline { self: Configuration =>
/**
* Convert from our configuration type to the one required by `Checkers`.
*
* We don't extend `Checkers` because we want to leave the user as much
* control as possible over available testing styles. Unfortunately we need
* this conversion because ScalaTest defines `PropertyCheckConfiguration`
* as a case class in the `Configuration` trait.
*/
final protected[this] def convertConfiguration(
config: PropertyCheckConfiguration
): Checkers.PropertyCheckConfiguration =
Checkers.PropertyCheckConfiguration(
config.minSuccessful,
config.maxDiscardedFactor,
config.minSize,
config.sizeRange,
config.workers
)
def checkAll(name: String, ruleSet: Laws#RuleSet)(implicit config: PropertyCheckConfiguration,
prettifier: Prettifier,
pos: Position): Unit
}
trait FlatSpecDiscipline extends Discipline { self: AnyFlatSpecLike with Configuration =>
final def checkAll(name: String, ruleSet: Laws#RuleSet)(implicit config: PropertyCheckConfiguration,
prettifier: Prettifier,
pos: Position): Unit =
ruleSet.all.properties match {
case first +: rest =>
name should first._1 in Checkers.check(first._2)(convertConfiguration(config), prettifier, pos)
for ((id, prop) <- rest)
it should id in Checkers.check(prop)(convertConfiguration(config), prettifier, pos)
}
}
trait FunSpecDiscipline extends Discipline { self: AnyFunSpecLike with Configuration =>
final def checkAll(name: String, ruleSet: Laws#RuleSet)(implicit config: PropertyCheckConfiguration,
prettifier: Prettifier,
pos: Position): Unit =
describe(name) {
for ((id, prop) <- ruleSet.all.properties)
it(id) {
Checkers.check(prop)(convertConfiguration(config), prettifier, pos)
}
}
}
trait FunSuiteDiscipline extends Discipline { self: AnyFunSuiteLike with Configuration =>
final def checkAll(name: String, ruleSet: Laws#RuleSet)(implicit config: PropertyCheckConfiguration,
prettifier: Prettifier,
pos: Position): Unit =
for ((id, prop) <- ruleSet.all.properties)
test(s"${name}.${id}") {
Checkers.check(prop)(convertConfiguration(config), prettifier, pos)
}
}