poohbar
06/25/2019, 1:49 PMrun
run {
// some code
}
{ /*my unrelated block here*/ } shouldNotThrow AnyExceptionJacques Smuts
06/25/2019, 1:51 PMpoohbar
06/25/2019, 1:52 PMval x = { my code } is validstreetsofboston
06/25/2019, 1:52 PM{ and ends with a } is an expression that results in a lambda. This lambda is not run and just sits there. It is lonely 🙂poohbar
06/25/2019, 1:52 PM{ my code } is valid toomarstran
06/25/2019, 1:52 PM{ } is not a block. It's a lambda.marstran
06/25/2019, 1:52 PMrun { ... }Shawn
06/25/2019, 1:52 PMShawn
06/25/2019, 1:52 PMpoohbar
06/25/2019, 1:53 PMif (true) {
// nothing
}
{ myMock.method(arg) } shouldNotThrow AnyExceptionpoohbar
06/25/2019, 1:53 PMShawn
06/25/2019, 1:54 PMmyMock.method() even run
2. the compiler knows not to treat a bare lambda as an argument to an `if`…streetsofboston
06/25/2019, 1:54 PMShawn
06/25/2019, 1:54 PMpoohbar
06/25/2019, 1:54 PMpoohbar
06/25/2019, 1:55 PMshouldNotThrow has this.invoke() in itstreetsofboston
06/25/2019, 1:55 PMpoohbar
06/25/2019, 1:55 PMstreetsofboston
06/25/2019, 1:55 PMpoohbar
06/25/2019, 1:56 PMpoohbar
06/25/2019, 1:56 PMstreetsofboston
06/25/2019, 1:57 PMshouldNotThrow?poohbar
06/25/2019, 1:57 PMinfix fun <T : Throwable> (() -> Any?).shouldNotThrow(expectedException: KClass<T>)poohbar
06/25/2019, 1:57 PMstreetsofboston
06/25/2019, 2:02 PMshouldNotThrow on the same line as the closing bracket of the `run`’s lambda generates a compiler error, but you put it on a new line. This should not give a compiler issue, I think.poohbar
06/25/2019, 2:04 PMstreetsofboston
06/25/2019, 2:05 PMpoohbar
06/25/2019, 2:05 PMrun {
// some code
}
val call = { myMock.method(arg) }
call shouldNotThrow AnyExceptionDias
06/25/2019, 2:06 PMDias
06/25/2019, 2:06 PMpoohbar
06/25/2019, 2:07 PMpoohbar
06/25/2019, 2:07 PMDias
06/25/2019, 2:08 PMpoohbar
06/25/2019, 2:09 PMLeoColman
06/25/2019, 4:23 PMLeoColman
06/25/2019, 4:23 PMshouldThrow { call() }LeoColman
06/25/2019, 4:23 PMshouldNotThrow { }