aboutsummaryrefslogtreecommitdiffstats
path: root/test/src/terminal-tests.el
blob: 85c4fa04efcd97ea94ee1e3643ef9195ef606955 (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
;;; terminal-tests.el --- tests for terminal.c -*- lexical-binding: t -*-

;; Copyright (C) 2026 Free Software Foundation, Inc.

;; 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)

(ert-deftest frame-initial-p ()
  "Test `frame-initial-p' behavior."
  (should-not (frame-initial-p t))
  (should-not (frame-initial-p (current-buffer)))
  (should-not (frame-initial-p (selected-window)))
  ;; "Initial frame" implies "initial terminal", and
  ;; no other terminal can have the initial frame.
  (should-not (xor (equal (terminal-name) "initial_terminal")
                   (frame-initial-p)))
  ;; Initial frame implies its terminal is a termcap-like
  ;; text-mode terminal.
  (should (or (not (frame-initial-p))
              (eq (terminal-live-p nil) t)))
  ;; It similarly implies a termcap-like text-mode frame.
  (should (or (not (frame-initial-p))
              (eq (frame-live-p (selected-frame)) t)))
  (dolist (ft (append '(nil) (frame-list) (terminal-list)))
    (ert-info ((prin1-to-string ft) :prefix "Argument: ")
      (should-not (xor (equal (terminal-name ft) "initial_terminal")
                       (frame-initial-p ft)))
      (should (or (not (frame-initial-p ft))
                  (eq (terminal-live-p ft) t)))))
  (cond (noninteractive
         ;; Batch mode should have an initial frame.
         (should (any #'frame-initial-p (frame-list)))
         (should (any #'frame-initial-p (terminal-list))))
        ((not (daemonp))
         ;; Non-daemon interactive mode should have none.
         (should-not (any #'frame-initial-p (frame-list)))
         (should-not (any #'frame-initial-p (terminal-list))))))

;;; terminal-tests.el ends here