From ec57a335f7abe6e0886fcd901440856dbb0ab25e Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Mon, 23 Apr 2018 21:00:06 +0300 Subject: [PATCH] Temporally hacked js assert to make depending tests work --- .../jetbrains/kotlin/js/test/BasicBoxTest.kt | 5 ++-- .../kotlin/js/test/BasicIrBoxTest.kt | 3 ++- .../testData/_commonFiles/arrayAsserts.kt | 25 ++++++++++++++++++ .../testData/_commonFiles/asserts.kt | 26 ------------------- .../testData/_commonFiles/fail.kt | 5 ++++ .../testData/_commonFiles/fail_hacked.kt | 7 +++++ 6 files changed, 42 insertions(+), 29 deletions(-) create mode 100644 js/js.translator/testData/_commonFiles/arrayAsserts.kt create mode 100644 js/js.translator/testData/_commonFiles/fail.kt create mode 100644 js/js.translator/testData/_commonFiles/fail_hacked.kt diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt index 4ed59ae60a9..ea879fc0e0f 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt @@ -436,8 +436,9 @@ abstract class BasicBoxTest( testPackage: String?, testFunction: String ) { + val filteredUnits = units.filter { it !is TranslationUnit.SourceFile || !it.file.virtualFilePath.endsWith("js/js.translator/testData/_commonFiles/fail_hacked.kt") } val translator = K2JSTranslator(config) - val translationResult = translator.translateUnits(ExceptionThrowingReporter, units, mainCallParameters) + val translationResult = translator.translateUnits(ExceptionThrowingReporter, filteredUnits, mainCallParameters) if (translationResult !is TranslationResult.Success) { val outputStream = ByteArrayOutputStream() @@ -476,7 +477,7 @@ abstract class BasicBoxTest( incrementalData.header = incrementalService.headerMetadata } - processJsProgram(translationResult.program, units.filterIsInstance().map { it.file }) + processJsProgram(translationResult.program, filteredUnits.filterIsInstance().map { it.file }) checkSourceMap(outputFile, translationResult.program, remap) } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt index 6f9e19c7471..b0a8c57fdfc 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt @@ -48,7 +48,8 @@ abstract class BasicIrBoxTest( units.map { (it as TranslationUnit.SourceFile).file } // TODO: temporary ignore _commonFiles/asserts.kt since it depends on stdlib but we don't have any library support in JS IR BE yet // and probably it will be better to avoid using stdlib in testData as much as possible. - .filter { !it.virtualFilePath.endsWith("js/js.translator/testData/_commonFiles/asserts.kt") }, + .filter { !it.virtualFilePath.endsWith("js/js.translator/testData/_commonFiles/arrayAsserts.kt") } + .filter { !it.virtualFilePath.endsWith("js/js.translator/testData/_commonFiles/fail.kt") }, config.configuration, FqName((testPackage?.let { it + "." } ?: "") + testFunction)) diff --git a/js/js.translator/testData/_commonFiles/arrayAsserts.kt b/js/js.translator/testData/_commonFiles/arrayAsserts.kt new file mode 100644 index 00000000000..36519db290f --- /dev/null +++ b/js/js.translator/testData/_commonFiles/arrayAsserts.kt @@ -0,0 +1,25 @@ +package kotlin + +fun assertArrayEquals(expected: Array, actual: Array, message: String? = null) { + if (!arraysEqual(expected, actual)) { + val msg = if (message == null) "" else ", message = '$message'" + fail("Unexpected array: expected = '$expected', actual = '$actual'$msg") + } +} + +private fun arraysEqual(first: Array, second: Array): Boolean { + if (first === second) return true + if (first.size != second.size) return false + for (index in first.indices) { + if (!equal(first[index], second[index])) return false + } + return true +} + +private fun equal(first: Any?, second: Any?) = + if (first is Array<*> && second is Array<*>) { + arraysEqual(first, second) + } + else { + first == second + } \ No newline at end of file diff --git a/js/js.translator/testData/_commonFiles/asserts.kt b/js/js.translator/testData/_commonFiles/asserts.kt index 786234eb818..360c80c0d5d 100644 --- a/js/js.translator/testData/_commonFiles/asserts.kt +++ b/js/js.translator/testData/_commonFiles/asserts.kt @@ -2,8 +2,6 @@ package kotlin // This file should be excluded from tests using StdLib, as these methods conflict with corresponding methods from kotlin.test // see StdLibTestBase.removeAdHocAssertions -fun fail(message: String? = null): Nothing = js("throw new Error(message)") - fun assertEquals(expected: T, actual: T, message: String? = null) { if (expected != actual) { val msg = if (message == null) "" else ", message = '$message'" @@ -25,30 +23,6 @@ fun assertSame(expected: T, actual: T, message: String? = null) { } } -fun assertArrayEquals(expected: Array, actual: Array, message: String? = null) { - if (!arraysEqual(expected, actual)) { - val msg = if (message == null) "" else ", message = '$message'" - fail("Unexpected array: expected = '$expected', actual = '$actual'$msg") - } -} - -private fun arraysEqual(first: Array, second: Array): Boolean { - if (first === second) return true - if (first.size != second.size) return false - for (index in first.indices) { - if (!equal(first[index], second[index])) return false - } - return true -} - -private fun equal(first: Any?, second: Any?) = - if (first is Array<*> && second is Array<*>) { - arraysEqual(first, second) - } - else { - first == second - } - fun assertTrue(actual: Boolean, message: String? = null) = assertEquals(true, actual, message) fun assertFalse(actual: Boolean, message: String? = null) = assertEquals(false, actual, message) diff --git a/js/js.translator/testData/_commonFiles/fail.kt b/js/js.translator/testData/_commonFiles/fail.kt new file mode 100644 index 00000000000..b5ea2ef55b6 --- /dev/null +++ b/js/js.translator/testData/_commonFiles/fail.kt @@ -0,0 +1,5 @@ +package kotlin +// This file should be excluded from tests using StdLib, as these methods conflict with corresponding methods from kotlin.test +// see StdLibTestBase.removeAdHocAssertions + +fun fail(message: String? = null) = js("throw new Error(message)") \ No newline at end of file diff --git a/js/js.translator/testData/_commonFiles/fail_hacked.kt b/js/js.translator/testData/_commonFiles/fail_hacked.kt new file mode 100644 index 00000000000..e99ea96df12 --- /dev/null +++ b/js/js.translator/testData/_commonFiles/fail_hacked.kt @@ -0,0 +1,7 @@ +package kotlin +// This file should be excluded from tests using StdLib, as these methods conflict with corresponding methods from kotlin.test +// see StdLibTestBase.removeAdHocAssertions + +fun fail(message: String? = null): Nothing { + null!! +} \ No newline at end of file