assert() now works with -ea
This commit is contained in:
@@ -1,16 +1,15 @@
|
|||||||
package kotlin
|
package kotlin
|
||||||
|
|
||||||
object Assertions {
|
|
||||||
// TODO make private once KT-1528 is fixed.
|
private object _Assertions
|
||||||
val _ENABLED = (javaClass<java.lang.System>()).desiredAssertionStatus()
|
private val ASSERTIONS_ENABLED = _Assertions.javaClass.desiredAssertionStatus()
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws an [[AssertionError]] with an optional *message* if the *value* is false
|
* Throws an [[AssertionError]] with an optional *message* if the *value* is false
|
||||||
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
|
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
|
||||||
*/
|
*/
|
||||||
public inline fun assert(value: Boolean, message: Any = "Assertion failed") {
|
public inline fun assert(value: Boolean, message: Any = "Assertion failed") {
|
||||||
if (Assertions._ENABLED) {
|
if (ASSERTIONS_ENABLED) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
throw AssertionError(message)
|
throw AssertionError(message)
|
||||||
}
|
}
|
||||||
@@ -22,7 +21,7 @@ public inline fun assert(value: Boolean, message: Any = "Assertion failed") {
|
|||||||
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
|
* and runtime assertions have been enabled on the JVM using the *-ea* JVM option.
|
||||||
*/
|
*/
|
||||||
public inline fun assert(value: Boolean, lazyMessage: () -> String) {
|
public inline fun assert(value: Boolean, lazyMessage: () -> String) {
|
||||||
if (Assertions._ENABLED) {
|
if (ASSERTIONS_ENABLED) {
|
||||||
if (!value) {
|
if (!value) {
|
||||||
val message = lazyMessage()
|
val message = lazyMessage()
|
||||||
throw AssertionError(message)
|
throw AssertionError(message)
|
||||||
|
|||||||
Reference in New Issue
Block a user