Skip to content

Commit a7563a5

Browse files
committed
Enhance static file handling and add globbing support in tests
1 parent 421e527 commit a7563a5

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

example_package/config.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ sinol_contest_type: oi
8181
sinol_latex_compiler: auto
8282

8383
# You can specify which tests are static (handwritten). This allows sinol-make to differentiate between
84-
# old and handwritten tests. If this key is not present old tests won't be removed.
84+
# old and handwritten tests. If this key is not present old tests won't be removed. The values can be
85+
# either a list of test names (e.g. `["__ID__0.in", "__ID__1.in"]`) or a glob pattern (e.g. `"__ID__*.in"`).
8586
# This key is optional and should be a list of tests.
8687
sinol_static_tests: ["__ID__0.in", "__ID__0a.in"]
8788

src/sinol_make/commands/ingen/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,11 @@ def delete_dangling_files(self, dates):
5151
static_files = config['sinol_static_tests']
5252
if isinstance(static_files, str):
5353
static_files = [static_files]
54-
static_files = set([os.path.basename(test) for test in static_files])
55-
to_delete = to_delete - static_files
54+
found_static_files = set()
55+
for static in static_files:
56+
files = [os.path.basename(f) for f in glob.glob(os.path.join(os.getcwd(), "in", static))]
57+
found_static_files.update(files)
58+
to_delete = to_delete - found_static_files
5659
if to_delete:
5760
print('Cleaning up old input files.')
5861
for test in to_delete:

tests/commands/gen/test_integration.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,17 @@ def test_dangling_inputs(create_package, capsys):
332332
for f in ["gen1.in", "gen2.in"]:
333333
assert os.path.exists(os.path.join(create_package, "in", f))
334334

335+
# Test if globbing works correctly
336+
config = package_util.get_config()
337+
config["sinol_static_tests"] = ["gen?.in"]
338+
sm_util.save_config(config)
339+
simple_run(["prog/geningen5.cpp"], command="ingen")
340+
for f in ["gen1.in", "gen2.in"]:
341+
assert os.path.exists(os.path.join(create_package, "in", f))
342+
simple_run(["prog/geningen7.cpp"], command="ingen")
343+
for f in ["gen1.in", "gen2.in"]:
344+
assert os.path.exists(os.path.join(create_package, "in", f))
345+
335346

336347
@pytest.mark.parametrize("create_package", [util.get_simple_package_path()], indirect=True)
337348
def test_outgen_cache_cleaning(create_package, capsys):
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
int main() {
6+
ofstream f("gen3.in");
7+
f << "2 3\n";
8+
f.close();
9+
}

0 commit comments

Comments
 (0)