From 4bdd4beb936949ee9b666b433389e46ffb35214e Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 9 Apr 2024 17:24:00 -0600 Subject: [PATCH] Tests/LibWeb: Add a script to create a new test, starting with Text --- Tests/LibWeb/add_libweb_test.py | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 Tests/LibWeb/add_libweb_test.py diff --git a/Tests/LibWeb/add_libweb_test.py b/Tests/LibWeb/add_libweb_test.py new file mode 100755 index 0000000000..3a25d435d3 --- /dev/null +++ b/Tests/LibWeb/add_libweb_test.py @@ -0,0 +1,61 @@ +#!/usr/bin/env python3 +""" +This script will create a new test file and expectations in the Tests/LibWeb directory +""" + +import argparse +from pathlib import Path + +TEST_DIR = Path(__file__).resolve().parent + + +def create_text_test(test_name: str, is_async: bool = False) -> None: + """ + Create a new Text type test file with the given test name. + + Args: + test_name (str): Name of the test. + is_async (bool, optional): Whether it is an async test. Defaults to False. + """ + input_prefix = TEST_DIR / "Text" / "input" / test_name + input_dir = input_prefix.parent + input_file = input_prefix.with_suffix(".html") + + expected_prefix = TEST_DIR / "Text" / "expected" / test_name + expected_dir = expected_prefix.parent + expected_file = expected_prefix.with_suffix(".txt") + + # Create directories if they don't exist + input_dir.mkdir(parents=True, exist_ok=True) + expected_dir.mkdir(parents=True, exist_ok=True) + + num_sub_levels = len(Path(test_name).parents) - 1 + path_to_include_js = "../" * num_sub_levels + "include.js" + + # Create input and expected files + input_file.write_text(fR""" + + +""") + expected_file.write_text("Expected println() output\n") + + print(f"Text test '{Path(test_name).with_suffix('.html')}' created successfully.") + + +def main(): + parser = argparse.ArgumentParser(description="Create a new LibWeb Text test file.") + parser.add_argument("test_name", type=str, help="Name of the test") + parser.add_argument("--async", action="store_true", help="Flag to indicate if it's an async test", dest="is_async") + args = parser.parse_args() + + # TODO: Add support for other test types: Layout and Ref + create_text_test(args.test_name, args.is_async) + + +if __name__ == "__main__": + main()