Skip to content

Commit 7b66351

Browse files
dannyfreemanbbatsov
authored andcommitted
Run tests against clojure-ts-mode
Includes top level "main" tests, plus an additional clojure-ts-mode/* tests. This also tries to install the language grammar in the CI environment. Git and CC are required. This works in github actions
1 parent c0bdf94 commit 7b66351

File tree

8 files changed

+256
-27
lines changed

8 files changed

+256
-27
lines changed

.github/workflows/test.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@ jobs:
9999
cd dev; ../clojure.sh clojure -M:gen; cd -
100100
wc -l test/File.edn
101101
eldev -p -dtTC test --test-type enrich || eldev -p -dtTC test --test-type enrich
102-
102+
103+
- name: Test clojure-ts-mode
104+
if: startsWith (matrix.emacs_version, '29')
105+
run: |
106+
eldev -p -dtTC test --test-type clojure-ts-mode || eldev -p -dtTC test --test-type clojure-ts-mode

Eldev

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,25 +23,34 @@
2323
(setf eldev-standard-excludes `(:or ,eldev-standard-excludes
2424
;; Avoid including files in test "projects".
2525
(eldev-pcase-exhaustive cider-test-type
26-
(`main "./test/*/")
27-
(`integration '("./test/" "!./test/integration"))
28-
(`enrich '("./test/" "!./test/enrich"))
29-
(`all '("./test/*/" "!./test/integration")))
26+
(`main "./test/*/")
27+
(`integration '("./test/" "!./test/integration"))
28+
(`enrich '("./test/" "!./test/enrich"))
29+
(`clojure-ts-mode '("./test/*/" "!./test/clojure-ts-mode"))
30+
(`all '("./test/*/" "!./test/integration")))
3031
"test/integration/projects"
3132
;; This file is _supposed_ to be excluded
3233
;; from automated testing.
3334
"test/cider-tests--no-auto.el"))
3435

3536
(eldev-defoption cider-test-selection (type)
36-
"Select tests to run; type can be `main', `integration', `enrich' or `all'"
37+
"Select tests to run; type can be `main', `integration', `enrich', `clojure-ts-mode' or `all'"
3738
:options (-T --test-type)
3839
:for-command test
3940
:value TYPE
4041
:default-value cider-test-type
41-
(unless (memq (intern type) '(main integration enrich all))
42+
(unless (memq (intern type) '(main integration enrich clojure-ts-mode all))
4243
(signal 'eldev-wrong-option-usage `("unknown test type `%s'" ,type)))
4344
(setf cider-test-type (intern type)))
4445

46+
(add-hook 'eldev-load-dependencies-hook
47+
(lambda (type additional-sets)
48+
(when (and (eq cider-test-type 'clojure-ts-mode)
49+
(member 'runtime additional-sets))
50+
(message "Installing tree-sitter grammars")
51+
(require 'clojure-ts-mode)
52+
(clojure-ts--ensure-grammars))))
53+
4554
(add-hook 'eldev-test-hook
4655
(lambda ()
4756
(eldev-verbose "Using cider tests of type `%s'" cider-test-type)))

test/cider-selector-tests.el

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,39 +29,27 @@
2929

3030
(require 'buttercup)
3131
(require 'cider-selector)
32+
(require 'cider-selector-test-utils "test/utils/cider-selector-test-utils")
3233
(require 'cider-connection-test-utils "test/utils/cider-connection-test-utils")
3334

3435
;; Please, for each `describe', ensure there's an `it' block, so that its execution is visible in CI.
3536

3637
;; selector
37-
(defun cider-invoke-selector-method-by-key (ch)
38-
(let ((method (cl-find ch cider-selector-methods :key #'car)))
39-
(funcall (cl-third method))))
40-
41-
(defun cider--test-selector-method (method buffer-mode buffer-name)
42-
(with-temp-buffer
43-
(rename-buffer buffer-name)
44-
(setq major-mode buffer-mode)
45-
(let ((expected-buffer (current-buffer)))
46-
;; switch to another buffer
47-
(with-temp-buffer
48-
(cider-invoke-selector-method-by-key method)
49-
(expect (current-buffer) :to-equal expected-buffer)))))
5038

5139
(describe "cider-seletor-method-c"
5240
(it "switches to most recently visited clojure-mode buffer"
53-
(cider--test-selector-method ?c 'clojure-mode "*testfile*.clj")))
41+
(cider-test-selector-method ?c 'clojure-mode "*testfile*.clj")))
5442

5543
(describe "cider-seletor-method-e"
5644
(it "switches to most recently visited emacs-lisp-mode buffer"
5745
(kill-buffer "*scratch*")
58-
(cider--test-selector-method ?e 'emacs-lisp-mode "*testfile*.el")))
46+
(cider-test-selector-method ?e 'emacs-lisp-mode "*testfile*.el")))
5947

6048
(describe "cider-seletor-method-r"
6149
:var (cider-current-repl)
6250
(it "switches to current REPL buffer"
6351
(spy-on 'cider-current-repl :and-return-value "*cider-repl xyz*")
64-
(cider--test-selector-method ?r 'cider-repl-mode "*cider-repl xyz*")))
52+
(cider-test-selector-method ?r 'cider-repl-mode "*cider-repl xyz*")))
6553

6654
;; FIXME: should work but doesn't with a nonsense error
6755
;; (describe "cider-selector-method-m"
@@ -70,18 +58,18 @@
7058
;; (with-repl-buffer "a-session" 'clj _
7159
;; (setq-local nrepl-messages-buffer buf)
7260
;; (message "%S" (nrepl-messages-buffer (cider-current-repl)))
73-
;; (cider--test-selector-method ?m nil "*nrepl-messages some-id*")))))
61+
;; (cider-test-selector-method ?m nil "*nrepl-messages some-id*")))))
7462

7563
(describe "cider-seletor-method-x"
7664
(it "switches to *cider-error* buffer"
77-
(cider--test-selector-method ?x 'cider-stacktrace-mode "*cider-error*")))
65+
(cider-test-selector-method ?x 'cider-stacktrace-mode "*cider-error*")))
7866

7967
(describe "cider-seletor-method-d"
8068
(it "switches to *cider-doc* buffer"
81-
(cider--test-selector-method ?d 'cider-stacktrace-mode "*cider-doc*")))
69+
(cider-test-selector-method ?d 'cider-stacktrace-mode "*cider-doc*")))
8270

8371
(describe "cider-seletor-method-s"
8472
:var (cider-scratch-find-or-create-buffer)
8573
(it "switches to *cider-scratch* buffer"
8674
(spy-on 'cider-scratch-find-or-create-buffer :and-return-value "*cider-scratch*")
87-
(cider--test-selector-method ?s 'cider-docview-mode "*cider-scratch*")))
75+
(cider-test-selector-method ?s 'cider-docview-mode "*cider-scratch*")))

test/cider-util-tests.el

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,21 @@ and some other vars (like clojure.core/filter).
374374
(expect (cider--find-symbol-xref) :to-equal "clojure.core/map")
375375
(expect (cider--find-symbol-xref) :to-equal "clojure.core/filter")
376376
(expect (cider--find-symbol-xref) :to-equal nil))))
377+
378+
(describe "major-mode-predicates"
379+
(with-temp-buffer
380+
(it "matches clojure-mode"
381+
(clojure-mode)
382+
(expect (cider-clojure-major-mode-p) :to-be-truthy)
383+
(expect (cider-clojurescript-major-mode-p) :not :to-be-truthy)
384+
(expect (cider-clojurec-major-mode-p) :not :to-be-truthy))
385+
(it "matches clojurescript-mode"
386+
(clojurescript-mode)
387+
(expect (cider-clojure-major-mode-p) :to-be-truthy)
388+
(expect (cider-clojurescript-major-mode-p) :to-be-truthy)
389+
(expect (cider-clojurec-major-mode-p) :not :to-be-truthy))
390+
(it "matches clojurec-mode"
391+
(clojurec-mode)
392+
(expect (cider-clojure-major-mode-p) :to-be-truthy)
393+
(expect (cider-clojurescript-major-mode-p) :not :to-be-truthy)
394+
(expect (cider-clojurec-major-mode-p) :to-be-truthy))))
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
;;; cider-connection-ts-tests.el -*- lexical-binding: t; -*-
2+
3+
;; Copyright © 2012-2023 Tim King, Bozhidar Batsov
4+
5+
;; Author: Tim King <kingtim@gmail.com>
6+
;; Bozhidar Batsov <bozhidar@batsov.dev>
7+
;; Artur Malabarba <bruce.connor.am@gmail.com>
8+
9+
;; This file is NOT part of GNU Emacs.
10+
11+
;; This program is free software: you can redistribute it and/or
12+
;; modify it under the terms of the GNU General Public License as
13+
;; published by the Free Software Foundation, either version 3 of the
14+
;; License, or (at your option) any later version.
15+
;;
16+
;; This program is distributed in the hope that it will be useful, but
17+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
18+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
;; General Public License for more details.
20+
;;
21+
;; You should have received a copy of the GNU General Public License
22+
;; along with this program. If not, see `http://www.gnu.org/licenses/'.
23+
24+
;;; Commentary:
25+
26+
;; This file is part of CIDER
27+
28+
;;; Code:
29+
30+
(require 'buttercup)
31+
(require 'clojure-ts-mode)
32+
(require 'cider-connection)
33+
34+
(describe "Enable cider-minor mode on clojure-ts-mode buffers"
35+
(setq clojure-ts-mode-hook nil)
36+
(with-temp-buffer
37+
(clojure-ts-mode)
38+
(it "should enable cider-mode in the clojure-ts-mode buffer"
39+
(cider-enable-on-existing-clojure-buffers)
40+
(expect local-minor-modes :to-contain 'cider-mode)
41+
(expect clojure-ts-mode-hook :to-contain #'cider-mode))
42+
(it "should disable cider-mode in the clojure-ts-mode-buffer"
43+
(cider-disable-on-existing-clojure-buffers)
44+
(expect local-minor-modes :not :to-contain 'cider-mode))))
45+
46+
(describe "cider-repl-type-for-buffers"
47+
(it "correctly detects corresponding repl type based on clojure-ts-* major mode"
48+
(with-temp-buffer
49+
(clojure-ts-mode)
50+
(expect (cider-repl-type-for-buffer) :to-be 'clj))
51+
(with-temp-buffer
52+
(clojurescript-ts-mode)
53+
(expect (cider-repl-type-for-buffer) :to-be 'cljs))
54+
(with-temp-buffer
55+
(clojurec-ts-mode)
56+
(expect (cider-repl-type-for-buffer) :to-be 'multi))))
57+
58+
(provide 'cider-connection-ts-tests)
59+
60+
;;; clojure-connection-ts-tests.el ends here
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
;;; cider-selector-ts-tests.el -*- lexical-binding: t; -*-
2+
3+
;; Copyright © 2012-2023 Tim King, Bozhidar Batsov
4+
5+
;; Author: Tim King <kingtim@gmail.com>
6+
;; Bozhidar Batsov <bozhidar@batsov.dev>
7+
;; Artur Malabarba <bruce.connor.am@gmail.com>
8+
9+
;; This file is NOT part of GNU Emacs.
10+
11+
;; This program is free software: you can redistribute it and/or
12+
;; modify it under the terms of the GNU General Public License as
13+
;; published by the Free Software Foundation, either version 3 of the
14+
;; License, or (at your option) any later version.
15+
;;
16+
;; This program is distributed in the hope that it will be useful, but
17+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
18+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
;; General Public License for more details.
20+
;;
21+
;; You should have received a copy of the GNU General Public License
22+
;; along with this program. If not, see `http://www.gnu.org/licenses/'.
23+
24+
;;; Commentary:
25+
26+
;; This file is part of CIDER
27+
28+
;;; Code:
29+
30+
(require 'buttercup)
31+
(require 'clojure-ts-mode)
32+
(require 'cider-selector-test-utils "test/cider-selector-tests")
33+
34+
(describe "cider-seletor-method-c"
35+
(it "switches to most recently visited clojure-ts-mode buffer"
36+
(cider-test-selector-method ?c 'clojure-ts-mode "*treesitter-test*.clj")))
37+
38+
(provide 'cider-selector-ts-tests)
39+
40+
;;; clojure-selector-ts-tests.el ends here
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
;;; cider-util-ts-tests.el -*- lexical-binding: t; -*-
2+
3+
;; Copyright © 2012-2023 Tim King, Bozhidar Batsov
4+
5+
;; Author: Tim King <kingtim@gmail.com>
6+
;; Bozhidar Batsov <bozhidar@batsov.dev>
7+
;; Artur Malabarba <bruce.connor.am@gmail.com>
8+
9+
;; This file is NOT part of GNU Emacs.
10+
11+
;; This program is free software: you can redistribute it and/or
12+
;; modify it under the terms of the GNU General Public License as
13+
;; published by the Free Software Foundation, either version 3 of the
14+
;; License, or (at your option) any later version.
15+
;;
16+
;; This program is distributed in the hope that it will be useful, but
17+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
18+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
;; General Public License for more details.
20+
;;
21+
;; You should have received a copy of the GNU General Public License
22+
;; along with this program. If not, see `http://www.gnu.org/licenses/'.
23+
24+
25+
;;; Commentary:
26+
27+
;; This file is part of CIDER
28+
29+
;;; Code:
30+
31+
(require 'buttercup)
32+
(require 'clojure-ts-mode)
33+
(require 'cider-util)
34+
35+
(describe "clojure-ts-mode activation"
36+
(it "test suite installs the tree-sitter-clojure grammar"
37+
(with-temp-buffer
38+
(clojure-ts-mode)
39+
(expect (treesit-ready-p 'clojure)))))
40+
41+
(describe "major-mode-predicates"
42+
(with-temp-buffer
43+
(it "matches clojure-ts-mode"
44+
(clojure-ts-mode)
45+
(expect (cider-clojure-major-mode-p) :to-be-truthy)
46+
(expect (cider-clojurescript-major-mode-p) :not :to-be-truthy)
47+
(expect (cider-clojurec-major-mode-p) :not :to-be-truthy))
48+
(it "matches clojurescript-ts-mode"
49+
(clojurescript-ts-mode)
50+
(expect (cider-clojure-major-mode-p) :to-be-truthy)
51+
(expect (cider-clojurescript-major-mode-p) :to-be-truthy)
52+
(expect (cider-clojurec-major-mode-p) :not :to-be-truthy))
53+
(it "matches clojurec-ts-mode"
54+
(clojurec-ts-mode)
55+
(expect (cider-clojure-major-mode-p) :to-be-truthy)
56+
(expect (cider-clojurescript-major-mode-p) :not :to-be-truthy)
57+
(expect (cider-clojurec-major-mode-p) :to-be-truthy))))
58+
59+
(provide 'cider-ts-util-tests)
60+
61+
;;; cider-util-ts-tests.el ends here
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
;;; cider-selector-test-utils.el -*- lexical-binding: t; -*-
2+
3+
;; Copyright © 2012-2023 Tim King, Bozhidar Batsov
4+
5+
;; Author: Tim King <kingtim@gmail.com>
6+
;; Bozhidar Batsov <bozhidar@batsov.dev>
7+
;; Artur Malabarba <bruce.connor.am@gmail.com>
8+
9+
;; This file is NOT part of GNU Emacs.
10+
11+
;; This program is free software: you can redistribute it and/or
12+
;; modify it under the terms of the GNU General Public License as
13+
;; published by the Free Software Foundation, either version 3 of the
14+
;; License, or (at your option) any later version.
15+
;;
16+
;; This program is distributed in the hope that it will be useful, but
17+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
18+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19+
;; General Public License for more details.
20+
;;
21+
;; You should have received a copy of the GNU General Public License
22+
;; along with this program. If not, see `http://www.gnu.org/licenses/'.
23+
24+
;;; Commentary:
25+
26+
;; This file is part of CIDER
27+
28+
;;; Code:
29+
30+
(require 'buttercup)
31+
(require 'cider-selector)
32+
33+
(defun cider-invoke-selector-method-by-key (ch)
34+
(let ((method (cl-find ch cider-selector-methods :key #'car)))
35+
(funcall (cl-third method))))
36+
37+
(defun cider-test-selector-method (method buffer-mode buffer-name)
38+
(with-temp-buffer
39+
(rename-buffer buffer-name)
40+
(setq major-mode buffer-mode)
41+
(let ((expected-buffer (current-buffer)))
42+
;; switch to another buffer
43+
(with-temp-buffer
44+
(cider-invoke-selector-method-by-key method)
45+
(expect (current-buffer) :to-equal expected-buffer)))))
46+
47+
(provide 'cider-selector-test-utils)
48+
49+
;;; clojure-selector-test-utilss.el ends here

0 commit comments

Comments
 (0)