Lines Matching +full:test +full:- +full:path

6 # This source code is licensed under both the BSD-style license (found in the
9 # You may select, at your option, one of the above-listed licenses.
67 def exclude_dir(dirname: str) -> bool:
69 Should files under the directory :dirname: be excluded from the test runner?
76 def exclude_file(filename: str) -> bool:
77 """Should the file :filename: be excluded from the test runner?"""
85 def read_file(filename: str) -> bytes:
91 def diff(a: bytes, b: bytes) -> str:
92 """Returns a diff between two different byte-strings :a: and :b:."""
105 def pop_line(data: bytes) -> typing.Tuple[typing.Optional[bytes], bytes]:
125 def glob_line_matches(actual: bytes, expect: bytes) -> bool:
132 def glob_diff(actual: bytes, expect: bytes) -> bytes:
141 # Handle end of file conditions - allow extra newlines
152 diff += b"---\n"
159 diff += b"---\n"
178 diff += b"---\n"
186 diff += b'---\n'
205 ) -> None:
217 Logic and state related to running a single test case.
219 1. Initialize the test case.
220 2. Launch the test case with :TestCase.launch():.
221 This will start the test execution in a subprocess, but
222 not wait for completion. So you could launch multiple test
223 cases in parallel. This will now print any test output.
225 join the test subprocess, check the results against the
229 steps for single-threaded use-cases.
233 def __init__(self, test_filename: str, options: Options) -> None:
235 Initialize the :TestCase: for the test located in :test_filename:
240 self._test_name = os.path.normpath(
241 os.path.relpath(test_filename, start=self._opts.test_dir)
246 self._scratch_dir = os.path.abspath(os.path.join(self._opts.scratch_dir, self._test_name))
249 def name(self) -> str:
250 """Returns the unique name for the test."""
253 def launch(self) -> None:
255 Launch the test case as a subprocess, but do not block on completion.
261 def analyze(self) -> bool:
263 Must be called after :TestCase.launch():. Joins the test subprocess and
274 def run(self) -> bool:
279 def _log(self, *args, **kwargs) -> None:
280 """Logs test output."""
283 def _vlog(self, *args, **kwargs) -> None:
284 """Logs verbose test output."""
288 def _test_environment(self) -> typing.Dict[str, str]:
291 test subprocess.
300 def _launch_test(self) -> None:
301 """Launch the test subprocess, but do not join it."""
302 args = [os.path.abspath(self._test_file)]
304 if os.path.exists(stdin_name):
320 def _join_test(self) -> None:
321 """Join the test process and save stderr, stdout, and the exit code."""
332 def _check_output_exact(self, out_name: str, expected: bytes, exact_name: str) -> None:
350 def _check_output_glob(self, out_name: str, expected: bytes) -> None:
366 def _check_output(self, out_name: str) -> None:
378 actual_name = os.path.join(self._scratch_dir, f"{out_name}")
386 if os.path.exists(exact_name):
388 elif os.path.exists(glob_name):
395 def _check_stderr(self) -> None:
399 def _check_stdout(self) -> None:
403 def _check_exit(self) -> None:
413 exit_name = os.path.join(self._scratch_dir, "exit")
417 if os.path.exists(exit_name):
428 def _analyze_results(self) -> None:
444 self._log("----------------------------------------")
449 Setup & teardown test suite & cases.
454 def __init__(self, test_directory: str, options: Options) -> None:
456 self._test_dir = os.path.abspath(test_directory)
457 rel_test_dir = os.path.relpath(test_directory, start=self._opts.test_dir)
458 assert not rel_test_dir.startswith(os.path.sep)
459 self._scratch_dir = os.path.normpath(os.path.join(self._opts.scratch_dir, rel_test_dir))
461 def __enter__(self) -> 'TestSuite':
465 def __exit__(self, _exc_type, _exc_value, _traceback) -> None:
469 def test_case(self, test_basename: str) -> TestCase:
471 Context manager for a test case in the test suite.
472 Pass the basename of the test relative to the :test_directory:.
474 assert os.path.dirname(test_basename) == ""
477 test_filename = os.path.join(self._test_dir, test_basename)
482 def _remove_scratch_dir(self, dir: str) -> None:
486 assert os.path.exists(dir)
489 def _setup_once(self) -> None:
490 if os.path.exists(self._scratch_dir):
493 setup_script = os.path.join(self._test_dir, "setup_once")
494 if os.path.exists(setup_script):
497 def _teardown_once(self) -> None:
498 assert os.path.exists(self._scratch_dir)
499 teardown_script = os.path.join(self._test_dir, "teardown_once")
500 if os.path.exists(teardown_script):
505 def _setup(self, test_basename: str) -> None:
506 test_scratch_dir = os.path.join(self._scratch_dir, test_basename)
507 assert not os.path.exists(test_scratch_dir)
509 setup_script = os.path.join(self._test_dir, "setup")
510 if os.path.exists(setup_script):
513 def _teardown(self, test_basename: str) -> None:
514 test_scratch_dir = os.path.join(self._scratch_dir, test_basename)
515 assert os.path.exists(test_scratch_dir)
516 teardown_script = os.path.join(self._test_dir, "teardown")
517 if os.path.exists(teardown_script):
522 def _run_script(self, script: str, cwd: str) -> None:
544 def get_all_tests(options: Options) -> TestSuites:
546 Find all the test in the test directory and return the test suites.
555 assert root == os.path.normpath(root)
562 ) -> TestSuites:
565 respective test suites. Tests can either be paths, or test names
566 relative to the test directory.
569 for test in tests:
570 if not os.path.exists(test):
571 test = os.path.join(options.test_dir, test)
572 if not os.path.exists(test):
573 raise RuntimeError(f"Test {test} does not exist!")
575 test = os.path.normpath(os.path.abspath(test))
576 assert test.startswith(options.test_dir)
577 test_suite = os.path.dirname(test)
578 test_case = os.path.basename(test)
583 def run_tests(test_suites: TestSuites, options: Options) -> bool:
585 Runs all the test in the :test_suites: with the given :options:.
597 for test, status in tests.items():
601 print(f"FAIL: {test}")
606 print(f"FAILED {len(tests) - successes} / {len(tests)} tests!")
610 def setup_zstd_symlink_dir(zstd_symlink_dir: str, zstd: str) -> None:
611 assert os.path.join("bin", "symlinks") in zstd_symlink_dir
612 if not os.path.exists(zstd_symlink_dir):
615 path = os.path.join(zstd_symlink_dir, symlink)
616 if os.path.exists(path):
617 os.remove(path)
618 os.symlink(zstd, path)
621 CLI_TEST_DIR = os.path.dirname(sys.argv[0])
622 REPO_DIR = os.path.join(CLI_TEST_DIR, "..", "..")
623 PROGRAMS_DIR = os.path.join(REPO_DIR, "programs")
624 TESTS_DIR = os.path.join(REPO_DIR, "tests")
625 ZSTD_PATH = os.path.join(PROGRAMS_DIR, "zstd")
626 ZSTDGREP_PATH = os.path.join(PROGRAMS_DIR, "zstdgrep")
627 ZSTDLESS_PATH = os.path.join(PROGRAMS_DIR, "zstdless")
628 DATAGEN_PATH = os.path.join(TESTS_DIR, "datagen")
633 "generally correct. Pass --preserve to preserve test output for debugging,\n"
634 "and --verbose to get verbose test output.\n"
638 "--preserve",
642 parser.add_argument("--verbose", action="store_true", help="Verbose test output.")
643 …parser.add_argument("--timeout", default=200, type=int, help="Test case timeout in seconds. Set to…
645 "--exec-prefix",
650 "--zstd",
652 help="Sets the ZSTD_BIN environment variable. Path of the zstd CLI."
655 "--zstdgrep",
657 help="Sets the ZSTDGREP_BIN environment variable. Path of the zstdgrep CLI."
660 "--zstdless",
662 help="Sets the ZSTDLESS_BIN environment variable. Path of the zstdless CLI."
665 "--datagen",
667 help="Sets the DATAGEN_BIN environment variable. Path to the datagen CLI."
670 "--test-dir",
674 "Adds TEST_DIR/bin/ to path. "
679 "--set-exact-output",
686 help="Run only these test cases. Can either be paths or test names relative to TEST_DIR/"
693 args.test_dir = os.path.normpath(os.path.abspath(args.test_dir))
694 bin_dir = os.path.abspath(os.path.join(args.test_dir, "bin"))
695 zstd_symlink_dir = os.path.join(bin_dir, "symlinks")
696 scratch_dir = os.path.join(args.test_dir, "scratch")
698 setup_zstd_symlink_dir(zstd_symlink_dir, os.path.abspath(args.zstd))
704 env["ZSTD_REPO_DIR"] = os.path.abspath(REPO_DIR)
705 env["DATAGEN_BIN"] = os.path.abspath(args.datagen)
706 env["ZSTDGREP_BIN"] = os.path.abspath(args.zstdgrep)
707 env["ZSTDLESS_BIN"] = os.path.abspath(args.zstdless)
708 env["COMMON"] = os.path.abspath(os.path.join(args.test_dir, "common"))
709 env["PATH"] = bin_dir + ":" + os.getenv("PATH", "")