diff --git a/mkconcore.py b/mkconcore.py index e901295..ccf985c 100644 --- a/mkconcore.py +++ b/mkconcore.py @@ -1389,7 +1389,8 @@ def cleanup_script_files(): else: # FIX: Safer wildcard removal. # Avoid quoting the wildcard itself ('path/*'). Instead cd into directory and remove contents. - fclear.write(f'cd {shlex.quote(path_part)} && rm -f *\n') + # The subshell keeps the cd from carrying over to the next edge's line. + fclear.write(f'(cd {shlex.quote(path_part)} && rm -f *)\n') writeedges = writeedges[writeedges.find(":")+1:] i=i+1 fclear.close() diff --git a/tests/test_cli.py b/tests/test_cli.py index 70441f6..5b64841 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,6 +2,7 @@ import tempfile import shutil import os +import subprocess import sys import json from pathlib import Path @@ -211,6 +212,49 @@ def test_build_command_rejects_edge_label_with_multiple_sources(self): self.assertNotEqual(result.exit_code, 0) self.assertIn("Edge label 'shared' has more than one source", result.output) + @unittest.skipIf(os.name == "nt", "runs the generated bash scripts") + def test_build_command_posix_clear_empties_every_edge(self): + with self.runner.isolated_filesystem(temp_dir=self.temp_dir): + Path("src").mkdir() + for name in ["a.py", "b.py"]: + Path("src", name).write_text("import concore\n") + Path("workflow.graphml").write_text( + '\n' + '\n' + 'A:a.py\n' + 'B:b.py\n' + 'y\n' + 'u\n' + 'u2\n' + "\n" + "\n" + ) + + result = self.runner.invoke( + cli, + [ + "build", + "workflow.graphml", + "--source", + "src", + "--output", + "out", + "--type", + "posix", + ], + ) + self.assertEqual(result.exit_code, 0) + + out = Path("out") + subprocess.run(["./build"], cwd=out, check=True, capture_output=True) + for edge in ["y", "u", "u2"]: + (out / edge / "data").write_text("[0, 1.0]") + + cleared = subprocess.run(["./clear"], cwd=out, capture_output=True) + self.assertEqual(cleared.returncode, 0, cleared.stderr) + for edge in ["y", "u", "u2"]: + self.assertEqual(list((out / edge).iterdir()), [], edge) + def test_build_command_from_project_dir(self): with self.runner.isolated_filesystem(temp_dir=self.temp_dir): result = self.runner.invoke(cli, ["init", "test-project"])