Skip to content

Instantly share code, notes, and snippets.

@anttih
Created November 4, 2010 18:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anttih/662925 to your computer and use it in GitHub Desktop.
Save anttih/662925 to your computer and use it in GitHub Desktop.
Tests for Object assert
Protos AssertionException := Exception clone
Object do(
assert := method(v, m,
if(true != v,
m ifNil(m = "true != (#{ call argAt(0) })" interpolate)
AssertionException raise(m)
)
)
)
doFile("Assert.io")
doFile("UnitTest.io") // my patched UnitTest.io
AssertTest := UnitTest clone do(
/*
Object does not respond to debug* messages on my installation
test_does_not_throw_when_debugging_off := method(
debugOff
assert(false)
debugOn
)
*/
test_no_params_throws := method(
e := try(assert())
e catch(AssertionException,
assertEquals(e error, "true != (nil)")
) pass
)
test_does_not_throw_when_true := method(
assert(true)
)
test_throws_assertionException_when_false := method(
e := try(assert(false))
e catch(AssertionException) pass
)
test_message_is_call_message_when_no_message := method(
e := try(assert(false == true))
e catch(AssertionException,
assertEquals(e error, "true != (false ==(true))")
) pass
)
test_uses_passed_in_message := method(
e := try(assert(false, "Message"))
e catch(AssertionException,
assertEquals(e error, "Message")
) pass
)
test_more_complicated_call_message := method(
e := try(assert((50 + 50) / 100 != 1))
e catch(AssertionException,
assertEquals(e error, "true != ((50 +(50)) /(100) !=(1))")
) pass
)
//test_this_should_fail := method(
// #fail("Failure!")
//)
)
FileCollector run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment