compile the assertions and a test case to QUnit on JS and got a working example to run the unit test case - yay!
This commit is contained in:
@@ -3,32 +3,8 @@
|
||||
*/
|
||||
package kotlin.test
|
||||
|
||||
import java.util.ServiceLoader
|
||||
|
||||
private var _asserter: Asserter? = null
|
||||
|
||||
public var asserter: Asserter
|
||||
get() {
|
||||
if (_asserter == null) {
|
||||
val klass = javaClass<Asserter>()
|
||||
val loader = ServiceLoader.load(klass)
|
||||
for (a in loader) {
|
||||
if (a != null) {
|
||||
_asserter = a
|
||||
break
|
||||
}
|
||||
}
|
||||
if (_asserter == null) {
|
||||
_asserter = DefaultAsserter()
|
||||
}
|
||||
//debug("using asserter $_asserter")
|
||||
}
|
||||
return _asserter.sure()
|
||||
}
|
||||
|
||||
set(value) {
|
||||
_asserter = value
|
||||
}
|
||||
// TODO should not need this - its here for the JS stuff
|
||||
import java.lang.IllegalStateException
|
||||
|
||||
/** Asserts that the given block returns true */
|
||||
public inline fun assertTrue(message: String, block: ()-> Boolean) {
|
||||
@@ -122,14 +98,6 @@ public fun <T: Throwable> failsWith(block: ()-> Any): T {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Comments out a block of test code until it is implemented while keeping a link to the code
|
||||
* to implement in your unit test output
|
||||
*/
|
||||
public inline fun todo(block: ()-> Any) {
|
||||
println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
|
||||
}
|
||||
|
||||
/**
|
||||
* A plugin for performing assertions which can reuse JUnit or TestNG
|
||||
*/
|
||||
@@ -144,37 +112,3 @@ trait Asserter {
|
||||
|
||||
public fun fail(message: String): Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* Default implementation to avoid dependency on JUnit or TestNG
|
||||
*/
|
||||
class DefaultAsserter() : Asserter {
|
||||
|
||||
public override fun assertTrue(message : String, actual : Boolean) {
|
||||
if (!actual) {
|
||||
fail(message)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun assertEquals(message : String, expected : Any?, actual : Any?) {
|
||||
if (expected != actual) {
|
||||
fail("$message. Expected <$expected> actual <$actual>")
|
||||
}
|
||||
}
|
||||
|
||||
public override fun assertNotNull(message : String, actual : Any?) {
|
||||
if (actual == null) {
|
||||
fail(message)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun assertNull(message : String, actual : Any?) {
|
||||
if (actual != null) {
|
||||
fail(message)
|
||||
}
|
||||
}
|
||||
public override fun fail(message : String) {
|
||||
// TODO work around compiler bug as it should never try call the private constructor
|
||||
throw AssertionError(message as Object)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package kotlin.test
|
||||
|
||||
import java.util.ServiceLoader
|
||||
|
||||
/**
|
||||
* Comments out a block of test code until it is implemented while keeping a link to the code
|
||||
* to implement in your unit test output
|
||||
*/
|
||||
public inline fun todo(block: ()-> Any) {
|
||||
println("TODO at " + (Exception() as java.lang.Throwable).getStackTrace()?.get(1) + " for " + block)
|
||||
}
|
||||
|
||||
private var _asserter: Asserter? = null
|
||||
|
||||
public var asserter: Asserter
|
||||
get() {
|
||||
if (_asserter == null) {
|
||||
val klass = javaClass<Asserter>()
|
||||
val loader = ServiceLoader.load(klass)
|
||||
for (a in loader) {
|
||||
if (a != null) {
|
||||
_asserter = a
|
||||
break
|
||||
}
|
||||
}
|
||||
if (_asserter == null) {
|
||||
_asserter = DefaultAsserter()
|
||||
}
|
||||
//debug("using asserter $_asserter")
|
||||
}
|
||||
return _asserter.sure()
|
||||
}
|
||||
|
||||
set(value) {
|
||||
_asserter = value
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation to avoid dependency on JUnit or TestNG
|
||||
*/
|
||||
class DefaultAsserter() : Asserter {
|
||||
|
||||
public override fun assertTrue(message : String, actual : Boolean) {
|
||||
if (!actual) {
|
||||
fail(message)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun assertEquals(message : String, expected : Any?, actual : Any?) {
|
||||
if (expected != actual) {
|
||||
fail("$message. Expected <$expected> actual <$actual>")
|
||||
}
|
||||
}
|
||||
|
||||
public override fun assertNotNull(message : String, actual : Any?) {
|
||||
if (actual == null) {
|
||||
fail(message)
|
||||
}
|
||||
}
|
||||
|
||||
public override fun assertNull(message : String, actual : Any?) {
|
||||
if (actual != null) {
|
||||
fail(message)
|
||||
}
|
||||
}
|
||||
public override fun fail(message : String) {
|
||||
// TODO work around compiler bug as it should never try call the private constructor
|
||||
throw AssertionError(message as Any)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user