From adc3e617427902e5ebf589546b059ab8b776d640 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 9 Apr 2018 05:51:06 +0300 Subject: [PATCH] Make assertion message more readable in JPS test The test was failing recently on CI, but assertion message does not give enough info: arrays' sizes are not equal, so there were extra warnings, but what they were? --- .../kotlin/jps/build/KotlinJpsBuildTest.kt | 32 +++++++++++-------- .../jps/build/KotlinJpsBuildTest.kt.172 | 32 +++++++++++-------- 2 files changed, 36 insertions(+), 28 deletions(-) diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt index 7d1a42aa023..d4be2bf9517 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt @@ -807,28 +807,32 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { } fun testFileDoesNotExistWarning() { + fun absoluteFiles(vararg paths: String): Array = + paths.map { File(it).absoluteFile }.toTypedArray() + initProject(JVM_MOCK_RUNTIME) + val filesToBeReported = absoluteFiles("badroot.jar", "some/test.class") + val otherFiles = absoluteFiles("test/other/file.xml", "some/other/baddir") + AbstractKotlinJpsBuildTestCase.addDependency( - JpsJavaDependencyScope.COMPILE, Lists.newArrayList(findModule("module")), false, "LibraryWithBadRoots", - File("badroot.jar"), - File("test/other/file.xml"), - File("some/test.class"), - File("some/other/baddir")) + JpsJavaDependencyScope.COMPILE, + Lists.newArrayList(findModule("module")), + false, + "LibraryWithBadRoots", + *(filesToBeReported + otherFiles) + ) val result = buildAllModules() result.assertSuccessful() - val warnings = result.getMessages(BuildMessage.Kind.WARNING) + val actualWarnings = result.getMessages(BuildMessage.Kind.WARNING).map { it.messageText } + val expectedWarnings = filesToBeReported.map { "Classpath entry points to a non-existent location: $it" } - Assert.assertArrayEquals( - arrayOf( - """Classpath entry points to a non-existent location: TEST_PATH/badroot.jar""", - """Classpath entry points to a non-existent location: TEST_PATH/some/test.class"""), - warnings.map { - it.messageText.replace(File("").absolutePath, "TEST_PATH").replace("\\", "/") - }.sorted().toTypedArray() - ) + val expectedText = expectedWarnings.sorted().joinToString("\n") + val actualText = actualWarnings.sorted().joinToString("\n") + + Assert.assertEquals(expectedText, actualText) } fun testHelp() { diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt.172 b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt.172 index de5f263db8b..a3a27221284 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt.172 +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/KotlinJpsBuildTest.kt.172 @@ -806,28 +806,32 @@ open class KotlinJpsBuildTest : AbstractKotlinJpsBuildTestCase() { } fun testFileDoesNotExistWarning() { + fun absoluteFiles(vararg paths: String): Array = + paths.map { File(it).absoluteFile }.toTypedArray() + initProject(JVM_MOCK_RUNTIME) + val filesToBeReported = absoluteFiles("badroot.jar", "some/test.class") + val otherFiles = absoluteFiles("test/other/file.xml", "some/other/baddir") + AbstractKotlinJpsBuildTestCase.addDependency( - JpsJavaDependencyScope.COMPILE, Lists.newArrayList(findModule("module")), false, "LibraryWithBadRoots", - File("badroot.jar"), - File("test/other/file.xml"), - File("some/test.class"), - File("some/other/baddir")) + JpsJavaDependencyScope.COMPILE, + Lists.newArrayList(findModule("module")), + false, + "LibraryWithBadRoots", + *(filesToBeReported + otherFiles) + ) val result = buildAllModules() result.assertSuccessful() - val warnings = result.getMessages(BuildMessage.Kind.WARNING) + val actualWarnings = result.getMessages(BuildMessage.Kind.WARNING).map { it.messageText } + val expectedWarnings = filesToBeReported.map { "Classpath entry points to a non-existent location: $it" } - Assert.assertArrayEquals( - arrayOf( - """Classpath entry points to a non-existent location: TEST_PATH/badroot.jar""", - """Classpath entry points to a non-existent location: TEST_PATH/some/test.class"""), - warnings.map { - it.messageText.replace(File("").absolutePath, "TEST_PATH").replace("\\", "/") - }.sorted().toTypedArray() - ) + val expectedText = expectedWarnings.sorted().joinToString("\n") + val actualText = actualWarnings.sorted().joinToString("\n") + + Assert.assertEquals(expectedText, actualText) } fun testHelp() {