Temporally hacked js assert to make depending tests work
This commit is contained in:
committed by
Roman Artemev
parent
efdc5701d9
commit
ec57a335f7
@@ -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<TranslationUnit.SourceFile>().map { it.file })
|
||||
processJsProgram(translationResult.program, filteredUnits.filterIsInstance<TranslationUnit.SourceFile>().map { it.file })
|
||||
checkSourceMap(outputFile, translationResult.program, remap)
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package kotlin
|
||||
|
||||
fun <T> assertArrayEquals(expected: Array<out T>, actual: Array<out T>, 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 <T> arraysEqual(first: Array<out T>, second: Array<out T>): 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
|
||||
}
|
||||
@@ -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 <T> assertEquals(expected: T, actual: T, message: String? = null) {
|
||||
if (expected != actual) {
|
||||
val msg = if (message == null) "" else ", message = '$message'"
|
||||
@@ -25,30 +23,6 @@ fun <T> assertSame(expected: T, actual: T, message: String? = null) {
|
||||
}
|
||||
}
|
||||
|
||||
fun <T> assertArrayEquals(expected: Array<out T>, actual: Array<out T>, 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 <T> arraysEqual(first: Array<out T>, second: Array<out T>): 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)
|
||||
|
||||
@@ -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)")
|
||||
@@ -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!!
|
||||
}
|
||||
Reference in New Issue
Block a user