From 1d9d252e8b9e1385337cd0af087a7007f8e62da8 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 3 May 2026 17:20:54 -0500 Subject: 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--`. Elisp test files run with `make test-file FILE=` so a per-helper file like `test-foo--bar.el' runs only its own tests. - Python source files map to `pytest tests/test_.py'. Python test files run with `pytest '. - Go runs the package containing the file: `go test ./'. 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. --- tests/test-dev-fkeys--f6-source-stem.el | 84 +++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 tests/test-dev-fkeys--f6-source-stem.el (limited to 'tests/test-dev-fkeys--f6-source-stem.el') diff --git a/tests/test-dev-fkeys--f6-source-stem.el b/tests/test-dev-fkeys--f6-source-stem.el new file mode 100644 index 00000000..bdf85b5f --- /dev/null +++ b/tests/test-dev-fkeys--f6-source-stem.el @@ -0,0 +1,84 @@ +;;; test-dev-fkeys--f6-source-stem.el --- Tests for cj/--f6-source-stem -*- lexical-binding: t -*- + +;;; Commentary: +;; Tests for the stem extractor. Given any source-or-test filename, returns +;; the source module name with directory, extension, and any test-pattern +;; prefix/suffix stripped. Used to map source files to their tests and +;; vice versa. + +;;; 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-source-stem-elisp-source () + "Normal: a regular elisp source file's stem is its basename." + (should (string= (cj/--f6-source-stem "modules/foo.el") "foo"))) + +(ert-deftest test-dev-fkeys-f6-source-stem-elisp-test () + "Normal: an elisp test file's stem strips the `test-' prefix." + (should (string= (cj/--f6-source-stem "tests/test-foo.el") "foo"))) + +(ert-deftest test-dev-fkeys-f6-source-stem-elisp-test-double-dash () + "Normal: an elisp per-helper test file `test---.el' yields +the module name (everything from `--' onward is dropped)." + (should (string= (cj/--f6-source-stem "tests/test-dev-fkeys--detect-project-type.el") + "dev-fkeys"))) + +;;; Normal Cases — Python + +(ert-deftest test-dev-fkeys-f6-source-stem-python-source () + "Normal: a regular Python source file's stem is its basename." + (should (string= (cj/--f6-source-stem "pkg/foo.py") "foo"))) + +(ert-deftest test-dev-fkeys-f6-source-stem-python-test-prefix () + "Normal: a `test_.py' file's stem strips the `test_' prefix." + (should (string= (cj/--f6-source-stem "tests/test_foo.py") "foo"))) + +(ert-deftest test-dev-fkeys-f6-source-stem-python-test-suffix () + "Normal: a `_test.py' file's stem strips the `_test' suffix." + (should (string= (cj/--f6-source-stem "pkg/foo_test.py") "foo"))) + +;;; Normal Cases — Go + +(ert-deftest test-dev-fkeys-f6-source-stem-go-source () + "Normal: a regular Go source file's stem is its basename." + (should (string= (cj/--f6-source-stem "pkg/foo.go") "foo"))) + +(ert-deftest test-dev-fkeys-f6-source-stem-go-test () + "Normal: a `_test.go' file's stem strips the `_test' suffix." + (should (string= (cj/--f6-source-stem "pkg/foo_test.go") "foo"))) + +;;; Boundary Cases + +(ert-deftest test-dev-fkeys-f6-source-stem-elisp-multi-segment-name () + "Boundary: hyphenated module names round-trip cleanly." + (should (string= (cj/--f6-source-stem "modules/calendar-sync.el") "calendar-sync")) + (should (string= (cj/--f6-source-stem "tests/test-calendar-sync.el") "calendar-sync"))) + +(ert-deftest test-dev-fkeys-f6-source-stem-elisp-test-with-dashes-after-double-dash () + "Boundary: a per-helper test file with hyphens in both module and helper: +`test-foo-bar--baz-qux.el' → `foo-bar' (stops at first `--')." + (should (string= (cj/--f6-source-stem "tests/test-foo-bar--baz-qux.el") + "foo-bar"))) + +(ert-deftest test-dev-fkeys-f6-source-stem-unknown-language-falls-back-to-basename () + "Boundary: an unsupported extension just returns the basename without extension." + (should (string= (cj/--f6-source-stem "foo.rs") "foo")) + (should (string= (cj/--f6-source-stem "foo.txt") "foo"))) + +;;; Error Cases + +(ert-deftest test-dev-fkeys-f6-source-stem-nil-returns-nil () + "Error: nil filename returns nil without erroring." + (should (null (cj/--f6-source-stem nil)))) + +(ert-deftest test-dev-fkeys-f6-source-stem-empty-returns-nil () + "Error: empty string returns nil." + (should (null (cj/--f6-source-stem "")))) + +(provide 'test-dev-fkeys--f6-source-stem) +;;; test-dev-fkeys--f6-source-stem.el ends here -- cgit v1.2.3