From a7563a58c2b23ac3aa6fe7e3c7dd58d7317b9148 Mon Sep 17 00:00:00 2001 From: MasloMaslane Date: Sun, 20 Jul 2025 12:33:54 +0200 Subject: [PATCH] Enhance static file handling and add globbing support in tests --- example_package/config.yml | 3 ++- src/sinol_make/commands/ingen/__init__.py | 7 +++++-- tests/commands/gen/test_integration.py | 11 +++++++++++ tests/packages/gen/prog/geningen7.cpp | 9 +++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 tests/packages/gen/prog/geningen7.cpp diff --git a/example_package/config.yml b/example_package/config.yml index e4dd6ae0..ea494e0d 100644 --- a/example_package/config.yml +++ b/example_package/config.yml @@ -81,7 +81,8 @@ sinol_contest_type: oi sinol_latex_compiler: auto # You can specify which tests are static (handwritten). This allows sinol-make to differentiate between -# old and handwritten tests. If this key is not present old tests won't be removed. +# old and handwritten tests. If this key is not present old tests won't be removed. The values can be +# either a list of test names (e.g. `["__ID__0.in", "__ID__1.in"]`) or a glob pattern (e.g. `"__ID__*.in"`). # This key is optional and should be a list of tests. sinol_static_tests: ["__ID__0.in", "__ID__0a.in"] diff --git a/src/sinol_make/commands/ingen/__init__.py b/src/sinol_make/commands/ingen/__init__.py index 6f45acaa..1c1041cc 100644 --- a/src/sinol_make/commands/ingen/__init__.py +++ b/src/sinol_make/commands/ingen/__init__.py @@ -51,8 +51,11 @@ def delete_dangling_files(self, dates): static_files = config['sinol_static_tests'] if isinstance(static_files, str): static_files = [static_files] - static_files = set([os.path.basename(test) for test in static_files]) - to_delete = to_delete - static_files + found_static_files = set() + for static in static_files: + files = [os.path.basename(f) for f in glob.glob(os.path.join(os.getcwd(), "in", static))] + found_static_files.update(files) + to_delete = to_delete - found_static_files if to_delete: print('Cleaning up old input files.') for test in to_delete: diff --git a/tests/commands/gen/test_integration.py b/tests/commands/gen/test_integration.py index bc47eb1b..285fcaca 100644 --- a/tests/commands/gen/test_integration.py +++ b/tests/commands/gen/test_integration.py @@ -332,6 +332,17 @@ def test_dangling_inputs(create_package, capsys): for f in ["gen1.in", "gen2.in"]: assert os.path.exists(os.path.join(create_package, "in", f)) + # Test if globbing works correctly + config = package_util.get_config() + config["sinol_static_tests"] = ["gen?.in"] + sm_util.save_config(config) + simple_run(["prog/geningen5.cpp"], command="ingen") + for f in ["gen1.in", "gen2.in"]: + assert os.path.exists(os.path.join(create_package, "in", f)) + simple_run(["prog/geningen7.cpp"], command="ingen") + for f in ["gen1.in", "gen2.in"]: + assert os.path.exists(os.path.join(create_package, "in", f)) + @pytest.mark.parametrize("create_package", [util.get_simple_package_path()], indirect=True) def test_outgen_cache_cleaning(create_package, capsys): diff --git a/tests/packages/gen/prog/geningen7.cpp b/tests/packages/gen/prog/geningen7.cpp new file mode 100644 index 00000000..44c2fb26 --- /dev/null +++ b/tests/packages/gen/prog/geningen7.cpp @@ -0,0 +1,9 @@ +#include + +using namespace std; + +int main() { + ofstream f("gen3.in"); + f << "2 3\n"; + f.close(); +}