-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* reindent current test * add some tests * add Makefile for running tests * add org-alert--map-entries to make testing a little easier * add test dependent on current-time * add no notification test with remindern * allow passing a different org file to `with-test-org` * add non-remindern tests * add ci.sh and github ci file * wrong order in use-package * add melpa * unwind-protect to prevent one failure from ruining all tests * use-package wasn't added until 29 * add/subtract 10 seconds for extra buffer time in failing tests * fix extra quote * assert preconditions for failing CI tests, they're working locally * debug prints * wrong remindern test * set timezone, github runners were in UTC * untabify and reindent * fix a test docstring
- Loading branch information
Showing
6 changed files
with
169 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# copied from | ||
# https://github.com/magnars/s.el/blob/dda84d38fffdaf0c9b12837b504b402af910d01d/.github/workflows/test.yml | ||
name: CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
jobs: | ||
test: | ||
timeout-minutes: 5 | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
emacs_version: | ||
- 29.1 | ||
- 29.2 | ||
- 29.3 | ||
- 29.4 | ||
- snapshot | ||
fail-fast: false | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Emacs | ||
uses: purcell/[email protected] | ||
with: | ||
version: ${{ matrix.emacs_version }} | ||
|
||
- name: Test | ||
run: | | ||
./ci.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
set -xe | ||
|
||
emacs -batch -f package-initialize \ | ||
--eval '(add-to-list (quote package-archives) (quote ("melpa" . "http://melpa.org/packages/")))' \ | ||
--eval '(use-package alert :ensure t)' | ||
|
||
cd test && make test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
test: | ||
emacs -batch -f package-initialize \ | ||
-l ert \ | ||
-l alert \ | ||
-l ../org-alert.el \ | ||
-l test.el \ | ||
-f ert-run-tests-batch-and-exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* TODO regular test | ||
SCHEDULED: <2023-05-20 Sat 09:55> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,96 @@ | ||
;; -*- lexical-binding: t; -*- | ||
|
||
(defvar test-alert-notifications nil | ||
"The notifications received so far") | ||
|
||
(defun test-alert-notify (info) | ||
(push info test-alert-notifications)) | ||
|
||
(defun test-alert-reset () | ||
(setq test-alert-notifications nil)) | ||
|
||
(alert-define-style 'test-alert :notifier #'test-alert-notify) | ||
|
||
(cl-defmacro with-test-org (agenda-file &rest body) | ||
(declare (indent defun)) | ||
(let ((agenda-file (or agenda-file "test.org"))) | ||
`(let ((org-directory ".") | ||
(org-agenda-files (list ,agenda-file)) | ||
(alert-default-style 'test-alert) | ||
;; TODO the fact that I have to include this from my own config is a | ||
;; really bad sign for the default value in the package | ||
(org-alert-match-string | ||
"SCHEDULED<\"<yesterday>\"+SCHEDULED<\"<tomorrow>\"")) | ||
(with-environment-variables (("TZ" "UTC4")) | ||
(unwind-protect | ||
(progn ,@body) | ||
(test-alert-reset)))))) | ||
|
||
(defmacro with-current-time (time &rest body) | ||
"Override `current-time` to return `Sat May 20 09:40:01 2023`, 15 minutes | ||
before the scheduled event in `test.org`." | ||
;; (current-time-string '(25704 52657 0 0)) | ||
(declare (indent defun)) | ||
(let ((time (or time '(25704 52657 0 0)))) | ||
`(cl-letf (((symbol-function 'current-time) | ||
(lambda () ',time))) | ||
,@body))) | ||
|
||
(ert-deftest org-alert-custom-cutoff () | ||
"checks that we can extract the correct cutoff from the | ||
PROPERTIES of a subtree" | ||
(let ((org-directory ".") | ||
(org-agenda-files (list "test.org"))) | ||
(with-test-org nil | ||
(should (equal | ||
'(("remindern test" "09:55" 15)) | ||
(org-map-entries 'org-alert--parse-entry org-alert-match-string 'agenda | ||
'(org-agenda-skip-entry-if 'todo | ||
org-done-keywords-for-agenda)))))) | ||
'(("remindern test" "09:55" 15)) | ||
(org-alert--map-entries 'org-alert--parse-entry))))) | ||
|
||
(ert-deftest check-alert-default () | ||
"Check that `org-alert-check` sends an alert from `test.org`. | ||
This works because the default `org-alert-notify-after-event-cutoff` is | ||
nil, so any time in the past will be alerted." | ||
(with-test-org nil | ||
(org-alert-check) | ||
(should (= (length test-alert-notifications) 1)))) | ||
|
||
(ert-deftest check-alert-none-cutoff () | ||
"Check that `org-alert-check` does not send an alert from `test.org` with | ||
a post-event cutoff set." | ||
(with-test-org nil | ||
(let ((org-alert-notify-after-event-cutoff 60)) | ||
(org-alert-check) | ||
(should (= (length test-alert-notifications) 0))))) | ||
|
||
;; TODO idea here is generate an org file with a timestamp in the near future to | ||
;; check if the notification actually works | ||
(ert-deftest check-alert-some-remindern () | ||
"Check that `org-alert-check` sends an alert from `test.org` with | ||
a post-event cutoff set but the current time set appropriately." | ||
(with-test-org nil | ||
(with-current-time (25704 52667 0 0) ; 9:40:11 | ||
(let ((org-alert-notify-after-event-cutoff 60)) | ||
(should (= (length test-alert-notifications) 0)) | ||
(org-alert-check) | ||
(should (= (length test-alert-notifications) 1)))))) | ||
|
||
;; (let ((org-directory ".") | ||
;; (org-agenda-files (list "test.org"))) | ||
;; (org-alert-check)) | ||
(ert-deftest check-alert-none-remindern () | ||
"Check that `org-alert-check` does not send an alert from `test.org` with | ||
a post-event cutoff set but the current time set appropriately." | ||
(with-test-org nil | ||
;; (current-time-string '(25704 52655 0 0)) => "Sat May 20 09:39:59 2023" or | ||
;; just before the notification should trigger | ||
(with-current-time (25704 52655 0 0) | ||
(let ((org-alert-notify-after-event-cutoff 60)) | ||
(org-alert-check) | ||
(should (= (length test-alert-notifications) 0)))))) | ||
|
||
;; (org-time-stamp '(16) nil) | ||
;; <2023-05-20 Sat 10:22> | ||
(ert-deftest check-alert-some () | ||
(with-test-org "plain.org" | ||
(with-current-time (25704 52957 0 0) ; 9:45:01 | ||
(org-alert-check) | ||
(should (= (length test-alert-notifications) 1))))) | ||
|
||
(ert-deftest check-alert-none () | ||
(with-test-org "plain.org" | ||
(with-current-time (25704 52945 0 0) ; 9:44:49 | ||
(should (= (length test-alert-notifications) 0)) | ||
(org-alert-check) | ||
(should (= (length test-alert-notifications) 0))))) |