diff --git a/tanco/driver.py b/tanco/driver.py index c17c145..5cfa475 100644 --- a/tanco/driver.py +++ b/tanco/driver.py @@ -465,6 +465,19 @@ 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 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: @@ -531,8 +544,21 @@ 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 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 + 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..c3abed0 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,21 @@ 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 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: