From f824bb69870805c332bd705768595cb50b5e2596 Mon Sep 17 00:00:00 2001 From: Roman Artemev Date: Tue, 6 Oct 2020 16:24:13 +0300 Subject: [PATCH] [JS BE] Merge Legacy and IR BE exceptions-related test data - regenerate tests - add consistency test --- .../semantics/IrBoxJsES6TestGenerated.java | 5 ++ .../ir/semantics/IrBoxJsTestGenerated.java | 5 ++ .../js/test/semantics/BoxJsTestGenerated.java | 5 ++ .../evaluationOrder/throwableDelegation.kt | 4 +- .../standardClasses/throwableConsistancy.kt | 55 +++++++++++++++++++ 5 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 js/js.translator/testData/box/standardClasses/throwableConsistancy.kt diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrBoxJsES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrBoxJsES6TestGenerated.java index e280c046d0e..52090674916 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrBoxJsES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrBoxJsES6TestGenerated.java @@ -7676,6 +7676,11 @@ public class IrBoxJsES6TestGenerated extends AbstractIrBoxJsES6Test { runTest("js/js.translator/testData/box/standardClasses/stringPlus.kt"); } + @TestMetadata("throwableConsistancy.kt") + public void testThrowableConsistancy() throws Exception { + runTest("js/js.translator/testData/box/standardClasses/throwableConsistancy.kt"); + } + @TestMetadata("throwableCtor.kt") public void testThrowableCtor() throws Exception { runTest("js/js.translator/testData/box/standardClasses/throwableCtor.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java index 3622a1e324f..9bc0e102973 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrBoxJsTestGenerated.java @@ -7676,6 +7676,11 @@ public class IrBoxJsTestGenerated extends AbstractIrBoxJsTest { runTest("js/js.translator/testData/box/standardClasses/stringPlus.kt"); } + @TestMetadata("throwableConsistancy.kt") + public void testThrowableConsistancy() throws Exception { + runTest("js/js.translator/testData/box/standardClasses/throwableConsistancy.kt"); + } + @TestMetadata("throwableCtor.kt") public void testThrowableCtor() throws Exception { runTest("js/js.translator/testData/box/standardClasses/throwableCtor.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java index 2d949c7e7fe..c85dde4dc75 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/BoxJsTestGenerated.java @@ -7706,6 +7706,11 @@ public class BoxJsTestGenerated extends AbstractBoxJsTest { runTest("js/js.translator/testData/box/standardClasses/stringPlus.kt"); } + @TestMetadata("throwableConsistancy.kt") + public void testThrowableConsistancy() throws Exception { + runTest("js/js.translator/testData/box/standardClasses/throwableConsistancy.kt"); + } + @TestMetadata("throwableCtor.kt") public void testThrowableCtor() throws Exception { runTest("js/js.translator/testData/box/standardClasses/throwableCtor.kt"); diff --git a/js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt b/js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt index ebb47e3a26d..9ae7db9f682 100644 --- a/js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt +++ b/js/js.translator/testData/box/expression/evaluationOrder/throwableDelegation.kt @@ -25,10 +25,10 @@ class MyException2(i1: String, i2: String, m: String? = null, t: Throwable? = nu fun box(): String { check(MyException1("1", "2"), "MyException1") check(MyException1("3", "4", "aaa"), "MyException1: aaa") - check(MyException1("5", "6", t = Throwable("bbb")), "MyException1: Throwable: bbb") + check(MyException1("5", "6", t = Throwable("bbb")), "MyException1") check(MyException2("7", "8"), "MyException2") check(MyException2("9", "0", "ccc"), "MyException2: ccc") - check(MyException2("A", "B", t = Throwable("ddd")), "MyException2: Throwable: ddd") + check(MyException2("A", "B", t = Throwable("ddd")), "MyException2") if (storage != "1234567890AB") return "FAIL $storage" diff --git a/js/js.translator/testData/box/standardClasses/throwableConsistancy.kt b/js/js.translator/testData/box/standardClasses/throwableConsistancy.kt new file mode 100644 index 00000000000..fe679fcef3d --- /dev/null +++ b/js/js.translator/testData/box/standardClasses/throwableConsistancy.kt @@ -0,0 +1,55 @@ +// IGNORE_BACKEND: JS + + + +fun test(case: String, expctedMessage: String?, expectedCause: Throwable?, expectedToString: String, t: Throwable): String { + val actualMessage = t.message + if (actualMessage != expctedMessage) return "$case FAIL message: $actualMessage, expcted: $expctedMessage" + + val actualCause = t.cause + if (actualCause != expectedCause) return "$case FAIL cause: $actualCause, expcted: $expectedCause" + + val actualToString = t.toString() + if (actualToString != expectedToString) return "$case FAIL toString: $actualToString, expcted: $expectedToString" + + return "OK" +} + + +fun box(): String { + + + var result: String = "FAIL" + + result = test("Throwable()", null, null, "Throwable", Throwable()) + if (result != "OK") return result + + result = test("Throwable(\"aaaa\")", "aaaa", null, "Throwable: aaaa", Throwable("aaaa")) + if (result != "OK") return result + + var cause = Throwable() + result = test("Throwable(Throwable())", "Throwable", cause, "Throwable: Throwable", Throwable(cause)) + if (result != "OK") return result + + cause = Throwable("ccc") + result = test("Throwable(\"bbbb\", Throwable(\"ccc\"))", "bbbb", cause, "Throwable: bbbb", Throwable("bbbb", cause)) + if (result != "OK") return result + + result = test("Throwable(message = null)", null, null, "Throwable", Throwable(message = null)) + if (result != "OK") return result + + result = test("Throwable(cause = null)", null, null, "Throwable", Throwable(cause = null)) + if (result != "OK") return result + + result = test("Throwable(null, null)", null, null, "Throwable", Throwable(null, null)) + if (result != "OK") return result + + result = test("Throwable(\"eee\", null)", "eee", null, "Throwable: eee", Throwable("eee", null)) + if (result != "OK") return result + + cause = Throwable("ddd") + result = test("Throwable(null, Throwable(\"ddd\"))", null, cause, "Throwable", Throwable(null, cause)) + if (result != "OK") return result + + return "OK" +}