aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dev-fkeys--f6-buffer-is-test-file-p.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-03 17:20:54 -0500
committerCraig Jennings <c@cjennings.net>2026-05-03 17:20:54 -0500
commit1d9d252e8b9e1385337cd0af087a7007f8e62da8 (patch)
tree4c774bbed6db0b0167e0235a39d5aeaab021ce9c /tests/test-dev-fkeys--f6-buffer-is-test-file-p.el
parent2c94acd52cc92dc4ebefd999dbca771367cc3090 (diff)
downloaddotemacs-1d9d252e8b9e1385337cd0af087a7007f8e62da8.tar.gz
dotemacs-1d9d252e8b9e1385337cd0af087a7007f8e62da8.zip
feat(dev-fkeys): add F6 test runner menu (Phase 2a)
I extended `dev-fkeys.el` with the F6 dispatcher half of the spec. F6 prompts via `completing-read` between two candidates: "All tests" delegates to `projectile-test-project`, and "Current file's tests" detects the buffer's language by extension, derives the runner command, and pipes through `compile' from the projectile root. C-F6 is the fast path straight to "Current file's tests". Per-language coverage: - Elisp source files map to `make test-name TEST=^test-<stem>-`. Elisp test files run with `make test-file FILE=<rel-path>` so a per-helper file like `test-foo--bar.el' runs only its own tests. - Python source files map to `pytest tests/test_<stem>.py'. Python test files run with `pytest <rel-path>'. - Go runs the package containing the file: `go test ./<rel-dir>'. Source and test files use the same command since Go test scope is per-package. Limit: this runs every `_test.go' in the package, not just the buffer's file. Phase 2b can refine via test-name discovery. - TypeScript and JavaScript are detected but punted for v1. The runner-command builder returns nil and the orchestrator signals a user-error rather than guessing. The F6 binding moved from the Phase 1 stopgap (`projectile-test-project') to `cj/f6-test-runner'. C-F6 is newly bound to `cj/f6-current-file-tests'. M-F6 stays unbound, reserved for Phase 2b's "Run a test..." menu entry. TDD: 68 new tests across 7 files. Production code split into small testable internals (`cj/--f6-language-detect', `cj/--f6-buffer-is-test-file-p', `cj/--f6-source-stem', `cj/--f6-test-runner-cmd-for', `cj/--f6-current-file-tests-impl') plus two thin interactive wrappers. Smoke tests confirm bindings register on load. I also updated the module commentary with the Phase 2b plan, the capture-then-filter approach for tree-sitter discovery, and a pointer to Emacs bug #79687. The bug is the predicate-syntax mismatch that breaks `:match' / `:equal' / `:pred' queries on Emacs 30.2 with libtree-sitter 0.26. The fix lives on Emacs master (commit b0143530), targets Emacs 31, and has not been backported to the emacs-30 branch as of today. Phase 2b will use queries without predicates and filter results in Elisp, sidestepping the issue. Mike Olson's `treesit-predicate-rewrite.el' applies the same idea to font-lock if you want it before Phase 2b lands.
Diffstat (limited to 'tests/test-dev-fkeys--f6-buffer-is-test-file-p.el')
-rw-r--r--tests/test-dev-fkeys--f6-buffer-is-test-file-p.el108
1 files changed, 108 insertions, 0 deletions
diff --git a/tests/test-dev-fkeys--f6-buffer-is-test-file-p.el b/tests/test-dev-fkeys--f6-buffer-is-test-file-p.el
new file mode 100644
index 00000000..b2ed95b9
--- /dev/null
+++ b/tests/test-dev-fkeys--f6-buffer-is-test-file-p.el
@@ -0,0 +1,108 @@
+;;; test-dev-fkeys--f6-buffer-is-test-file-p.el --- Tests for cj/--f6-buffer-is-test-file-p -*- lexical-binding: t -*-
+
+;;; Commentary:
+;; Tests for the test-file detector. Naming heuristics per language:
+;;
+;; elisp: basename starts with "test-"
+;; python: basename starts with "test_" OR ends with "_test.py"
+;; go: basename ends with "_test.go"
+;; ts/js: basename contains ".test." or ".spec."
+;;
+;; Anything else (including unsupported languages) returns nil.
+
+;;; Code:
+
+(require 'ert)
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'dev-fkeys)
+
+;;; Normal Cases — Elisp
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-elisp-test ()
+ "Normal: an elisp file with `test-` prefix is a test file."
+ (should (cj/--f6-buffer-is-test-file-p "tests/test-foo.el")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-elisp-source ()
+ "Normal: an elisp file without `test-` prefix is not a test file."
+ (should-not (cj/--f6-buffer-is-test-file-p "modules/foo.el")))
+
+;;; Normal Cases — Python
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-python-prefix ()
+ "Normal: a Python file with `test_` prefix is a test file."
+ (should (cj/--f6-buffer-is-test-file-p "tests/test_foo.py")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-python-suffix ()
+ "Normal: a Python file with `_test.py` suffix is a test file."
+ (should (cj/--f6-buffer-is-test-file-p "pkg/foo_test.py")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-python-source ()
+ "Normal: a Python file with neither prefix nor suffix is not a test file."
+ (should-not (cj/--f6-buffer-is-test-file-p "pkg/foo.py")))
+
+;;; Normal Cases — Go
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-go-test ()
+ "Normal: a Go file with `_test.go` suffix is a test file."
+ (should (cj/--f6-buffer-is-test-file-p "pkg/foo_test.go")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-go-source ()
+ "Normal: a Go file without `_test` suffix is not a test file."
+ (should-not (cj/--f6-buffer-is-test-file-p "pkg/foo.go")))
+
+;;; Normal Cases — TS / JS
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-typescript-test ()
+ "Normal: a .ts file with `.test.` infix is a test file."
+ (should (cj/--f6-buffer-is-test-file-p "src/foo.test.ts")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-typescript-spec ()
+ "Normal: a .ts file with `.spec.` infix is a test file."
+ (should (cj/--f6-buffer-is-test-file-p "src/foo.spec.ts")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-javascript-test ()
+ "Normal: a .js file with `.test.` infix is a test file."
+ (should (cj/--f6-buffer-is-test-file-p "src/foo.test.js")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-typescript-source ()
+ "Normal: a .ts file with no test/spec marker is not a test file."
+ (should-not (cj/--f6-buffer-is-test-file-p "src/foo.ts")))
+
+;;; Boundary Cases
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-double-dash-elisp ()
+ "Boundary: `test-foo--bar.el' (project's per-helper convention) is a test file."
+ (should (cj/--f6-buffer-is-test-file-p "tests/test-foo--bar.el")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-test-in-name-elisp ()
+ "Boundary: a non-test elisp file that just happens to contain `test` somewhere
+in the basename is not a test file (must start with `test-`)."
+ (should-not (cj/--f6-buffer-is-test-file-p "modules/contest.el")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-just-test-py ()
+ "Boundary: `test.py' alone is not a test file (no underscore separator)."
+ (should-not (cj/--f6-buffer-is-test-file-p "test.py")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-go-suffix-only ()
+ "Boundary: only `_test.go' suffix counts; `test_foo.go' does not (Go
+convention is suffix, not prefix)."
+ (should-not (cj/--f6-buffer-is-test-file-p "pkg/test_foo.go")))
+
+;;; Error Cases
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-nil ()
+ "Error: nil filename returns nil without erroring."
+ (should-not (cj/--f6-buffer-is-test-file-p nil)))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-empty ()
+ "Error: empty string returns nil."
+ (should-not (cj/--f6-buffer-is-test-file-p "")))
+
+(ert-deftest test-dev-fkeys-f6-buffer-is-test-file-p-unsupported-language ()
+ "Error: a file in an unsupported language returns nil even if the basename
+matches a generic pattern."
+ (should-not (cj/--f6-buffer-is-test-file-p "test-foo.rs"))
+ (should-not (cj/--f6-buffer-is-test-file-p "foo_test.rb")))
+
+(provide 'test-dev-fkeys--f6-buffer-is-test-file-p)
+;;; test-dev-fkeys--f6-buffer-is-test-file-p.el ends here