headless-browser: Improve error on failure to open expectation file

Mostly to output the path of the file which failed to open. This is
mostly helpful if you create a test, but forget to 'touch' the
expectation path.
This commit is contained in:
Shannon Booth 2023-07-31 20:01:37 +12:00 committed by Andreas Kling
parent 590f0f85e0
commit 25153703c9

View file

@ -240,7 +240,14 @@ static ErrorOr<TestResult> run_test(HeadlessWebContentView& view, StringView inp
if (result.is_error())
return result.release_error();
auto expectation_file = TRY(Core::File::open(expectation_path, Core::File::OpenMode::Read));
auto expectation_file_or_error = Core::File::open(expectation_path, Core::File::OpenMode::Read);
if (expectation_file_or_error.is_error()) {
warnln("Failed opening '{}': {}", expectation_path, expectation_file_or_error.error());
return expectation_file_or_error.release_error();
}
auto expectation_file = expectation_file_or_error.release_value();
auto expectation = TRY(String::from_utf8(StringView(TRY(expectation_file->read_until_eof()).bytes())));
auto actual = result.release_value();