mirror of
https://github.com/sbt/sbt.git
synced 2026-09-07 11:01:08 +02:00
Extra logging, update default sbt.boot.properties
Tests for standard library substitutes
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
package xsbt.boot
|
||||
|
||||
import org.scalacheck._
|
||||
import Prop._
|
||||
|
||||
object CacheTest extends Properties("Cache")
|
||||
{
|
||||
implicit val functions: Arbitrary[Int => Int] = Arbitrary { Gen.elements(identity[Int], i => -i, i=>i/2, i => i+1) }
|
||||
|
||||
property("Cache") = Prop.forAll { (key: Int, keys: List[Int], map: Int => Int) =>
|
||||
val cache = new Cache(map)
|
||||
def toProperty(key: Int) = ("Key " + key) |: ("Value: " + map(key)) |: (cache.apply(key) == map(key))
|
||||
Prop.all( keys.map(toProperty) : _*)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package xsbt.boot
|
||||
|
||||
import org.scalacheck._
|
||||
import Prop.{Exception => _,_}
|
||||
|
||||
object EnumerationTest extends Properties("Enumeration")
|
||||
{
|
||||
property("MultiEnum.toValue") = checkToValue(MultiEnum, multiElements : _*)
|
||||
property("MultiEnum.elements") = checkElements(MultiEnum, multiElements : _*)
|
||||
property("EmptyEnum.toValue") = checkToValue(EmptyEnum)
|
||||
property("EmptyEnum.elements") = EmptyEnum.elements.isEmpty
|
||||
property("SingleEnum.toValue") = checkToValue( SingleEnum, singleElements )
|
||||
property("SingleEnum.elements") = checkElements( SingleEnum,singleElements )
|
||||
|
||||
def singleElements = ("A", SingleEnum.a)
|
||||
def multiElements =
|
||||
{
|
||||
import MultiEnum.{a,b,c}
|
||||
List(("A" -> a), ("B" -> b), ("C" -> c))
|
||||
}
|
||||
|
||||
def checkElements(enum: Enumeration, mapped: (String, Enumeration#Value)*) =
|
||||
{
|
||||
val elements = enum.elements
|
||||
("elements: " + elements) |:
|
||||
( mapped.forall{ case (s,v) => elements.contains(v) } && (elements.length == mapped.length) )
|
||||
}
|
||||
def checkToValue(enum: Enumeration, mapped: (String, Enumeration#Value)*) =
|
||||
{
|
||||
def invalid(s: String) =
|
||||
("valueOf(" + s + ")") |:
|
||||
Prop.throws(enum.toValue(s), classOf[Exception])
|
||||
def valid(s: String, expected: Enumeration#Value) =
|
||||
("valueOf(" + s + ")") |:
|
||||
("Expected " + expected) |:
|
||||
( enum.toValue(s) == expected )
|
||||
val map = Map( mapped : _*)
|
||||
Prop.forAll( (s: String) =>
|
||||
map.get(s) match {
|
||||
case Some(v) => valid(s, v)
|
||||
case None => invalid(s)
|
||||
} )
|
||||
}
|
||||
object MultiEnum extends Enumeration
|
||||
{
|
||||
val a = value("A")
|
||||
val b = value("B")
|
||||
val c = value("C")
|
||||
}
|
||||
object SingleEnum extends Enumeration
|
||||
{
|
||||
val a = value("A")
|
||||
}
|
||||
object EmptyEnum extends Enumeration
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package xsbt.boot
|
||||
|
||||
import org.scalacheck._
|
||||
|
||||
object ListMapProperties extends Properties("ListMap")
|
||||
{
|
||||
implicit val genListMap = Arbitrary ( for(list <- Arbitrary.arbitrary[List[(Int,Int)]]) yield ListMap(list : _*) )
|
||||
|
||||
property("ListMap from List contains all members of that List") = Prop.forAll { (list: List[(Int,Int)]) =>
|
||||
val map = ListMap(list : _*)
|
||||
list forall { entry => map contains entry._1 }
|
||||
}
|
||||
property("contains added entry") = Prop.forAll { (map: ListMap[Int,Int], key: Int, value: Int) =>
|
||||
{ (map + (key, value) ) contains(key) } &&
|
||||
{ (map + (key, value) )(key) == value } &&
|
||||
{ (map + (key, value) ).get(key) == Some(value) }
|
||||
}
|
||||
property("remove") = Prop.forAll { (map: ListMap[Int,Int], key: Int) =>
|
||||
{ Prop.throws((map - key)(key), classOf[Exception]) } &&
|
||||
{ !(map - key).contains(key) } &&
|
||||
{ (map - key).get(key).isEmpty }
|
||||
}
|
||||
property("empty") = Prop.forAll { (key: Int) =>
|
||||
{ Prop.throws(ListMap.empty(key), classOf[Exception]) }
|
||||
{ !ListMap.empty.contains(key) } &&
|
||||
{ ListMap.empty.get(key).isEmpty }
|
||||
}
|
||||
}
|
||||
|
||||
object ListMapEmpty extends Properties("ListMap.empty")
|
||||
{
|
||||
import ListMap.empty
|
||||
property("isEmpty") = empty.isEmpty
|
||||
property("toList.isEmpty") = empty.toList.isEmpty
|
||||
property("toSeq.isEmpty") = empty.toSeq.isEmpty
|
||||
property("toStream.isEmpty") = empty.toStream.isEmpty
|
||||
property("keys.isEmpty") = empty.keys.isEmpty
|
||||
property("elements.isEmpty") = !empty.elements.hasNext
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package xsbt.boot
|
||||
|
||||
import org.scalacheck._
|
||||
|
||||
object PreTest extends Properties("Pre")
|
||||
{
|
||||
import Pre._
|
||||
property("isEmpty") = Prop.forAll( (s: String) => (s.isEmpty == isEmpty(s)) )
|
||||
property("isNonEmpty") = Prop.forAll( (s: String) => (isEmpty(s) != isNonEmpty(s)) )
|
||||
property("assert true") = { assert(true); true }
|
||||
property("assert false") = Prop.throws(assert(false), classOf[AssertionError])
|
||||
property("assert true with message") = Prop.forAll { (s: String) => assert(true, s); true }
|
||||
property("assert false with message") = Prop.forAll( (s: String) => Prop.throws(assert(false, s), classOf[AssertionError] ) )
|
||||
property("require false") = Prop.forAll( (s: String) => Prop.throws(require(false, s), classOf[IllegalArgumentException]) )
|
||||
property("require true") = Prop.forAll { (s: String) => require(true, s); true }
|
||||
property("error") = Prop.forAll( (s: String) => Prop.throws(error(s), classOf[BootException]) )
|
||||
property("toBoolean") = Prop.forAll( (s: String) => trap(toBoolean(s)) == trap(java.lang.Boolean.parseBoolean(s)) )
|
||||
property("toArray") = Prop.forAll( (list: List[Int]) => list.toArray deepEquals toArray(list) )
|
||||
property("toArray") = Prop.forAll( (list: List[String]) => list.toArray deepEquals toArray(list) )
|
||||
|
||||
def trap[T](t: => T): Option[T] = try { Some(t) } catch { case e: Exception => None }
|
||||
}
|
||||
Reference in New Issue
Block a user