From 62ad33af93103aa12c43131a2904743b96963e70 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sun, 13 Feb 2022 14:54:45 +0330 Subject: [PATCH] Tests: Wrap test-bytecode-js source in an IIFE Putting everything in the global scope will lead to mayhem and failing tests with an actually correct implementation of scoping :^) Also adds in a tiny debug log of the exception, otherwise we'd be staring at failing tests with no info on what failed. --- Tests/LibJS/test-bytecode-js.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Tests/LibJS/test-bytecode-js.cpp b/Tests/LibJS/test-bytecode-js.cpp index 7f20a1a38f..3ee794d49a 100644 --- a/Tests/LibJS/test-bytecode-js.cpp +++ b/Tests/LibJS/test-bytecode-js.cpp @@ -25,7 +25,9 @@ #define EXPECT_NO_EXCEPTION(executable) \ auto executable = MUST(JS::Bytecode::Generator::generate(program)); \ auto result = bytecode_interpreter.run(*executable); \ - EXPECT(!result.is_error()); + EXPECT(!result.is_error()); \ + if (result.is_error()) \ + dbgln("Error: {}", MUST(result.throw_completion().value()->to_string(bytecode_interpreter.global_object()))); #define EXPECT_NO_EXCEPTION_WITH_OPTIMIZATIONS(executable) \ auto& passes = JS::Bytecode::Interpreter::optimization_pipeline(); \ @@ -33,11 +35,13 @@ \ auto result_with_optimizations = bytecode_interpreter.run(*executable); \ \ - EXPECT(!result_with_optimizations.is_error()); + EXPECT(!result_with_optimizations.is_error()); \ + if (result_with_optimizations.is_error()) \ + dbgln("Error: {}", MUST(result_with_optimizations.throw_completion().value()->to_string(bytecode_interpreter.global_object()))); -#define EXPECT_NO_EXCEPTION_ALL(source) \ - SETUP_AND_PARSE(source) \ - EXPECT_NO_EXCEPTION(executable) \ +#define EXPECT_NO_EXCEPTION_ALL(source) \ + SETUP_AND_PARSE("(() => {\n" source "\n})()") \ + EXPECT_NO_EXCEPTION(executable) \ EXPECT_NO_EXCEPTION_WITH_OPTIMIZATIONS(executable) TEST_CASE(empty_program)