"""Which files PHPUnit and `node --test` find as tests by their names, beyond the ones `mutate_changes.changed_lines.is_test` tells. `is_test` stays as it is: changing it would change what `mutate-changes` skips.""" import posixpath import re from mutate_changes.changed_lines import is_test, STRYKER # PHPUnit's default suffix, wherever the file stands; node --test's `*-test`, `*_test`, `test-*` and `test` stems, in each suffix # Stryker covers. node --test's `*.test.*` is `is_test`'s already. FRAMEWORK_NAME = re.compile(rf".*Test\.php|(?:.*[-_]test|test|test-.*)(?:{'|'.join(re.escape(suffix) for suffix in STRYKER)})") def is_test_file(path: str) -> bool: """Whether path is a test by its name or folder alone, as `is_test` or PHPUnit or `node --test` tells it.""" return is_test(path) or bool(FRAMEWORK_NAME.fullmatch(posixpath.basename(path)))