aboutsummaryrefslogtreecommitdiff
path: root/tests/test-dev-fkeys--f6-current-file-tests-impl.el
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test-dev-fkeys--f6-current-file-tests-impl.el')
-rw-r--r--tests/test-dev-fkeys--f6-current-file-tests-impl.el125
1 files changed, 125 insertions, 0 deletions
diff --git a/tests/test-dev-fkeys--f6-current-file-tests-impl.el b/tests/test-dev-fkeys--f6-current-file-tests-impl.el
new file mode 100644
index 00000000..ecc7a4f4
--- /dev/null
+++ b/tests/test-dev-fkeys--f6-current-file-tests-impl.el
@@ -0,0 +1,125 @@
+;;; test-dev-fkeys--f6-current-file-tests-impl.el --- Tests for cj/--f6-current-file-tests-impl -*- lexical-binding: t -*-
+
+;;; Commentary:
+;; Tests for the "Current file's tests" orchestrator. Takes (FILE
+;; PROJECT-ROOT), composes the per-language test-runner command, and runs
+;; it through `compile' with `default-directory' bound to PROJECT-ROOT.
+;; Errors when no file, no project root, or no test runner is available
+;; for the file's language.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+(add-to-list 'load-path (expand-file-name "modules" user-emacs-directory))
+(require 'dev-fkeys)
+
+;;; Normal Cases
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-elisp-source ()
+ "Normal: an elisp source file runs `make test-name TEST=^test-<stem>-'.
+
+Components integrated:
+- `cj/--f6-current-file-tests-impl' (unit under test)
+- `cj/--f6-language-detect' (real)
+- `cj/--f6-source-stem' (real)
+- `cj/--f6-buffer-is-test-file-p' (real)
+- `cj/--f6-test-runner-cmd-for' (real)
+- `compile' (MOCKED — captures cmd and default-directory)"
+ (let (seen-cmd seen-dir)
+ (cl-letf (((symbol-function 'compile)
+ (lambda (cmd) (setq seen-cmd cmd
+ seen-dir default-directory))))
+ (cj/--f6-current-file-tests-impl
+ "/home/u/proj/modules/foo.el"
+ "/home/u/proj/")
+ (should (string= seen-cmd "make test-name TEST=^test-foo-"))
+ (should (string= (file-name-as-directory seen-dir)
+ (file-name-as-directory "/home/u/proj/"))))))
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-elisp-test-file ()
+ "Normal: an elisp test file runs `make test-file FILE=<rel-path>'."
+ (let (seen-cmd)
+ (cl-letf (((symbol-function 'compile)
+ (lambda (cmd) (setq seen-cmd cmd))))
+ (cj/--f6-current-file-tests-impl
+ "/home/u/proj/tests/test-foo.el"
+ "/home/u/proj/")
+ (should (string= seen-cmd "make test-file FILE=tests/test-foo.el")))))
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-python-source ()
+ "Normal: a Python source file maps to `pytest tests/test_<stem>.py'."
+ (let (seen-cmd)
+ (cl-letf (((symbol-function 'compile)
+ (lambda (cmd) (setq seen-cmd cmd))))
+ (cj/--f6-current-file-tests-impl
+ "/home/u/proj/pkg/foo.py"
+ "/home/u/proj/")
+ (should (string= seen-cmd "pytest tests/test_foo.py")))))
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-go-source ()
+ "Normal: a Go source file runs the package via `go test ./<rel-dir>'."
+ (let (seen-cmd)
+ (cl-letf (((symbol-function 'compile)
+ (lambda (cmd) (setq seen-cmd cmd))))
+ (cj/--f6-current-file-tests-impl
+ "/home/u/proj/pkg/foo.go"
+ "/home/u/proj/")
+ (should (string= seen-cmd "go test ./pkg")))))
+
+;;; Boundary Cases
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-go-source-at-root ()
+ "Boundary: a Go source file at project root runs `go test ./'."
+ (let (seen-cmd)
+ (cl-letf (((symbol-function 'compile)
+ (lambda (cmd) (setq seen-cmd cmd))))
+ (cj/--f6-current-file-tests-impl
+ "/home/u/proj/main.go"
+ "/home/u/proj/")
+ (should (string= seen-cmd "go test ./")))))
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-elisp-double-dash-test ()
+ "Boundary: a per-helper elisp test file runs `make test-file FILE=...' so
+just that file's tests run, not the whole module's prefix."
+ (let (seen-cmd)
+ (cl-letf (((symbol-function 'compile)
+ (lambda (cmd) (setq seen-cmd cmd))))
+ (cj/--f6-current-file-tests-impl
+ "/home/u/proj/tests/test-foo--bar.el"
+ "/home/u/proj/")
+ (should (string= seen-cmd "make test-file FILE=tests/test-foo--bar.el")))))
+
+;;; Error Cases
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-nil-file-errors ()
+ "Error: nil FILE signals a user-error."
+ (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)))
+ (should-error (cj/--f6-current-file-tests-impl nil "/home/u/proj/")
+ :type 'user-error)))
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-nil-root-errors ()
+ "Error: nil PROJECT-ROOT signals a user-error."
+ (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)))
+ (should-error (cj/--f6-current-file-tests-impl
+ "/home/u/proj/modules/foo.el" nil)
+ :type 'user-error)))
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-unsupported-language-errors ()
+ "Error: a file with no language-specific runner signals a user-error
+naming the language."
+ (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)))
+ (should-error (cj/--f6-current-file-tests-impl
+ "/home/u/proj/src/foo.test.ts" "/home/u/proj/")
+ :type 'user-error)))
+
+(ert-deftest test-dev-fkeys-f6-current-file-tests-impl-unknown-language-errors ()
+ "Error: an unknown extension signals a user-error rather than running
+something the user didn't ask for."
+ (cl-letf (((symbol-function 'compile) (lambda (_cmd) nil)))
+ (should-error (cj/--f6-current-file-tests-impl
+ "/home/u/proj/Makefile" "/home/u/proj/")
+ :type 'user-error)))
+
+(provide 'test-dev-fkeys--f6-current-file-tests-impl)
+;;; test-dev-fkeys--f6-current-file-tests-impl.el ends here