Extra logging, update default sbt.boot.properties

Tests for standard library substitutes
This commit is contained in:
Mark Harrah
2009-10-18 22:25:50 -04:00
parent 33434bc82b
commit fa73205ac3
13 changed files with 153 additions and 12 deletions
@@ -15,7 +15,7 @@
# Sbt Repository, http://simple-build-tool.googlecode.com/svn/artifacts/, [revision]/[type]s/[artifact].[ext]
maven-central
scala-tools-releases
# scala-tools-snapshots
scala-tools-snapshots
[boot]
directory: project/boot
@@ -29,9 +29,9 @@
[app-properties]
project.name: quick=set(test), new=prompt(Name), fill=prompt(Name)
project.organization: new=prompt(Organization)
project.version: quick=set(1.0), new=prompt(Version)[1.0], fill=prompt(Version)[1.0]
build.init.scala.version: quick=set(2.7.5), new=prompt(Scala version)[2.7.5]
scala.version: quick=set(2.7.5), new=set(2.7.5), fill=set(2.7.5)
scala.version: quick=set(2.7.5), new=prompt(Scala version)[2.7.5], fill=prompt(Scala version)[2.7.5]
sbt.version: quick=set(0.5.6-SNAPSHOT), new=prompt(sbt version)[0.5.6-SNAPSHOT], fill=prompt(sbt version)[0.5.6-SNAPSHOT]
project.scratch: quick=set(true)
project.initialize: quick=set(true), new=set(true)
+15
View File
@@ -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
}
+39
View File
@@ -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
}
+22
View File
@@ -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 }
}