[Test] Extract MockLibraryUtil to :compiler:tests-compiler-utils

Also provide MockLibraryUtilExt with bridges to MockLibraryUtil
  with JUnit4Assertions
This commit is contained in:
Dmitriy Novozhilov
2020-12-22 13:56:06 +03:00
committed by TeamCityServer
parent eadec08937
commit cb7b1652e7
26 changed files with 271 additions and 172 deletions
@@ -3,40 +3,9 @@
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
@file:JvmName("KtAssert")
package org.jetbrains.kotlin.test
import java.io.File
import java.util.*
import kotlin.collections.ArrayList
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
/*
* Those functions are needed only in this module because it has no testing framework
* with assertions in it's dependencies
*/
internal fun fail(message: String) {
throw AssertionError(message)
}
@OptIn(ExperimentalContracts::class)
internal fun assertNotNull(message: String, value: Any?) {
contract {
returns() implies (value != null)
}
if (value == null) {
fail(message)
}
}
internal fun assertTrue(message: String, value: Boolean) {
if (!value) {
fail(message)
}
}
abstract class Assertions {
fun assertEqualsToFile(expectedFile: File, actual: String, sanitizer: (String) -> String = { it }) {
@@ -0,0 +1,45 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.test
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract
/*
* Those functions are needed only in modules which are not depend on any testing framework
*/
object KtAssert {
@JvmStatic
fun fail(message: String) {
throw AssertionError(message)
}
@JvmStatic
@OptIn(ExperimentalContracts::class)
fun assertNotNull(message: String, value: Any?) {
contract {
returns() implies (value != null)
}
if (value == null) {
fail(message)
}
}
@JvmStatic
fun assertTrue(message: String, value: Boolean) {
if (!value) {
fail(message)
}
}
@JvmStatic
fun <T> assertEquals(message: String, expected: T, actual: T) {
if (expected != actual) {
fail(message)
}
}
}