From 33de91cabfaed8b8211d009926a9a11f7d1c76fd Mon Sep 17 00:00:00 2001 From: Austin Appleby Date: Tue, 26 Mar 2024 01:42:56 -0700 Subject: [PATCH] checkpoint --- tests/garbage_command.hancho | 8 +++++++- tests/run_tests.py | 35 +++++++++++++++++++++++++++-------- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/tests/garbage_command.hancho b/tests/garbage_command.hancho index 791b43b..71683a5 100644 --- a/tests/garbage_command.hancho +++ b/tests/garbage_command.hancho @@ -1,4 +1,10 @@ from hancho import * -garbage_command = Rule(command = "aklsjdflksjdlfkjldfk") +build_config.defaults( + command_path = Path.cwd(), + source_path = Path.cwd(), + build_path = Path.cwd() / "build", +) + +garbage_command = build_config.rule(command = "aklsjdflksjdlfkjldfk") garbage_command(__file__, "result.txt") diff --git a/tests/run_tests.py b/tests/run_tests.py index 0288668..c5d0d10 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -49,7 +49,13 @@ def run(cmd): def run_hancho(name): """Runs a Hancho build script and returns a subprocess.CompletedProcess.""" - return subprocess.run(f"python3 ../hancho.py {name}.hancho", shell=True, text=True, capture_output=True) + return subprocess.run( + f"python3 ../hancho.py {name}.hancho", + shell=True, + text=True, + capture_output=True, + ) + ################################################################################ @@ -77,7 +83,10 @@ def test_should_pass(self): def test_should_fail(self): """Sanity check""" result = run_hancho("should_fail") - self.assertTrue("ValueError: Command '(exit 255)' exited with return code 255" in result.stderr) + self.assertTrue( + "ValueError: Command '(exit 255)' exited with return code 255" + in result.stderr + ) def test_check_output(self): """A build rule that doesn't update one of its outputs should fail""" @@ -102,7 +111,10 @@ def test_command_missing(self): def test_missing_field(self): """Missing fields should raise an error when expanded""" result = run_hancho("missing_field") - self.assertTrue("NameError: name 'this_field_does_not_exist' is not defined" in result.stderr) + self.assertTrue( + "NameError: name 'this_field_does_not_exist' is not defined" + in result.stderr + ) def test_missing_input(self): """We should fail if an input is missing""" @@ -119,12 +131,19 @@ def test_missing_dep(self): def test_expand_failed_to_terminate(self): """A recursive text template should cause an 'expand failed to terminate' error.""" result = run_hancho("expand_failed_to_terminate") - self.assertTrue("RecursionError: Expanding '{flarp}' failed to terminate" in result.stderr) + self.assertTrue( + "RecursionError: Expanding '{flarp}' failed to terminate" in result.stderr + ) + + def test_garbage_command(self): + """Non-existent command line commands should cause Hancho to fail the build.""" + result = run_hancho("garbage_command") + self.assertTrue( + "ValueError: Command 'aklsjdflksjdlfkjldfk' exited with return code 127" + in result.stderr + ) + -# def test_garbage_command(self): -# """Non-existent command line commands should cause Hancho to fail the build.""" -# self.assertNotEqual(0, run_hancho("garbage_command")) -# # def test_garbage_template(self): # """Templates that can't be eval()d should cause Hancho to fail the build.""" # self.assertNotEqual(0, run_hancho("garbage_template"))