From cb1d42de518514b3d3ee07e85c36e26e7570916e Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Fri, 10 Jul 2026 00:53:13 -0500 Subject: fix(test-runner): reject a sibling dir that shares the test dir's prefix cj/test--do-focus-add-file tested containment with a bare string-prefix-p on two truenames, so tests-old/foo.el passed as being inside tests/ and joined the focus list. The correct helper was already there. cj/test--file-in-directory-p wraps the directory in file-name-as-directory first, and the other two call sites already used it. This one didn't. The helper even had a sibling-rejection test. It was proven correct while the call site two hundred lines away never called it, which is why the new test drives the real focus-add path with a tests-old/ directory on disk rather than testing the helper again. --- tests/test-test-runner.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/test-test-runner.el b/tests/test-test-runner.el index 0ff66f7f..6854b72e 100644 --- a/tests/test-test-runner.el +++ b/tests/test-test-runner.el @@ -152,6 +152,25 @@ FILES is an alist of relative test filenames to file contents." (should (eq (car result) 'not-in-testdir))) (test-testrunner-teardown)) +(ert-deftest test-testrunner-focus-add-file-shared-prefix-sibling-rejected () + "Boundary: a sibling directory sharing the test dir's name prefix is outside it. +`/tmp/x/tests-old/f.el' starts with `/tmp/x/tests' as a string, but it is not +in `/tmp/x/tests'. A raw `string-prefix-p' on the two truenames accepts it; +comparing against the directory with a trailing slash rejects it." + (test-testrunner-setup) + (let* ((testdir (file-truename test-testrunner--temp-dir)) + (sibling (concat (directory-file-name testdir) "-old")) + (filepath (expand-file-name "test-foo.el" sibling))) + (unwind-protect + (progn + (make-directory sibling t) + (with-temp-file filepath (insert ";; not in the test dir\n")) + (let ((result (cj/test--do-focus-add-file + filepath test-testrunner--temp-dir '()))) + (should (eq (car result) 'not-in-testdir)))) + (when (file-directory-p sibling) (delete-directory sibling t)))) + (test-testrunner-teardown)) + (ert-deftest test-testrunner-focus-add-file-already-focused () "Should detect already focused file." (test-testrunner-setup) -- cgit v1.2.3