From ac2ae9dc7f439574dd12260e7fc63cc5f9938a97 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 7 Dec 2025 19:45:46 +0000 Subject: [PATCH 1/2] fix: add error handling for missing tests (#7) Add NoTestsFoundError exception that is raised when a test source (org file or database) exists but contains no valid test definitions. Previously this would silently print "All 0 tests passed." which was misleading. Now provides a clear error message with the source that was checked and guidance on how to define tests. --- tanco/driver.py | 20 +++++++++++++++++++- tanco/runner.py | 23 ++++++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/tanco/driver.py b/tanco/driver.py index c17c145..e67e04a 100644 --- a/tanco/driver.py +++ b/tanco/driver.py @@ -465,6 +465,15 @@ def do_test(arg): except runner.NoTestPlanError: runner.error(cfg, ['No challenge selected.', 'Use `tanco init`, `tanco test -t file.org`, or set TEST_PLAN environment variable.']) + except runner.NoTestsFoundError as e: + runner.error(cfg, [str(e), + '', + 'For org files, tests should be defined using:', + ' ** TEST testname : title', + ' #+begin_src', + ' > input line', + ' expected output', + ' #+end_src']) except runner.StopTesting: pass except Exception: @@ -531,8 +540,17 @@ def do_run(self, arg): runner.run_tests(cfg) except runner.NoTestPlanError: print("No tests specified. Use --tests PATH or ensure you're in a tanco project.") + except runner.NoTestsFoundError as e: + print(str(e)) + print() + print('For org files, tests should be defined using:') + print(' ** TEST testname : title') + print(' #+begin_src') + print(' > input line') + print(' expected output') + print(' #+end_src') except runner.StopTesting: - pass # Normal exit after test failure + pass # Normal exit after test failure except Exception: # handle_unexpected_error already prints traceback runner.handle_unexpected_error(cfg) diff --git a/tanco/runner.py b/tanco/runner.py index 914d510..de6f839 100644 --- a/tanco/runner.py +++ b/tanco/runner.py @@ -94,6 +94,10 @@ class NoTestPlanError(Exception): pass +class NoTestsFoundError(Exception): + """Raised when a test source exists but contains no tests.""" + + class StopTesting(Exception): pass @@ -354,6 +358,14 @@ def run_tests(cfg: Config, names=None): challenge = get_challenge(cfg) tests = challenge.tests + # Check for empty tests list + if not tests: + source = cfg.test_path or cfg.test_plan or 'database' + raise NoTestsFoundError( + f'No tests found in {source}. ' + 'Make sure the file contains valid test definitions.', + ) + # Use persistent process mode if restart_cmd is configured if cfg.restart_cmd and cfg.restart_expect: run_tests_persistent(cfg, tests, names) @@ -502,8 +514,17 @@ def main(names: list[str]): try: run_tests(cfg, names) except NoTestPlanError: - error(cfg, ['No challenge selected.' + error(cfg, ['No challenge selected.', 'Use `tanco init` or set TEST_PLAN environment variable.']) + except NoTestsFoundError as e: + error(cfg, [str(e), + '', + 'For org files, tests should be defined using:', + ' ** TEST testname : title', + ' #+begin_src', + ' > input line', + ' expected output', + ' #+end_src']) except StopTesting: pass except Exception: From cb204e888511882475c2295e866bc657b40d3f1d Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 7 Dec 2025 22:45:56 +0000 Subject: [PATCH 2/2] fix: add error handling for missing test files Handle FileNotFoundError when the specified test file doesn't exist, providing a clear error message instead of showing a traceback. --- tanco/driver.py | 8 ++++++++ tanco/runner.py | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/tanco/driver.py b/tanco/driver.py index e67e04a..5cfa475 100644 --- a/tanco/driver.py +++ b/tanco/driver.py @@ -474,6 +474,10 @@ def do_test(arg): ' > input line', ' expected output', ' #+end_src']) + except FileNotFoundError as e: + runner.error(cfg, [f'Test file not found: {e.filename}', + '', + 'Make sure the path is correct and the file exists.']) except runner.StopTesting: pass except Exception: @@ -549,6 +553,10 @@ def do_run(self, arg): print(' > input line') print(' expected output') print(' #+end_src') + except FileNotFoundError as e: + print(f'Test file not found: {e.filename}') + print() + print('Make sure the path is correct and the file exists.') except runner.StopTesting: pass # Normal exit after test failure except Exception: diff --git a/tanco/runner.py b/tanco/runner.py index de6f839..c3abed0 100644 --- a/tanco/runner.py +++ b/tanco/runner.py @@ -525,6 +525,10 @@ def main(names: list[str]): ' > input line', ' expected output', ' #+end_src']) + except FileNotFoundError as e: + error(cfg, [f'Test file not found: {e.filename}', + '', + 'Make sure the path is correct and the file exists.']) except StopTesting: pass except Exception: