doomemacs/core/test/test-core.el

120 lines
4.1 KiB
EmacsLisp
Raw Normal View History

;; -*- no-byte-compile: t; -*-
;;; core/test/test-core.el
2018-08-17 10:03:07 +08:00
(describe "core"
(xdescribe "initialize"
:var (doom-init-p doom-init-modules-p doom-private-dir)
(before-each
(setq doom-init-p nil
doom-init-modules-p nil
doom-private-dir doom-emacs-dir)
(spy-on 'require)
(spy-on 'load)
(spy-on 'doom-reload-doom-autoloads)
(spy-on 'doom-reload-package-autoloads)
(spy-on 'doom-initialize-autoloads)
(spy-on 'doom-ensure-core-directories)
(spy-on 'doom-ensure-core-packages)
(spy-on 'doom-ensure-packages-initialized)
(spy-on 'doom-ensure-same-emacs-version-p))
(describe "in interactive session"
:var (noninteractive)
(before-each (setq noninteractive t))
(it "initializes once, unless forced")
(it "does not initialize on consecutive invokations")
(it "loads all core libraries" )
(it "loads autoloads file" )
(it "does not load autoloads file if forced" )
(it "regenerates missing autoloads" ))
(describe "in non-interactive session"
:var (noninteractive)
(before-each (setq noninteractive nil))
(it "initializes once, unless forced")
(it "does not initialize on consecutive invokations")
(it "does not load all core libraries" )
(it "loads autoloads file" )
(it "does not load autoloads file if forced" )
(it "does not regenerate missing autoloads" )))
2018-08-17 10:03:07 +08:00
(xdescribe "initialize-packages"
(before-each (spy-on 'quelpa-setup-p))
(it "initializes package.el once, unless forced" )
(it "initializes quelpa once, unless forced" )
(it "initializes doom-packages once, unless forced" ))
2018-08-17 10:03:07 +08:00
(xdescribe "initialize-modules"
(it "loads private init.el once, unless forced" ))
2018-08-17 10:03:07 +08:00
(xdescribe "initialize-autoloads"
(it "loads autoloads file" )
2018-08-17 10:03:07 +08:00
(it "ignores autoloads file if cleared" ))
(describe "custom hooks"
(describe "switch hooks"
:var (before-hook after-hook a b)
(before-each
(setq a (switch-to-buffer (get-buffer-create "a"))
b (get-buffer-create "b"))
(spy-on 'hook)
:boom: revise advice naming convention (1/2) This is first of three big naming convention updates that have been a long time coming. With 2.1 on the horizon, all the breaking updates will batched together in preparation for the long haul. In this commit, we do away with the asterix to communicate that a function is an advice function, and we replace it with the '-a' suffix. e.g. doom*shut-up -> doom-shut-up-a doom*recenter -> doom-recenter-a +evil*static-reindent -> +evil--static-reindent-a The rationale behind this change is: 1. Elisp's own formatting/indenting tools would occasionally struggle with | and * (particularly pp and cl-prettyprint). They have no problem with / and :, fortunately. 2. External syntax highlighters (like pygmentize, discord markdown or github markdown) struggle with it, sometimes refusing to highlight code beyond these symbols. 3. * and | are less expressive than - and -- in communicating the intended visibility, versatility and stability of a function. 4. It complicated the regexps we must use to search for them. 5. They were arbitrary and over-complicated to begin with, decided on haphazardly way back when Doom was simply "my private config". Anyhow, like how predicate functions have the -p suffix, we'll adopt the -a suffix for advice functions, -h for hook functions and -fn for variable functions. Other noteable changes: - Replaces advice-{add,remove}! macro with new def-advice! macro. The old pair weren't as useful. The new def-advice! saves on a lot of space. - Removed "stage" assertions to make sure you were using the right macros in the right place. Turned out to not be necessary, we'll employ better checks later.
2019-07-18 21:42:52 +08:00
(add-hook 'buffer-list-update-hook #'doom-run-switch-window-hooks-h)
(add-hook 'focus-in-hook #'doom-run-switch-frame-hooks-h)
(dolist (fn '(switch-to-buffer display-buffer))
(advice-add fn :around #'doom-run-switch-buffer-hooks-a)))
2018-08-17 10:03:07 +08:00
(after-each
:boom: revise advice naming convention (1/2) This is first of three big naming convention updates that have been a long time coming. With 2.1 on the horizon, all the breaking updates will batched together in preparation for the long haul. In this commit, we do away with the asterix to communicate that a function is an advice function, and we replace it with the '-a' suffix. e.g. doom*shut-up -> doom-shut-up-a doom*recenter -> doom-recenter-a +evil*static-reindent -> +evil--static-reindent-a The rationale behind this change is: 1. Elisp's own formatting/indenting tools would occasionally struggle with | and * (particularly pp and cl-prettyprint). They have no problem with / and :, fortunately. 2. External syntax highlighters (like pygmentize, discord markdown or github markdown) struggle with it, sometimes refusing to highlight code beyond these symbols. 3. * and | are less expressive than - and -- in communicating the intended visibility, versatility and stability of a function. 4. It complicated the regexps we must use to search for them. 5. They were arbitrary and over-complicated to begin with, decided on haphazardly way back when Doom was simply "my private config". Anyhow, like how predicate functions have the -p suffix, we'll adopt the -a suffix for advice functions, -h for hook functions and -fn for variable functions. Other noteable changes: - Replaces advice-{add,remove}! macro with new def-advice! macro. The old pair weren't as useful. The new def-advice! saves on a lot of space. - Removed "stage" assertions to make sure you were using the right macros in the right place. Turned out to not be necessary, we'll employ better checks later.
2019-07-18 21:42:52 +08:00
(remove-hook 'buffer-list-update-hook #'doom-run-switch-window-hooks-h)
(remove-hook 'focus-in-hook #'doom-run-switch-frame-hooks-h)
(dolist (fn '(switch-to-buffer display-buffer))
(advice-remove fn #'doom-run-switch-buffer-hooks-a))
2018-08-17 10:03:07 +08:00
(kill-buffer a)
(kill-buffer b))
(describe "switch-buffer"
:var (doom-switch-buffer-hook)
2018-08-17 10:03:07 +08:00
(before-each
(setq doom-switch-buffer-hook '(hook)))
2018-08-17 10:03:07 +08:00
(after-each
(setq doom-switch-buffer-hook nil))
2018-08-17 10:03:07 +08:00
(it "should trigger when switching buffers"
(switch-to-buffer b)
(switch-to-buffer a)
(switch-to-buffer b)
(expect 'hook :to-have-been-called-times 3))
2018-08-17 10:03:07 +08:00
(it "should trigger only once on the same buffer"
(switch-to-buffer b)
(switch-to-buffer b)
(switch-to-buffer a)
(expect 'hook :to-have-been-called-times 2)))
2018-08-17 10:03:07 +08:00
(describe "switch-window"
:var (doom-switch-window-hook x y)
2018-08-17 10:03:07 +08:00
(before-each
(delete-other-windows)
(setq x (get-buffer-window a)
y (save-selected-window (split-window)))
(with-selected-window y
(switch-to-buffer b))
(select-window x)
(spy-calls-reset 'hook)
(setq doom-switch-window-hook '(hook)))
2018-08-17 10:03:07 +08:00
(it "should trigger when switching windows"
(select-window y)
(select-window x)
(select-window y)
(expect 'hook :to-have-been-called-times 3))
2018-08-17 10:03:07 +08:00
(it "should trigger only once on the same window"
(select-window y)
(select-window y)
(select-window x)
(expect 'hook :to-have-been-called-times 2))))))