aboutsummaryrefslogtreecommitdiff
path: root/tests/test-chime-log-silently.el
blob: e08987f2a8878af2e2ef830bca95563b3148ab70 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
;;; 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:

;; Initialize package system for batch mode
(when noninteractive
  (package-initialize))

(require 'ert)

;; Load dependencies required by chime
(require 'dash)
(require 'alert)
(require 'async)
(require 'org-agenda)

;; Load chime from parent directory
(load (expand-file-name "../chime.el") nil t)

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