[Build] Add jUnit dependencies in testApiJUnit5 to the implementation configuration
Adding these dependencies to the `api` configuration pollutes classpath for each dependant modules even if it doesn't need them. Instead, the dependencies should be declared more granularly if they're required #KTI-1349 In Progress
This commit is contained in:
committed by
Space Team
parent
0ecbb64c64
commit
53fde520d5
@@ -25,7 +25,7 @@ dependencies {
|
||||
testApi(projectTests(":compiler:tests-common"))
|
||||
testApiJUnit5()
|
||||
testImplementation(libs.junit.jupyter.params)
|
||||
testApi(libs.junit4)
|
||||
testImplementation(libs.junit4)
|
||||
testApi(protobufFull())
|
||||
testApi(kotlinStdlib())
|
||||
testImplementation(project(":compiler:build-tools:kotlin-build-statistics"))
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2010-2023 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.util
|
||||
|
||||
/**
|
||||
* A replacement for the JUnit Jupiter function to be used in JUnit 4 tests.
|
||||
*
|
||||
* Asserts that the given code block throws an exception of the specified type.
|
||||
*
|
||||
* @param E the type of exception that is expected to be thrown
|
||||
* @param message the error message to be used if the exception is not thrown
|
||||
* @param body the code block to be executed and verified
|
||||
* @return the caught exception if it is of the specified type
|
||||
* @throws AssertionError if the specified exception is not thrown
|
||||
*/
|
||||
inline fun <reified E : Exception> assertThrows(
|
||||
message: String = "Expected ${E::class.java.name} to be thrown",
|
||||
body: () -> Unit,
|
||||
): Throwable {
|
||||
try {
|
||||
body()
|
||||
} catch (e: Throwable) {
|
||||
if (e is E) {
|
||||
return e
|
||||
}
|
||||
}
|
||||
throw AssertionError(message)
|
||||
}
|
||||
|
||||
/**
|
||||
* A replacement for the JUnit Jupiter function to be used in JUnit 4 tests.
|
||||
*
|
||||
* Asserts that the specified code block does not throw any exception.
|
||||
*
|
||||
* @param message The message to be included in the AssertionError if an exception is thrown.
|
||||
* It can contain the "{}" placeholder, which will be replaced with the thrown exception.
|
||||
* @param body The code block to be executed.
|
||||
*
|
||||
* @return The result of executing the code block.
|
||||
*
|
||||
* @throws AssertionError If the code block throws an exception.
|
||||
*/
|
||||
fun <R> assertDoesNotThrow(
|
||||
message: String = "Expected no exception, but {} was thrown",
|
||||
body: () -> R,
|
||||
): R {
|
||||
try {
|
||||
return body()
|
||||
} catch (e: Throwable) {
|
||||
throw AssertionError(message.format(e))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user