Skip to content

Commit b7ef45c

Browse files
committed
[wip] tests
1 parent ed5d4a0 commit b7ef45c

6 files changed

Lines changed: 305 additions & 5 deletions

File tree

.github/workflows/test.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: Test
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
name: Test
6+
uses: emacscollective/workflows/.github/workflows/test.yml@main

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ help:
2020
$(info make release - publish release manuals)
2121
$(info make stats - generate statistics)
2222
$(info make stats-upload - publish statistics)
23+
$(info make test - run tests)
2324
$(info make clean - remove most generated files)
2425
@printf "\n"
2526

@@ -53,6 +54,10 @@ stats:
5354
stats-upload:
5455
@$(MAKE) -C docs stats-upload
5556

57+
test: lisp
58+
@$(MAKE) -C test test
59+
5660
clean:
5761
@$(MAKE) -C lisp clean
5862
@$(MAKE) -C docs clean
63+
@$(MAKE) -C test clean

default.mk

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ EMACS_ARGS ?= --eval "(progn \
2020
(put 'when-let 'byte-obsolete-info nil))"
2121

2222
LOAD_PATH ?= $(addprefix -L ../../,$(DEPS))
23-
LOAD_PATH += -L .
23+
LOAD_PATH += -L $(TOP)lisp
2424

2525
ifndef ORG_LOAD_PATH
2626
ORG_LOAD_PATH = -L ../../org/lisp
@@ -33,3 +33,7 @@ MANUAL_HTML_ARGS ?= --css-ref /assets/page.css
3333
GITSTATS ?= gitstats
3434
GITSTATS_DIR ?= $(TOP)docs/stats
3535
GITSTATS_ARGS ?= -c style=https://magit.vc/assets/stats.css -c max_authors=999
36+
37+
%.elc: %.el
38+
@printf "Compiling $<\n"
39+
@$(EMACS) -Q --batch $(EMACS_ARGS) $(LOAD_PATH) -f batch-byte-compile $<

lisp/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ lisp: $(ELCS) loaddefs check-declare
55

66
loaddefs: $(PKG)-autoloads.el
77

8-
%.elc: %.el
9-
@printf "Compiling $<\n"
10-
@$(EMACS) -Q --batch $(EMACS_ARGS) $(LOAD_PATH) -f batch-byte-compile $<
11-
128
check-declare:
139
@printf " Checking function declarations\n"
1410
@$(EMACS) -Q --batch $(EMACS_ARGS) $(LOAD_PATH) \

test/Makefile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-include ../config.mk
2+
include ../default.mk
3+
4+
LOAD_PATH += -L $(TOP)test
5+
6+
test: lisp
7+
@printf " Testing...\n"
8+
@$(EMACS) -Q --batch $(EMACS_ARGS) $(LOAD_PATH) \
9+
-l ert -l $(PKG)-test -f ert-run-tests-batch-and-exit
10+
11+
lisp: ../lisp/$(PKG).elc $(PKG)-test.elc
12+
13+
clean:
14+
@printf " Cleaning test/*...\n"
15+
@rm -rf $(PKG)-test.elc

test/transient-test.el

Lines changed: 274 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,274 @@
1+
;;; llama-tests.el --- Tests for Llama -*- lexical-binding:t -*-
2+
3+
;; Copyright (C) 2018-2025 Jonas Bernoulli
4+
5+
;; Authors: Jonas Bernoulli <emacs.transient@jonas.bernoulli.dev>
6+
;; Homepage: https://github.com/magit/transient
7+
8+
;; SPDX-License-Identifier: GPL-3.0-or-later
9+
10+
;; This file is free software: you can redistribute it and/or modify
11+
;; it under the terms of the GNU General Public License as published
12+
;; by the Free Software Foundation, either version 3 of the License,
13+
;; or (at your option) any later version.
14+
;;
15+
;; This file is distributed in the hope that it will be useful,
16+
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18+
;; GNU General Public License for more details.
19+
;;
20+
;; You should have received a copy of the GNU General Public License
21+
;; along with this file. If not, see <https://www.gnu.org/licenses/>.
22+
23+
;;; Code:
24+
25+
(require 'ert)
26+
27+
(setq ert-batch-backtrace-right-margin 95)
28+
(setq ert-batch-print-length nil)
29+
(setq ert-batch-print-level nil)
30+
31+
(require 'transient)
32+
33+
;; (setq transient-detect-key-conflicts t)
34+
(setq transient-error-on-insert-failure t)
35+
36+
(transient-define-suffix test-command-a () (interactive))
37+
(transient-define-suffix test-command-b () (interactive))
38+
(transient-define-suffix test-command-c () :key "c" (interactive))
39+
(transient-define-suffix test-command-d () (interactive))
40+
(transient-define-suffix test-command-e () (interactive))
41+
(transient-define-suffix test-command-f () (interactive))
42+
(transient-define-suffix test-command-g () (interactive))
43+
(transient-define-suffix test-command-h () (interactive))
44+
(transient-define-suffix test-command-i () (interactive))
45+
(transient-define-suffix test-command-j () (interactive))
46+
47+
(transient-define-suffix test-command-q () (interactive))
48+
(transient-define-suffix test-command-r () (interactive))
49+
(transient-define-suffix test-command-s () (interactive))
50+
(transient-define-suffix test-command-t () (interactive))
51+
(transient-define-suffix test-command-u () (interactive))
52+
(transient-define-suffix test-command-v () (interactive))
53+
(transient-define-suffix test-command-w () :key "w" (interactive))
54+
(transient-define-suffix test-command-x () :key "x" (interactive))
55+
(transient-define-suffix test-command-y () :key "y" (interactive))
56+
(transient-define-suffix test-command-z () :key "z" (interactive))
57+
58+
(ert-deftest transient-test-101-define nil
59+
(transient-define-prefix test-101-menu ()
60+
[(test-command-a :key "a")
61+
(test-command-b :key "b")
62+
(test-command-c)
63+
(test-command-d :key "d")])
64+
(defvar test-101-menu--layout (transient--get-layout 'test-101-menu))
65+
(should (equal (transient--get-layout 'test-101-menu)
66+
[2 nil
67+
([transient-column nil
68+
((transient-suffix :command test-command-a :key "a")
69+
(transient-suffix :command test-command-b :key "b")
70+
(transient-suffix :command test-command-c)
71+
(transient-suffix :command test-command-d :key "d"))])]))
72+
(should (eq (transient--get-layout 'test-101-menu) test-101-menu--layout)))
73+
74+
(ert-deftest transient-test-102-change-key nil
75+
(transient-define-prefix test-102-menu ()
76+
[(test-command-a :key "a")
77+
(test-command-b :key "b")
78+
(test-command-c)
79+
(test-command-d :key "d")])
80+
(defvar test-102-menu--layout (transient--get-layout 'test-102-menu))
81+
(transient-suffix-put 'test-102-menu "a" :key "A")
82+
(transient-suffix-put 'test-102-menu 'test-command-b :key "B")
83+
(transient-suffix-put 'test-102-menu [0 -2] :key "C")
84+
(transient-suffix-put 'test-102-menu "d" :key "D")
85+
(should (equal (transient--get-layout 'test-102-menu)
86+
[2 nil
87+
([transient-column nil
88+
((transient-suffix :command test-command-a :key "A")
89+
(transient-suffix :command test-command-b :key "B")
90+
(transient-suffix :command test-command-c :key "C")
91+
(transient-suffix :command test-command-d :key "D"))])]))
92+
(should (eq (transient--get-layout 'test-102-menu) test-102-menu--layout)))
93+
94+
(ert-deftest transient-test-103-insert nil
95+
(transient-define-prefix test-103-menu ()
96+
[(test-command-a :key "a")
97+
(test-command-b :key "b")
98+
(test-command-c)
99+
(test-command-d :key "d")])
100+
(defvar test-103-menu--layout (transient--get-layout 'test-103-menu))
101+
(transient-insert-suffix 'test-103-menu "a" '(test-command-z))
102+
(transient-append-suffix 'test-103-menu "a" '(test-command-y))
103+
(transient-insert-suffix 'test-103-menu "b" '(test-command-x))
104+
(transient-append-suffix 'test-103-menu "b" '(test-command-w))
105+
(transient-insert-suffix 'test-103-menu "d" '(test-command-v :key "v"))
106+
(transient-append-suffix 'test-103-menu "d" '(test-command-u :key "u"))
107+
(should (equal (transient--get-layout 'test-103-menu)
108+
[2 nil
109+
([transient-column nil
110+
((transient-suffix :command test-command-z)
111+
(transient-suffix :command test-command-a :key "a")
112+
(transient-suffix :command test-command-y)
113+
(transient-suffix :command test-command-x)
114+
(transient-suffix :command test-command-b :key "b")
115+
(transient-suffix :command test-command-w)
116+
(transient-suffix :command test-command-c)
117+
(transient-suffix :command test-command-v :key "v")
118+
(transient-suffix :command test-command-d :key "d")
119+
(transient-suffix :command test-command-u :key "u"))])]))
120+
(should (eq (transient--get-layout 'test-103-menu) test-103-menu--layout)))
121+
122+
(ert-deftest transient-test-104-remove nil
123+
(transient-define-prefix test-104-menu ()
124+
[(test-command-a :key "a")
125+
(test-command-b :key "b")
126+
(test-command-c)
127+
(test-command-d :key "d")
128+
(test-command-e :key "e")
129+
(test-command-f :key "f")
130+
(test-command-g :key "g")])
131+
(defvar test-104-menu--layout (transient--get-layout 'test-104-menu))
132+
(transient-remove-suffix 'test-104-menu "a")
133+
(transient-remove-suffix 'test-104-menu 'test-command-b)
134+
(transient-remove-suffix 'test-104-menu "c")
135+
(transient-remove-suffix 'test-104-menu [0 0])
136+
(transient-remove-suffix 'test-104-menu [0 -1])
137+
(should (equal (transient--get-layout 'test-104-menu)
138+
[2 nil
139+
([transient-column nil
140+
((transient-suffix :command test-command-e :key "e")
141+
(transient-suffix :command test-command-f :key "f"))])]))
142+
(should (eq (transient--get-layout 'test-104-menu) test-104-menu--layout)))
143+
144+
(ert-deftest transient-test-105-include nil
145+
(transient-define-group test-105-top-group
146+
[:class transient-row
147+
(test-command-a :key "a")
148+
(test-command-b :key "b")])
149+
(should (equal (transient--get-layout 'test-105-top-group)
150+
[2 nil
151+
([transient-row nil
152+
((transient-suffix :command test-command-a :key "a")
153+
(transient-suffix :command test-command-b :key "b"))])]))
154+
(transient-define-group test-105-top-groups
155+
[[(test-command-c :key "c")
156+
(test-command-d :key "d")]
157+
[(test-command-e :key "e")
158+
(test-command-f :key "f")]])
159+
(should (equal (transient--get-layout 'test-105-top-groups)
160+
[2 nil
161+
([transient-columns nil
162+
([transient-column nil
163+
((transient-suffix :command test-command-c :key "c")
164+
(transient-suffix :command test-command-d :key "d"))]
165+
[transient-column nil
166+
((transient-suffix :command test-command-e :key "e")
167+
(transient-suffix :command test-command-f :key "f"))])])]))
168+
(transient-define-group test-105-child-group
169+
[(test-command-g :key "g")
170+
(test-command-h :key "h")])
171+
(should (equal (transient--get-layout 'test-105-child-group)
172+
[2 nil
173+
([transient-column nil
174+
((transient-suffix :command test-command-g :key "g")
175+
(transient-suffix :command test-command-h :key "h"))])]))
176+
(transient-define-group test-105-suffix-list
177+
(test-command-z :key "z")
178+
(test-command-y :key "y"))
179+
(should (equal (transient--get-layout 'test-105-suffix-list)
180+
[2 nil
181+
((transient-suffix :command test-command-z :key "z")
182+
(transient-suffix :command test-command-y :key "y"))]))
183+
(transient-define-prefix test-105-menu ()
184+
'test-105-top-group
185+
'test-105-top-groups
186+
[[(test-command-i :key "i")
187+
(test-command-j :key "j")
188+
test-105-suffix-list]
189+
test-105-child-group])
190+
(should (equal (transient--get-layout 'test-105-menu)
191+
[2 nil
192+
(test-105-top-group
193+
test-105-top-groups
194+
[transient-columns nil
195+
([transient-column nil
196+
((transient-suffix :command test-command-i :key "i")
197+
(transient-suffix :command test-command-j :key "j")
198+
test-105-suffix-list)]
199+
test-105-child-group)])]))
200+
)
201+
202+
(ert-deftest transient-test-106-edit-include nil
203+
(transient-define-group test-106-group
204+
[(test-command-a :key "a")
205+
(test-command-b :key "b")
206+
(test-command-c :key "c")
207+
(test-command-d :key "d")
208+
(test-command-e :key "e")
209+
(test-command-f :key "f")])
210+
(transient-define-prefix test-106-menu-1 ()
211+
'test-106-group)
212+
(transient-define-prefix test-106-menu-2 ()
213+
'test-106-group)
214+
(transient-suffix-put 'test-106-group "a" :key "A")
215+
(transient-suffix-put 'test-106-menu-1 "b" :key "B")
216+
(transient-suffix-put 'test-106-menu-2 "c" :key "C")
217+
(should (equal (transient--get-layout 'test-106-group)
218+
[2 nil
219+
([transient-column nil
220+
((transient-suffix :command test-command-a :key "A")
221+
(transient-suffix :command test-command-b :key "B")
222+
(transient-suffix :command test-command-c :key "C")
223+
(transient-suffix :command test-command-d :key "d")
224+
(transient-suffix :command test-command-e :key "e")
225+
(transient-suffix :command test-command-f :key "f"))])]))
226+
(transient-insert-suffix 'test-106-group "A" '(test-command-z :key "z"))
227+
(transient-append-suffix 'test-106-group "f" '(test-command-y :key "y"))
228+
(transient-insert-suffix 'test-106-menu-1 "z" '(test-command-x :key "x"))
229+
(transient-append-suffix 'test-106-menu-2 "y" '(test-command-w :key "w"))
230+
(should (equal (transient--get-layout 'test-106-group)
231+
[2 nil
232+
([transient-column nil
233+
((transient-suffix :command test-command-x :key "x")
234+
(transient-suffix :command test-command-z :key "z")
235+
(transient-suffix :command test-command-a :key "A")
236+
(transient-suffix :command test-command-b :key "B")
237+
(transient-suffix :command test-command-c :key "C")
238+
(transient-suffix :command test-command-d :key "d")
239+
(transient-suffix :command test-command-e :key "e")
240+
(transient-suffix :command test-command-f :key "f")
241+
(transient-suffix :command test-command-y :key "y")
242+
(transient-suffix :command test-command-w :key "w"))])]))
243+
(transient-remove-suffix 'test-106-group "z")
244+
(transient-remove-suffix 'test-106-group "y")
245+
(transient-remove-suffix 'test-106-group "x")
246+
(transient-remove-suffix 'test-106-group "w")
247+
(should (equal (transient--get-layout 'test-106-group)
248+
[2 nil
249+
([transient-column nil
250+
((transient-suffix :command test-command-a :key "A")
251+
(transient-suffix :command test-command-b :key "B")
252+
(transient-suffix :command test-command-c :key "C")
253+
(transient-suffix :command test-command-d :key "d")
254+
(transient-suffix :command test-command-e :key "e")
255+
(transient-suffix :command test-command-f :key "f"))])]))
256+
)
257+
258+
(ert-deftest transient-test-107-edit-include-list nil
259+
(transient-define-group test-107-suffix-list
260+
(test-command-c :key "c")
261+
(test-command-d :key "d"))
262+
(transient-define-prefix test-107-menu ()
263+
[(test-command-a :key "a")
264+
(test-command-b :key "b")
265+
test-107-suffix-list
266+
(test-command-e :key "e")
267+
(test-command-f :key "f")])
268+
(transient-append-suffix 'test-107-menu "c" '(test-command-z :key "z"))
269+
) ;TODO
270+
271+
;; Local Variables:
272+
;; indent-tabs-mode: nil
273+
;; End:
274+
;;; transient-tests.el ends here

0 commit comments

Comments
 (0)