blob: 74bb77f173c1934d15c37a3e8b58b0e08d0af152 (
plain)
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
|
;;; test-chime-log-silently.el --- Tests for chime--log-silently -*- lexical-binding: t; -*-
;; Copyright (C) 2024-2026 Craig Jennings
;; Author: Craig Jennings <c@cjennings.net>
;; This program 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.
;; This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Unit tests for chime--log-silently function.
;; This function writes to *Messages* buffer without echoing to minibuffer.
;;; Code:
(require 'test-bootstrap (expand-file-name "test-bootstrap.el"))
;;; Normal Cases
(ert-deftest test-chime-log-silently-writes-to-messages ()
"Should write the formatted text to *Messages* buffer."
(let ((messages-buf (get-buffer-create "*Messages*")))
(with-current-buffer messages-buf
(let ((pos-before (point-max)))
(chime--log-silently "Test log message")
(goto-char pos-before)
(should (search-forward "Test log message" nil t))))))
(ert-deftest test-chime-log-silently-formats-with-args ()
"Should format with args like `format'."
(let ((messages-buf (get-buffer-create "*Messages*")))
(with-current-buffer messages-buf
(let ((pos-before (point-max)))
(chime--log-silently "Event count: %d, name: %s" 5 "Meeting")
(goto-char pos-before)
(should (search-forward "Event count: 5, name: Meeting" nil t))))))
(ert-deftest test-chime-log-silently-multiple-calls-append ()
"Multiple calls should append sequentially."
(let ((messages-buf (get-buffer-create "*Messages*")))
(with-current-buffer messages-buf
(let ((pos-before (point-max)))
(chime--log-silently "First message")
(chime--log-silently "Second message")
(goto-char pos-before)
(let ((first-pos (search-forward "First message" nil t))
(second-pos (progn (goto-char pos-before)
(search-forward "Second message" nil t))))
(should first-pos)
(should second-pos)
;; Second should come after first
(should (> second-pos first-pos)))))))
;;; Boundary Cases
(ert-deftest test-chime-log-silently-empty-format-string ()
"Empty format string should not error."
;; Should not signal an error
(should-not (condition-case nil
(progn (chime--log-silently "") nil)
(error t))))
(provide 'test-chime-log-silently)
;;; test-chime-log-silently.el ends here
|