-
Notifications
You must be signed in to change notification settings - Fork 6
/
eva-test.el
94 lines (77 loc) · 2.93 KB
/
eva-test.el
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
;;; eva-test.el --- Unit tests -*- lexical-binding: t; -*-
;; Copyright (C) 2020-2024 Martin Edström
;; This file is not part of GNU Emacs.
;; 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.
;;; Code:
(require 'eva-builtin)
(require 'eva)
(require 'ert)
;; (setq eva--idle-beginning (setq eva--last-online (make-ts :unix 0)))
;; (eva--count-successes-today #'eva-present-diary)
;; (eva--call-timidly)
;; (named-timer-run :eva-attempt (* 60 60) (* 60 60) #'eva--call-timidly)
;; (run-with-timer 3 nil (lambda () (print (frame-focus-state))))
;; (eva-call-from-idle)
;; (eva-memory-put 'eva-items eva-items)
;; HACK: sit times specific to my machine. Also the chemacs profile
;; (ert-deftest eva-test-pid ()
;; (eva-mode 0)
;; (let ((p (pfuture-new "emacs" "--with-profile=doom")))
;; (sit-for 5)
;; (should (eva--another-eva-running-p))
;; (kill-process p)
;; (sit-for 1)
;; (should-not (eva--another-eva-running-p))))
(ert-deftest eva-test-idle1 ()
(let ((was-on eva-mode))
(when was-on
(eva-mode 0))
(setq eva--last-online (ts-now))
(setq eva--idle-beginning (ts-now))
(setq eva--idle-secs-fn #'eva--idle-secs-emacs)
(eva--start-next-timer t)
(sit-for .05)
(should (eq (seq-elt (named-timer-get :eva) 5)
'eva--user-is-idle))
(sit-for 2)
(should (eq (seq-elt (named-timer-get :eva) 5)
'eva--user-is-present))
(when was-on
(eva-mode))))
(ert-deftest eva-test-keepalive ()
(let ((was-on eva-mode))
(when was-on
(eva-mode 0))
(setq eva--last-online (ts-now))
(setq eva--idle-secs-fn #'eva--idle-secs-emacs)
(eva--keepalive)
(sit-for .1)
(should (named-timer-get :eva))
;; Takedown
(named-timer-cancel :eva-keepalive)
(named-timer-cancel :eva-retry)
(named-timer-cancel :eva)
(when was-on
(eva-mode))))
(ert-deftest eva-test-ts-usage ()
(let ((now (ts-now)))
(should (equal (ts-dec 'month 12 now)
(ts-dec 'year 1 now)))
(should (= 16 (length (-uniq (append
(--iterate (ts-dec 'month 1 it) now 12)
(--iterate (ts-dec 'year 1 it) now 5))))))
;; (should (= 66 (length (eva-past-sample-default))))
(should (-all-p #'ts-p (eva-past-sample-greedy)))))
(provide 'eva-test)
;;; eva-test.el ends here