blob: 46aa1f2a84532f0226b3aa51c76b2bcbcd78f9f9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
|
;;; tab-bar-tests.el --- Tests for tab-bar.el -*- lexical-binding: t; -*-
;; Copyright (C) 2021-2026 Free Software Foundation, Inc.
;; Author: Juri Linkov <juri@linkov.net>
;; This file is part of GNU Emacs.
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
;;; Code:
(require 'ert)
(defun tab-bar-tests-close-other-tabs (arg)
(tab-bar-tabs-set nil)
(tab-rename "1")
(tab-new) (tab-rename "2") ;; (tab-switch "2")
(tab-new) (tab-rename "3") ;; (tab-switch "3")
(should (eq (length (tab-bar-tabs)) 3))
(should (equal (alist-get 'name (tab-bar--current-tab-find)) "3"))
(tab-bar-close-other-tabs arg)
(should (equal (alist-get 'name (tab-bar--current-tab-find))
(if arg (number-to-string (max 1 (min arg 3))) "3")))
(should (eq (length (tab-bar-tabs)) 1))
(should (eq (length tab-bar-closed-tabs) 2))
(tab-undo)
(tab-undo)
(should (equal (tab-undo) "No more closed tabs to undo"))
(should (eq (length (tab-bar-tabs)) 3))
(should (eq (length tab-bar-closed-tabs) 0)))
(ert-deftest tab-bar-tests-close-other-tabs-default ()
(tab-bar-tests-close-other-tabs nil)
;; Clean up tabs afterwards
(tab-bar-tabs-set nil))
(ert-deftest tab-bar-tests-close-other-tabs-with-arg ()
(dotimes (i 5) (tab-bar-tests-close-other-tabs i))
;; Clean up tabs afterwards
(tab-bar-tabs-set nil))
(ert-deftest tab-bar-tests-quit-restore-window ()
(skip-when (pcase system-type
;; Skip test on MS-Windows in batch mode, since terminal
;; frames cannot be created in that case.
('windows-nt noninteractive)
;; This test is unreliable on macOS when run in batch mode
;; from Emacs (M-x compile).
('darwin (equal (getenv "TERM") "dumb"))
;; Emba runs the container without "--tty"
;; (the environment variable "TERM" is nil), and this
;; test fails with '(error "Could not open file: /dev/tty")'.
;; Therefore skip it unless it can use '(tty-type . "linux")'.
('gnu/linux (null (getenv "TERM")))))
(let* ((frame-params (when noninteractive
'((window-system . nil)
(tty-type . "linux"))))
(pop-up-frame-alist frame-params)
(frame-auto-hide-function 'delete-frame))
;; 1.1. 'quit-restore-window' should delete the frame
;; from initial window (bug#59862)
(progn
(should (eq (length (frame-list)) 1))
(other-frame-prefix)
(info)
(should (eq (length (frame-list)) 2))
(should (equal (buffer-name) "*info*"))
(view-echo-area-messages)
(other-window 1)
(should (eq (length (window-list)) 2))
(should (equal (buffer-name) "*Messages*"))
(quit-window)
(should (eq (length (window-list)) 1))
(should (equal (buffer-name) "*info*"))
(quit-window)
(should (eq (length (frame-list)) 1)))
;; 1.2. 'quit-restore-window' should not delete the frame
;; from non-initial window (bug#59862)
(progn
(should (eq (length (frame-list)) 1))
(other-frame-prefix)
(info)
(should (eq (length (frame-list)) 2))
(should (equal (buffer-name) "*info*"))
(view-echo-area-messages)
(should (eq (length (window-list)) 2))
(should (equal (buffer-name) "*info*"))
(quit-window)
(should (eq (length (window-list)) 1))
(should (eq (length (frame-list)) 2))
(should (equal (buffer-name) "*Messages*"))
(quit-window)
(should (eq (length (frame-list)) 2))
;; Delete the created frame afterwards because with tty frames
;; the output of 'message' is bound to the original frame
(delete-frame (car (frame-list))))
;; 2.1. 'quit-restore-window' should close the tab
;; from initial window (bug#59862)
(progn
(should (eq (length (tab-bar-tabs)) 1))
(other-tab-prefix)
(info)
(should (eq (length (tab-bar-tabs)) 2))
(should (equal (buffer-name) "*info*"))
(view-echo-area-messages)
(other-window 1)
(should (eq (length (window-list)) 2))
(should (equal (buffer-name) "*Messages*"))
(quit-window)
(should (eq (length (window-list)) 1))
(should (equal (buffer-name) "*info*"))
(quit-window)
(should (eq (length (tab-bar-tabs)) 1)))
;; 2.2. 'quit-restore-window' should not close the tab
;; from non-initial window (bug#59862)
(progn
(should (eq (length (tab-bar-tabs)) 1))
(other-tab-prefix)
(info)
(should (eq (length (tab-bar-tabs)) 2))
(should (equal (buffer-name) "*info*"))
(view-echo-area-messages)
(should (eq (length (window-list)) 2))
(should (equal (buffer-name) "*info*"))
(quit-window)
(should (eq (length (window-list)) 1))
(should (eq (length (tab-bar-tabs)) 2))
(should (equal (buffer-name) "*Messages*"))
(quit-window)
(should (eq (length (tab-bar-tabs)) 2))
;; Clean up the tab afterwards
(tab-close))
;; 3.1. Don't delete the frame with dedicated window
;; from the second tab (bug#71386)
(with-selected-frame (make-frame frame-params)
(switch-to-buffer (generate-new-buffer "test1"))
(tab-new)
(switch-to-buffer (generate-new-buffer "test2"))
(set-window-dedicated-p (selected-window) t)
(kill-buffer)
(should (eq (length (frame-list)) 2))
(should (eq (length (tab-bar-tabs)) 1))
;; But now should delete the frame with dedicated window
;; from the last tab
(set-window-dedicated-p (selected-window) t)
(kill-buffer)
(should (eq (length (frame-list)) 1)))
;; 3.2. Don't delete the frame with an effectively-dedicated window
;; from the second tab (bug#71386)
(with-selected-frame (make-frame frame-params)
(let ((switch-to-prev-buffer-skip #'always)
(kill-buffer-quit-windows nil))
(switch-to-buffer (generate-new-buffer "test1"))
(tab-bar-new-tab)
(switch-to-buffer (generate-new-buffer "test2"))
;; This makes the window effectively dedicated.
(set-window-prev-buffers nil nil)
;; Killing the buffer should close the tab, leave one open tab,
;; and not delete the frame.
(kill-buffer)
(should (eq (length (tab-bar-tabs)) 1))
(should (eq (length (frame-list)) 2))
(delete-frame))))
;; Clean up tabs afterwards
(tab-bar-tabs-set nil))
(provide 'tab-bar-tests)
;;; tab-bar-tests.el ends here
|