Refactor and fix unit tests, plus isolate them better
This commit is contained in:
parent
5c74814860
commit
8ad2666f8f
14 changed files with 146 additions and 117 deletions
|
@ -4,20 +4,21 @@
|
|||
(require! :completion company)
|
||||
(require 'company)
|
||||
|
||||
;;
|
||||
(def-test! set-company-backend
|
||||
(let ((default-backends (default-value 'company-backends)))
|
||||
:minor-mode company-mode
|
||||
(let ((company-backends '(default)))
|
||||
(set! :company-backend 'emacs-lisp-mode '(backend-1))
|
||||
(set! :company-backend 'lisp-interaction-mode 'backend-1 'backend-2)
|
||||
(set! :company-backend 'text-mode 'backend-1)
|
||||
(with-temp-buffer
|
||||
(emacs-lisp-mode)
|
||||
(should (equal (car company-backends) '(backend-1))))
|
||||
(should (equal company-backends '((backend-1) default))))
|
||||
(with-temp-buffer
|
||||
(lisp-interaction-mode)
|
||||
(should (equal company-backends
|
||||
(append '(backend-1 backend-2) default-backends))))
|
||||
(should (equal company-backends '(backend-1 backend-2 default))))
|
||||
(with-temp-buffer
|
||||
(text-mode)
|
||||
(should (eq (car company-backends) 'backend-1)))
|
||||
(should (equal company-backends '(backend-1 default))))
|
||||
;; global backends shouldn't be affected
|
||||
(should (equal company-backends default-backends))))
|
||||
(should (equal company-backends '(default)))))
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; feature/evil/test/autoload-files.el
|
||||
|
||||
(defmacro -with-temp-files! (src dest &rest body)
|
||||
(defmacro with-temp-files!! (src dest &rest body)
|
||||
"Run FORMS in the context of a temporary package setup (as in, it won't
|
||||
affects your Emacs packages)."
|
||||
(declare (indent 2) (doc-string 3))
|
||||
|
@ -23,7 +23,7 @@ affects your Emacs packages)."
|
|||
;;
|
||||
(def-test! move-this-file
|
||||
":mv"
|
||||
(-with-temp-files! "/tmp/doom-buffer" "/tmp/doom-buffer-new"
|
||||
(with-temp-files!! "/tmp/doom-buffer" "/tmp/doom-buffer-new"
|
||||
(should-error (+evil:move-this-file it))
|
||||
(should (+evil:move-this-file other t))
|
||||
(should (file-exists-p other))
|
||||
|
@ -31,7 +31,7 @@ affects your Emacs packages)."
|
|||
|
||||
(def-test! copy-this-file
|
||||
":cp"
|
||||
(-with-temp-files! "/tmp/doom-buffer-2" "/tmp/doom-buffer-2-new"
|
||||
(with-temp-files!! "/tmp/doom-buffer-2" "/tmp/doom-buffer-2-new"
|
||||
(should-error (+evil:copy-this-file it))
|
||||
(should (+evil:copy-this-file other t))
|
||||
(should (file-exists-p other))
|
||||
|
@ -39,7 +39,7 @@ affects your Emacs packages)."
|
|||
|
||||
(def-test! delete-this-file
|
||||
":rm"
|
||||
(-with-temp-files! "/tmp/doom-buffer-3" nil
|
||||
(with-temp-files!! "/tmp/doom-buffer-3" nil
|
||||
(should-error (+evil:delete-this-file "this-file-does-not-exist"))
|
||||
(should (+evil:delete-this-file nil t))
|
||||
(should (not (file-exists-p it)))))
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
(require! :feature evil)
|
||||
|
||||
;;
|
||||
;; `evil-ex-replace-special-filenames'
|
||||
;; NOTE The majority of this function is tested in core/test/core-lib.el, this
|
||||
;; only tests the evil-mode-specific functionality.
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
(require! :feature workspaces)
|
||||
|
||||
(defmacro -with-workspace! (buffer-args &rest body)
|
||||
(defmacro with-workspace!! (buffer-args &rest body)
|
||||
(declare (indent defun))
|
||||
(let ((buffers
|
||||
(cl-loop for bsym in buffer-args
|
||||
|
@ -27,14 +27,19 @@
|
|||
|
||||
;;
|
||||
(def-test! init
|
||||
(-with-workspace! ()
|
||||
(with-workspace!! ()
|
||||
(should (equal (+workspace-current-name) +workspaces-main))))
|
||||
|
||||
(def-test! advice
|
||||
(should (advice-member-p #'+workspaces*auto-add-buffer #'switch-to-buffer)))
|
||||
(def-test! auto-add-buffer-to-persp
|
||||
(let ((a (generate-new-buffer "a")))
|
||||
(doom-set-buffer-real a t)
|
||||
(with-workspace!! ()
|
||||
(should-not (+workspace-contains-buffer-p a))
|
||||
(switch-to-buffer a)
|
||||
(should (+workspace-contains-buffer-p a)))))
|
||||
|
||||
(def-test! current
|
||||
(-with-workspace! ()
|
||||
(with-workspace!! ()
|
||||
(should (equal (+workspace-current-name) +workspaces-main))
|
||||
(should (+workspace-exists-p +workspaces-main))
|
||||
(let ((workspace (+workspace-get +workspaces-main))
|
||||
|
@ -45,7 +50,7 @@
|
|||
(should (equal workspace current-workspace)))))
|
||||
|
||||
(def-test! workspace-list
|
||||
(-with-workspace! ()
|
||||
(with-workspace!! ()
|
||||
(should (equal (+workspace-list-names)
|
||||
(list (+workspace-current-name))))
|
||||
(should (equal (+workspace-list)
|
||||
|
@ -53,7 +58,7 @@
|
|||
|
||||
(def-test! workspace-crud
|
||||
"Creating, reading, updating and deleting workspaces."
|
||||
(-with-workspace! ()
|
||||
(with-workspace!! ()
|
||||
(let ((new-workspace-name "*new-test*")
|
||||
(renamed-workspace-name "*old-test*"))
|
||||
(should (+workspace-new new-workspace-name))
|
||||
|
@ -67,14 +72,14 @@
|
|||
(should (= (length (+workspace-list-names)) 1)))))
|
||||
|
||||
(def-test! workspace-switch
|
||||
(-with-workspace! ()
|
||||
(with-workspace!! ()
|
||||
(let ((new-workspace-name "*new-test*"))
|
||||
(should-error (+workspace-switch new-workspace-name))
|
||||
(should (+workspace-switch new-workspace-name t))
|
||||
(should (equal (+workspace-current-name) new-workspace-name)))))
|
||||
|
||||
(def-test! buffer-list
|
||||
(-with-workspace! (a b)
|
||||
(with-workspace!! (a b)
|
||||
(let ((c (get-buffer-create "c"))
|
||||
(d (get-buffer-create "d")))
|
||||
(should (+workspace-contains-buffer-p a))
|
||||
|
|
|
@ -1,40 +1,40 @@
|
|||
;; -*- no-byte-compile: t; -*-
|
||||
;;; lang/org/test/autoload-org.el
|
||||
|
||||
(defmacro should-org-buffer! (source expected &rest body)
|
||||
(defmacro should-org-buffer!! (source expected &rest body)
|
||||
`(should-buffer! ,source ,expected
|
||||
(org-mode)
|
||||
,@body))
|
||||
|
||||
|
||||
;;
|
||||
;; `+org/insert-item'
|
||||
(def-test! insert-item-h1
|
||||
"Should append/prepend new first-level headers with an extra newline."
|
||||
(should-org-buffer! ("* {0}Header") ("* Header\n\n* {|}")
|
||||
(should-org-buffer!! ("* {0}Header") ("* Header\n\n* {|}")
|
||||
(+org/insert-item 'below))
|
||||
(should-org-buffer! ("* {0}Header") ("* {|}\n\n* Header")
|
||||
(should-org-buffer!! ("* {0}Header") ("* {|}\n\n* Header")
|
||||
(+org/insert-item 'above)))
|
||||
|
||||
(def-test! insert-item-h2
|
||||
"Should append/prepend new second-level (and higher) headers without an extra
|
||||
newline."
|
||||
(should-org-buffer! ("** {0}Header") ("** Header\n** {|}")
|
||||
(should-org-buffer!! ("** {0}Header") ("** Header\n** {|}")
|
||||
(+org/insert-item 'below))
|
||||
(should-org-buffer! ("** {0}Header") ("** {|}\n** Header")
|
||||
(should-org-buffer!! ("** {0}Header") ("** {|}\n** Header")
|
||||
(+org/insert-item 'above)))
|
||||
|
||||
(def-test! insert-item-plain-list
|
||||
"Should append/prepend new second-level (and higher) headers without an extra
|
||||
newline."
|
||||
(should-org-buffer! ("+ {0}List item") ("+ List item\n+ {|}")
|
||||
(should-org-buffer!! ("+ {0}List item") ("+ List item\n+ {|}")
|
||||
(+org/insert-item 'below))
|
||||
(should-org-buffer! ("+ {0}List item"
|
||||
(should-org-buffer!! ("+ {0}List item"
|
||||
" + Sub item")
|
||||
("+ List item"
|
||||
" + Sub item"
|
||||
"+ {|}")
|
||||
(+org/insert-item 'below))
|
||||
(should-org-buffer! ("+ {0}List item"
|
||||
(should-org-buffer!! ("+ {0}List item"
|
||||
"+ Next item")
|
||||
("+ List item"
|
||||
"+ {|}"
|
||||
|
|
|
@ -5,3 +5,5 @@
|
|||
(require! :lang org)
|
||||
|
||||
(require 'org (locate-library "org" nil doom--package-load-path))
|
||||
|
||||
;;
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
(load! ../autoload)
|
||||
|
||||
(defmacro -with-passwords! (buffer-args &rest body)
|
||||
(defmacro with-passwords!! (buffer-args &rest body)
|
||||
(declare (indent defun))
|
||||
`(cl-letf
|
||||
(((symbol-function '+pass--get-entry)
|
||||
|
@ -18,7 +18,7 @@
|
|||
|
||||
;;
|
||||
(def-test! get-field
|
||||
(-with-passwords!
|
||||
(with-passwords!!
|
||||
(should (equal (+pass-get-field "fake/source" "login")
|
||||
"HL2532-GANDI"))
|
||||
(should (equal (+pass-get-field "fake/source" "email")
|
||||
|
@ -29,14 +29,14 @@
|
|||
"henrik@lissner.net"))))
|
||||
|
||||
(def-test! missing-fields-return-nil
|
||||
(-with-passwords!
|
||||
(with-passwords!!
|
||||
(should-not (+pass-get-field "fake/source" '("x" "y" "z")))))
|
||||
|
||||
(def-test! missing-entries-throw-error
|
||||
(-with-passwords!
|
||||
(with-passwords!!
|
||||
(should-error (+pass-get-field "nonexistent/source" "login"))))
|
||||
|
||||
(def-test! get-login
|
||||
(-with-passwords!
|
||||
(with-passwords!!
|
||||
(should (equal (+pass-get-user "fake/source") "HL2532-GANDI"))
|
||||
(should (equal (+pass-get-secret "fake/source") "defuse-account-gad"))))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue