1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-07 21:17:07 +09:00

LibTest/Tests: Build and run test-js on windows

This commit allows test-js to build and run, also in CI.

Co-authored-by: Andrew Kaster <andrew@ladybird.org>
This commit is contained in:
R-Goc 2025-05-30 10:50:55 +02:00 committed by Andrew Kaster
parent 6c8623320f
commit 9ec26058d1
Notes: github-actions[bot] 2025-06-06 04:01:57 +00:00
6 changed files with 54 additions and 48 deletions

View file

@ -6,11 +6,11 @@ describe("getter - normal behavior", () => {
test("basic functionality", () => { test("basic functionality", () => {
const stackFrames = [ const stackFrames = [
/^ at .*Error$/, /^ at .*Error$/,
/^ at .+\/Error\/Error\.prototype\.stack\.js:\d+:\d+$/, /^ at .+[\\/]Error[\\/]Error\.prototype\.stack\.js:\d+:\d+$/,
/^ at test \(.+\/test-common.js:\d+:\d+\)$/, /^ at test \(.+[\\/]test-common\.js:\d+:\d+\)$/,
/^ at .+\/Error\/Error\.prototype\.stack\.js:6:9$/, /^ at .+[\\/]Error[\\/]Error\.prototype\.stack\.js:6:9$/,
/^ at describe \(.+\/test-common\.js:\d+:\d+\)$/, /^ at describe \(.+[\\/]test-common\.js:\d+:\d+\)$/,
/^ at .+\/Error\/Error\.prototype\.stack\.js:5:9$/, /^ at .+[\\/]Error[\\/]Error\.prototype\.stack\.js:5:9$/,
]; ];
const values = [ const values = [
{ {

View file

@ -11,9 +11,4 @@ lagom_generate_export_header(LibTest test)
target_link_libraries(LibTest PRIVATE AK LibCore LibFileSystem) target_link_libraries(LibTest PRIVATE AK LibCore LibFileSystem)
set_target_properties(LibTest PROPERTIES OUTPUT_NAME lagom-test) set_target_properties(LibTest PROPERTIES OUTPUT_NAME lagom-test)
# FIXME: Increase support for building targets on Windows
if (WIN32 AND ENABLE_WINDOWS_CI)
return()
endif()
add_library(JavaScriptTestRunnerMain OBJECT JavaScriptTestRunnerMain.cpp) add_library(JavaScriptTestRunnerMain OBJECT JavaScriptTestRunnerMain.cpp)

View file

@ -32,9 +32,6 @@
#include <LibJS/SourceTextModule.h> #include <LibJS/SourceTextModule.h>
#include <LibTest/Results.h> #include <LibTest/Results.h>
#include <LibTest/TestRunner.h> #include <LibTest/TestRunner.h>
#include <fcntl.h>
#include <sys/time.h>
#include <unistd.h>
#define STRCAT(x, y) __STRCAT(x, y) #define STRCAT(x, y) __STRCAT(x, y)
#define STRSTRCAT(x, y) __STRSTRCAT(x, y) #define STRSTRCAT(x, y) __STRSTRCAT(x, y)

View file

@ -6,7 +6,10 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include <AK/LexicalPath.h>
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/Environment.h>
#include <LibCore/System.h>
#include <LibFileSystem/FileSystem.h> #include <LibFileSystem/FileSystem.h>
#include <LibTest/JavaScriptTestRunner.h> #include <LibTest/JavaScriptTestRunner.h>
#include <signal.h> #include <signal.h>
@ -36,19 +39,35 @@ using namespace Test::JS;
static StringView g_program_name { "test-js"sv }; static StringView g_program_name { "test-js"sv };
static bool set_abort_action(void (*function)(int))
{
#if defined(AK_OS_WINDOWS)
auto rc = signal(SIGABRT, function);
if (rc == SIG_ERR) {
perror("sigaction");
return false;
}
return true;
#else
struct sigaction act;
memset(&act, 0, sizeof(act));
act.sa_flags = 0;
act.sa_handler = function;
int rc = sigaction(SIGABRT, &act, nullptr);
if (rc < 0) {
perror("sigaction");
return false;
}
return true;
#endif
}
static void handle_sigabrt(int) static void handle_sigabrt(int)
{ {
dbgln("{}: SIGABRT received, cleaning up.", g_program_name); dbgln("{}: SIGABRT received, cleaning up.", g_program_name);
Test::cleanup(); Test::cleanup();
struct sigaction act; if (!set_abort_action(SIG_DFL))
memset(&act, 0, sizeof(act));
act.sa_flags = 0;
act.sa_handler = SIG_DFL;
int rc = sigaction(SIGABRT, &act, nullptr);
if (rc < 0) {
perror("sigaction");
exit(1); exit(1);
}
abort(); abort();
} }
@ -64,15 +83,8 @@ int main(int argc, char** argv)
auto program_name = LexicalPath::basename(argv[0]); auto program_name = LexicalPath::basename(argv[0]);
g_program_name = program_name; g_program_name = program_name;
struct sigaction act; if (!set_abort_action(handle_sigabrt))
memset(&act, 0, sizeof(act));
act.sa_flags = 0;
act.sa_handler = handle_sigabrt;
int rc = sigaction(SIGABRT, &act, nullptr);
if (rc < 0) {
perror("sigaction");
return 1; return 1;
}
#ifdef SIGINFO #ifdef SIGINFO
signal(SIGINFO, [](int) { signal(SIGINFO, [](int) {
@ -128,7 +140,7 @@ int main(int argc, char** argv)
if (test_globs.is_empty()) if (test_globs.is_empty())
test_globs.append("*"sv); test_globs.append("*"sv);
if (getenv("DISABLE_DBG_OUTPUT")) { if (Core::Environment::has("DISABLE_DBG_OUTPUT"sv)) {
AK::set_debug_enabled(false); AK::set_debug_enabled(false);
} }
@ -137,13 +149,13 @@ int main(int argc, char** argv)
if (!specified_test_root.is_empty()) { if (!specified_test_root.is_empty()) {
test_root = ByteString { specified_test_root }; test_root = ByteString { specified_test_root };
} else { } else {
char* ladybird_source_dir = getenv("LADYBIRD_SOURCE_DIR"); auto ladybird_source_dir = Core::Environment::get("LADYBIRD_SOURCE_DIR"sv);
if (!ladybird_source_dir) { if (!ladybird_source_dir.has_value()) {
warnln("No test root given, {} requires the LADYBIRD_SOURCE_DIR environment variable to be set", g_program_name); warnln("No test root given, {} requires the LADYBIRD_SOURCE_DIR environment variable to be set", g_program_name);
return 1; return 1;
} }
test_root = ByteString::formatted("{}/{}", ladybird_source_dir, g_test_root_fragment); test_root = LexicalPath::join(*ladybird_source_dir, g_test_root_fragment).string();
common_path = ByteString::formatted("{}/Libraries/LibJS/Tests/test-common.js", ladybird_source_dir); common_path = LexicalPath::join(*ladybird_source_dir, "Libraries"sv, "LibJS"sv, "Tests"sv, "test-common.js"sv).string();
} }
if (!FileSystem::is_directory(test_root)) { if (!FileSystem::is_directory(test_root)) {
warnln("Test root is not a directory: {}", test_root); warnln("Test root is not a directory: {}", test_root);
@ -151,12 +163,12 @@ int main(int argc, char** argv)
} }
if (common_path.is_empty()) { if (common_path.is_empty()) {
char* ladybird_source_dir = getenv("LADYBIRD_SOURCE_DIR"); auto ladybird_source_dir = Core::Environment::get("LADYBIRD_SOURCE_DIR"sv);
if (!ladybird_source_dir) { if (!ladybird_source_dir.has_value()) {
warnln("No test root given, {} requires the LADYBIRD_SOURCE_DIR environment variable to be set", g_program_name); warnln("No test root given, {} requires the LADYBIRD_SOURCE_DIR environment variable to be set", g_program_name);
return 1; return 1;
} }
common_path = ByteString::formatted("{}/Libraries/LibJS/Tests/test-common.js", ladybird_source_dir); common_path = LexicalPath::join(*ladybird_source_dir, "Libraries"sv, "LibJS"sv, "Tests"sv, "test-common.js"sv).string();
} }
auto test_root_or_error = FileSystem::real_path(test_root); auto test_root_or_error = FileSystem::real_path(test_root);
@ -173,9 +185,8 @@ int main(int argc, char** argv)
} }
common_path = common_path_or_error.release_value(); common_path = common_path_or_error.release_value();
if (chdir(test_root.characters()) < 0) { if (auto err = Core::System::chdir(test_root); err.is_error()) {
auto saved_errno = errno; warnln("chdir failed: {}", err.error());
warnln("chdir failed: {}", strerror(saved_errno));
return 1; return 1;
} }

View file

@ -8,9 +8,12 @@
#include <AK/Time.h> #include <AK/Time.h>
#include <LibCore/DirIterator.h> #include <LibCore/DirIterator.h>
#include <fcntl.h> #include <LibFileSystem/FileSystem.h>
#include <sys/stat.h>
#include <sys/time.h> #if !defined(AK_OS_WINDOWS)
# include <fcntl.h>
# include <sys/stat.h>
#endif
namespace Test { namespace Test {
@ -27,11 +30,15 @@ inline void iterate_directory_recursively(ByteString const& directory_path, Call
while (directory_iterator.has_next()) { while (directory_iterator.has_next()) {
auto name = directory_iterator.next_path(); auto name = directory_iterator.next_path();
auto full_path = LexicalPath::join(directory_path, name).string();
#if defined(AK_OS_WINDOWS)
bool is_directory = FileSystem::is_directory(full_path);
#else
struct stat st = {}; struct stat st = {};
if (fstatat(directory_iterator.fd(), name.characters(), &st, AT_SYMLINK_NOFOLLOW) < 0) if (fstatat(directory_iterator.fd(), name.characters(), &st, AT_SYMLINK_NOFOLLOW) < 0)
continue; continue;
bool is_directory = S_ISDIR(st.st_mode); bool is_directory = S_ISDIR(st.st_mode);
auto full_path = ByteString::formatted("{}/{}", directory_path, name); #endif
if (is_directory && name != "/Fixtures"sv) { if (is_directory && name != "/Fixtures"sv) {
iterate_directory_recursively(full_path, callback); iterate_directory_recursively(full_path, callback);
} else if (!is_directory) { } else if (!is_directory) {

View file

@ -1,9 +1,5 @@
serenity_test(test-invalid-unicode-js.cpp LibJS LIBS LibJS LibUnicode) serenity_test(test-invalid-unicode-js.cpp LibJS LIBS LibJS LibUnicode)
serenity_test(test-value-js.cpp LibJS LIBS LibJS LibUnicode) serenity_test(test-value-js.cpp LibJS LIBS LibJS LibUnicode)
if (WIN32 AND ENABLE_WINDOWS_CI)
return()
endif()
serenity_testjs_test(test-js.cpp test-js LIBS LibGC) serenity_testjs_test(test-js.cpp test-js LIBS LibGC)
set_tests_properties(test-js PROPERTIES ENVIRONMENT LADYBIRD_SOURCE_DIR=${SERENITY_PROJECT_ROOT}) set_tests_properties(test-js PROPERTIES ENVIRONMENT LADYBIRD_SOURCE_DIR=${SERENITY_PROJECT_ROOT})