blob: 0a51e2eb698f5ce314a4bfb56910d89d6d499b43 (
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
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
|
;;; test-chime-check-interval.el --- Tests for chime-check-interval -*- lexical-binding: t; -*-
;; Copyright (C) 2024 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-check-interval customization variable.
;; Tests cover normal cases, boundary cases, and error cases.
;;; 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)
;; Load test utilities
(require 'testutil-general (expand-file-name "testutil-general.el"))
;;; Setup and Teardown
(defun test-chime-check-interval-setup ()
"Setup function run before each test."
(chime-create-test-base-dir)
;; Reset to default
(setq chime-check-interval 60))
(defun test-chime-check-interval-teardown ()
"Teardown function run after each test."
(chime-delete-test-base-dir)
;; Reset to default
(setq chime-check-interval 60))
;;; Normal Cases
(ert-deftest test-chime-check-interval-normal-default-is-60 ()
"Test that default check interval is 60 seconds."
(test-chime-check-interval-setup)
(unwind-protect
(progn
(should (equal chime-check-interval 60)))
(test-chime-check-interval-teardown)))
(ert-deftest test-chime-check-interval-normal-can-set-30-seconds ()
"Test that check interval can be set to 30 seconds."
(test-chime-check-interval-setup)
(unwind-protect
(progn
(setq chime-check-interval 30)
(should (equal chime-check-interval 30)))
(test-chime-check-interval-teardown)))
(ert-deftest test-chime-check-interval-normal-can-set-300-seconds ()
"Test that check interval can be set to 300 seconds (5 minutes)."
(test-chime-check-interval-setup)
(unwind-protect
(progn
(setq chime-check-interval 300)
(should (equal chime-check-interval 300)))
(test-chime-check-interval-teardown)))
(ert-deftest test-chime-check-interval-normal-can-set-10-seconds ()
"Test that check interval can be set to 10 seconds (minimum recommended)."
(test-chime-check-interval-setup)
(unwind-protect
(progn
(setq chime-check-interval 10)
(should (equal chime-check-interval 10)))
(test-chime-check-interval-teardown)))
;;; Boundary Cases
(ert-deftest test-chime-check-interval-boundary-one-second-triggers-warning ()
"Test that 1 second interval triggers warning but is allowed."
(test-chime-check-interval-setup)
(unwind-protect
(progn
;; Setting to 1 should trigger a warning but succeed
;; We can't easily test the warning, but we can verify it's set
(setq chime-check-interval 1)
(should (equal chime-check-interval 1)))
(test-chime-check-interval-teardown)))
(ert-deftest test-chime-check-interval-boundary-large-value-accepted ()
"Test that large interval values are accepted (e.g., 1 hour)."
(test-chime-check-interval-setup)
(unwind-protect
(progn
(setq chime-check-interval 3600) ; 1 hour
(should (equal chime-check-interval 3600)))
(test-chime-check-interval-teardown)))
;;; Error Cases
(ert-deftest test-chime-check-interval-error-zero-rejected ()
"Test that zero interval is rejected."
(test-chime-check-interval-setup)
(unwind-protect
(progn
(should-error (customize-set-variable 'chime-check-interval 0)
:type 'user-error))
(test-chime-check-interval-teardown)))
(ert-deftest test-chime-check-interval-error-negative-rejected ()
"Test that negative interval is rejected."
(test-chime-check-interval-setup)
(unwind-protect
(progn
(should-error (customize-set-variable 'chime-check-interval -60)
:type 'user-error))
(test-chime-check-interval-teardown)))
(ert-deftest test-chime-check-interval-error-non-integer-rejected ()
"Test that non-integer values are rejected."
(test-chime-check-interval-setup)
(unwind-protect
(progn
(should-error (customize-set-variable 'chime-check-interval "60")
:type 'user-error))
(test-chime-check-interval-teardown)))
(provide 'test-chime-check-interval)
;;; test-chime-check-interval.el ends here
|