[Native][tests] Minor. Prefer to use raw string literals for better readability

This commit is contained in:
Dmitriy Dolovov
2021-11-13 13:05:22 +03:00
parent e5bb16c750
commit e30f33b18d
5 changed files with 38 additions and 11 deletions
@@ -175,9 +175,13 @@ internal sealed interface TestCompilationResult {
is DependencyFailures -> fail { describeDependencyFailures() }
}
private fun Failure.describeFailure() = when (this) {
is CompilerFailure -> "Compilation failed.\n\n$loggedData"
is UnexpectedFailure -> "Compilation failed with unexpected exception.\n\n$loggedData"
private fun Failure.describeFailure() = buildString {
when (this@describeFailure) {
is CompilerFailure -> appendLine("Compilation failed.")
is UnexpectedFailure -> appendLine("Compilation failed with unexpected exception.")
}
appendLine()
appendLine(loggedData)
}
private fun DependencyFailures.describeDependencyFailures() =
@@ -109,8 +109,11 @@ private class TestOutput(
private inline fun <T> verifyExpectation(expected: T, actual: T, crossinline errorMessageHeader: () -> String) {
assertEquals(expected, actual) {
val loggedTestRun = LoggedData.TestRun(loggedParameters, exitCode, stdOut, stdErr, finishTimeMillis - startTimeMillis)
"${errorMessageHeader()}\n\n$loggedTestRun"
"""
${errorMessageHeader()}
${LoggedData.TestRun(loggedParameters, exitCode, stdOut, stdErr, finishTimeMillis - startTimeMillis)}
""".trimIndent()
}
}
@@ -67,7 +67,11 @@ internal class StandardTestCaseGroupProvider(private val environment: TestEnviro
// Don't register new test module if there is another one with the same name.
val testModule = testModules.getOrPut(newTestModule.name) { newTestModule }
assertTrue(testModule === newTestModule || testModule.haveSameSymbols(newTestModule)) {
"$location: Two declarations of the same module with different dependencies or friends found:\n$testModule\n$newTestModule"
"""
$location: Two declarations of the same module with different dependencies or friends found:
$testModule
$newTestModule
""".trimIndent()
}
currentTestModule = testModule
@@ -111,7 +115,13 @@ internal class StandardTestCaseGroupProvider(private val environment: TestEnviro
directivesParser.convertToRegisteredDirective(rawDirective)
} catch (e: AssertionError) {
// Enhance error message with concrete test data file and line number where the error has happened.
throw AssertionError("$location: Error while parsing directive in test data file.\nCause: ${e.message}", e)
throw AssertionError(
"""
$location: Error while parsing directive in test data file.
Cause: ${e.message}
""".trimIndent(),
e
)
}
if (parsedDirective != null) {
@@ -228,8 +238,10 @@ internal class StandardTestCaseGroupProvider(private val environment: TestEnviro
&& existingPackageName[packageName.length] == '.')
) {
val location = Location(testDataFile, existingPackageDeclarationLineNumber)
"$location: Invalid package name declaration found: $existingPackageDeclarationLine\nExpected: package $packageName"
"""
$location: Invalid package name declaration found: $existingPackageDeclarationLine
Expected: package $packageName
""".trimIndent()
}
text
} else
@@ -19,7 +19,11 @@ internal fun getAbsoluteFile(localPath: String): File = File(getHomeDirectory())
internal fun computeGeneratedSourcesDir(testDataBaseDir: File, testDataFile: File, generatedSourcesBaseDir: File): File {
assertTrue(testDataFile.startsWith(testDataBaseDir)) {
"The file is outside of the directory.\nFile: $testDataFile\nDirectory: $testDataBaseDir"
"""
The file is outside of the directory.
File: $testDataFile
Directory: $testDataBaseDir
""".trimIndent()
}
val testDataFileDir = testDataFile.parentFile
@@ -15,7 +15,11 @@ import kotlin.math.min
internal fun computePackageName(testDataBaseDir: File, testDataFile: File): PackageName {
assertTrue(testDataFile.startsWith(testDataBaseDir)) {
"The file is outside of the directory.\nFile: $testDataFile\nDirectory: $testDataBaseDir"
"""
The file is outside of the directory.
File: $testDataFile
Directory: $testDataBaseDir
""".trimIndent()
}
return testDataFile.parentFile