-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathAtomicTest.scala
More file actions
42 lines (40 loc) · 1.07 KB
/
AtomicTest.scala
File metadata and controls
42 lines (40 loc) · 1.07 KB
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
// AtomicTest.scala
/* A tiny little testing framework, to
display results and to introduce & promote
unit testing early in the learning curve.
For use in a script or App, include:
import com.atomicscala.AtomicTest._
*/
package com.atomicscala
import language.implicitConversions
import java.io.FileWriter
class AtomicTest[T](val target:T) {
val errorLog = "_AtomicTestErrors.txt"
def tst[E](expected:E)(test: => Boolean){
println(target)
if(test == false) {
val msg = "[Error] expected:\n" +
expected
println(msg)
val el= new FileWriter(errorLog,true)
el.write(target + msg + "\n")
el.close()
}
}
def str = // Safely convert to a String
Option(target).getOrElse("").toString
def is(expected:String) = tst(expected) {
expected.replaceAll("\r\n","\n") == str
}
def is[E](expected:E) = tst(expected) {
expected == target
}
def beginsWith(exp:String) = tst(exp) {
str.startsWith(
exp.replaceAll("\r\n","\n"))
}
}
object AtomicTest {
implicit def any2Atomic[T](target:T) =
new AtomicTest(target)
}