summaryrefslogtreecommitdiff
path: root/Tests/Spreadsheet/test-spreadsheet.cpp
blob: 88d3296a3bd40f85baefa29c63aa4bd9eeadabdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/*
 * Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#include <LibJS/Runtime/Map.h>
#include <LibTest/JavaScriptTestRunner.h>

TEST_ROOT("Userland/Applications/Spreadsheet/Tests");

#ifdef AK_OS_SERENITY
static constexpr auto s_spreadsheet_runtime_path = "/res/js/Spreadsheet/runtime.js"sv;
#else
static constexpr auto s_spreadsheet_runtime_path = "../../../../Base/res/js/Spreadsheet/runtime.js"sv;
#endif

TESTJS_RUN_FILE_FUNCTION(DeprecatedString const&, JS::Interpreter& interpreter, JS::ExecutionContext& global_execution_context)
{
    auto run_file = [&](StringView name) {
        auto result = Test::JS::parse_script(name, interpreter.realm());
        if (result.is_error()) {
            warnln("Unable to parse {}", name);
            warnln("{}", result.error().error.to_deprecated_string());
            warnln("{}", result.error().hint);
            Test::cleanup_and_exit();
        }
        auto script = result.release_value();

        interpreter.vm().push_execution_context(global_execution_context);
        MUST(interpreter.run(*script));
        interpreter.vm().pop_execution_context();
    };

#ifdef AK_OS_SERENITY
    run_file(s_spreadsheet_runtime_path);
#else
    run_file(LexicalPath::join(Test::JS::g_test_root, s_spreadsheet_runtime_path).string());
#endif

    run_file("mock.test-common.js"sv);

    return Test::JS::RunFileHookResult::RunAsNormal;
}