From ba68ef697a58acff80bb942f6bb910b25293e6ac Mon Sep 17 00:00:00 2001 From: Andrew Morris Date: Thu, 23 Mar 2023 15:48:33 +1100 Subject: [PATCH] Test exceptions --- .../passing/exceptions/finallyWithoutThrow.ts | 12 +++++++++++ inputs/passing/exceptions/nestedTry.ts | 21 +++++++++++++++++++ inputs/passing/exceptions/tryCatch.ts | 9 ++++++++ inputs/passing/exceptions/tryCatchFinally.ts | 11 ++++++++++ inputs/passing/exceptions/tryFinally.ts | 9 ++++++++ .../exceptions/tryReturnFinallyReturn.ts | 9 ++++++++ 6 files changed, 71 insertions(+) create mode 100644 inputs/passing/exceptions/finallyWithoutThrow.ts create mode 100644 inputs/passing/exceptions/nestedTry.ts create mode 100644 inputs/passing/exceptions/tryCatch.ts create mode 100644 inputs/passing/exceptions/tryCatchFinally.ts create mode 100644 inputs/passing/exceptions/tryFinally.ts create mode 100644 inputs/passing/exceptions/tryReturnFinallyReturn.ts diff --git a/inputs/passing/exceptions/finallyWithoutThrow.ts b/inputs/passing/exceptions/finallyWithoutThrow.ts new file mode 100644 index 0000000..467780c --- /dev/null +++ b/inputs/passing/exceptions/finallyWithoutThrow.ts @@ -0,0 +1,12 @@ +// test_output! "Ok" + +export default function () { + let result: string; + + try { + } finally { + result = "Ok"; + } + + return result; +} diff --git a/inputs/passing/exceptions/nestedTry.ts b/inputs/passing/exceptions/nestedTry.ts new file mode 100644 index 0000000..0d04600 --- /dev/null +++ b/inputs/passing/exceptions/nestedTry.ts @@ -0,0 +1,21 @@ +// test_output! ["here","nested boom","boom"] + +export default function () { + let logs: unknown[] = []; + + try { + logs.push("here"); + + try { + throw new Error("nested boom"); + } catch (error) { + logs.push(error.message); + } + + throw new Error("boom"); + } catch (error) { + logs.push(error.message); + } + + return logs; +} diff --git a/inputs/passing/exceptions/tryCatch.ts b/inputs/passing/exceptions/tryCatch.ts new file mode 100644 index 0000000..8ded5b6 --- /dev/null +++ b/inputs/passing/exceptions/tryCatch.ts @@ -0,0 +1,9 @@ +// test_output! Error{"message":"Something went wrong"} + +export default function () { + try { + throw new Error("Something went wrong"); + } catch (error) { + return error; + } +} diff --git a/inputs/passing/exceptions/tryCatchFinally.ts b/inputs/passing/exceptions/tryCatchFinally.ts new file mode 100644 index 0000000..57f38fb --- /dev/null +++ b/inputs/passing/exceptions/tryCatchFinally.ts @@ -0,0 +1,11 @@ +// test_output! E: Error{"message":"teraboom"} + +export default function () { + try { + throw new Error("boom"); + } catch { + throw new Error("megaboom"); + } finally { + throw new Error("teraboom"); + } +} diff --git a/inputs/passing/exceptions/tryFinally.ts b/inputs/passing/exceptions/tryFinally.ts new file mode 100644 index 0000000..904d14d --- /dev/null +++ b/inputs/passing/exceptions/tryFinally.ts @@ -0,0 +1,9 @@ +// test_output! E: Error{"message":"Something went wrong"} + +export default function () { + try { + throw new Error("Something went wrong"); + } finally { + 1 + 1; + } +} diff --git a/inputs/passing/exceptions/tryReturnFinallyReturn.ts b/inputs/passing/exceptions/tryReturnFinallyReturn.ts new file mode 100644 index 0000000..fe6ba65 --- /dev/null +++ b/inputs/passing/exceptions/tryReturnFinallyReturn.ts @@ -0,0 +1,9 @@ +// test_output! 42 + +export default function () { + try { + return 37; + } finally { + return 42; + } +}