Tests/LibWeb: Normalize paths when removing test files via glob matches
When tests are being collected, the paths get canonicalized via the FileSystem::real_path() call. This means on Windows the paths are using `\` as the directory separator. Tests get removed by performing string-based matching on a hardcoded set of support file globs and an optional user defined glob. Even if we normalized these globs to use `\` instead of `/` on Windows, they still wouldn't match because AK::StringUtils::matches() uses `\` to escape metacharacters. For example, `my\relative\windows\path` will not match `my\*\path` because the mask is interpreted as `"my*\path"` instead. So we normalize paths to use POSIX separators to support the existing glob matching infrastructure. This allows Windows to filter out support files properly which prevents us from crashing when Ref tests try to load one of those files. It also allows Windows to use `/`-based paths for the -f argument.
This commit is contained in:
parent
aa6b588c97
commit
259e10a28a
1 changed files with 5 additions and 2 deletions
|
|
@ -1109,8 +1109,11 @@ static ErrorOr<int> run_tests(Core::AnonymousBuffer const& theme, Web::DevicePix
|
|||
"*/wpt-import/common/*"sv,
|
||||
"*/wpt-import/images/*"sv,
|
||||
};
|
||||
bool is_support_file = any_of(support_file_patterns, [&](auto pattern) { return test.input_path.matches(pattern); });
|
||||
bool match_glob = any_of(app.test_globs, [&](auto const& glob) { return test.relative_path.matches(glob, CaseSensitivity::CaseSensitive); });
|
||||
auto normalize_path = [](ByteString const& path) { return path.replace("\\"sv, "/"sv); };
|
||||
auto const test_input_path = normalize_path(test.input_path);
|
||||
auto const test_relative_path = normalize_path(test.relative_path);
|
||||
bool is_support_file = any_of(support_file_patterns, [&](auto pattern) { return test_input_path.matches(pattern); });
|
||||
bool match_glob = any_of(app.test_globs, [&](auto const& glob) { return test_relative_path.matches(glob, CaseSensitivity::CaseSensitive); });
|
||||
return is_support_file || !match_glob;
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue