mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 21:13:04 +00:00
enhancement: tests for snippet autocompilation
This commit is contained in:
parent
0e7f510e9d
commit
209cf81f04
@ -28,8 +28,6 @@
|
|||||||
(require 'ert)
|
(require 'ert)
|
||||||
(require 'ert-x)
|
(require 'ert-x)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;;; Snippet mechanics
|
;;; Snippet mechanics
|
||||||
|
|
||||||
(ert-deftest field-navigation ()
|
(ert-deftest field-navigation ()
|
||||||
@ -112,9 +110,9 @@ TODO: correct this bug!"
|
|||||||
|
|
||||||
;;; Loading
|
;;; Loading
|
||||||
;;;
|
;;;
|
||||||
(defmacro with-some-interesting-snippet-dirs (&rest body)
|
(defmacro yas/with-some-interesting-snippet-dirs (&rest body)
|
||||||
`(yas/saving-variables
|
`(yas/saving-variables
|
||||||
(with-snippet-dirs
|
(yas/with-snippet-dirs
|
||||||
'((".emacs.d/snippets"
|
'((".emacs.d/snippets"
|
||||||
("c-mode"
|
("c-mode"
|
||||||
(".yas-parents" . "cc-mode")
|
(".yas-parents" . "cc-mode")
|
||||||
@ -130,13 +128,13 @@ TODO: correct this bug!"
|
|||||||
|
|
||||||
(ert-deftest basic-jit-loading ()
|
(ert-deftest basic-jit-loading ()
|
||||||
"Test basic loading and expansion of snippets"
|
"Test basic loading and expansion of snippets"
|
||||||
(with-some-interesting-snippet-dirs
|
(yas/with-some-interesting-snippet-dirs
|
||||||
(yas/reload-all)
|
(yas/reload-all)
|
||||||
(yas/basic-jit-loading-1)))
|
(yas/basic-jit-loading-1)))
|
||||||
|
|
||||||
(ert-deftest basic-jit-loading-with-compiled-snippets ()
|
(ert-deftest basic-jit-loading-with-compiled-snippets ()
|
||||||
"Test basic loading and expansion of snippets"
|
"Test basic loading and expansion of snippets"
|
||||||
(with-some-interesting-snippet-dirs
|
(yas/with-some-interesting-snippet-dirs
|
||||||
(yas/reload-all)
|
(yas/reload-all)
|
||||||
(yas/recompile-all)
|
(yas/recompile-all)
|
||||||
(flet ((yas/load-directory-2
|
(flet ((yas/load-directory-2
|
||||||
@ -168,6 +166,53 @@ TODO: correct this bug!"
|
|||||||
("def" . "# define")))
|
("def" . "# define")))
|
||||||
(yas/should-not-expand '("sc" "dolist" "ert-deftest"))))
|
(yas/should-not-expand '("sc" "dolist" "ert-deftest"))))
|
||||||
|
|
||||||
|
;;; Smart recompilation
|
||||||
|
;;;
|
||||||
|
(ert-deftest smart-recompilation ()
|
||||||
|
"Test if the mtime-based recompilation logic works"
|
||||||
|
(yas/with-snippet-dirs
|
||||||
|
'((".emacs.d/snippets"
|
||||||
|
("c-mode"
|
||||||
|
("printf" . "printf($1);")
|
||||||
|
("fopen" . "fopen($1);")
|
||||||
|
("stupidsnippet" . "stupidbla($1);"))))
|
||||||
|
(yas/recompile-all)
|
||||||
|
(let ((compiled ".emacs.d/snippets/c-mode/.yas-compiled-snippets.el"))
|
||||||
|
(should (file-readable-p compiled))
|
||||||
|
(let ((yas/auto-compile-snippets t)
|
||||||
|
(yas/verbosity 4)
|
||||||
|
(old-compiled-mtime (nth 5 (file-attributes compiled))))
|
||||||
|
(flet ((test-compiled-snippets-mtime ()
|
||||||
|
(sit-for 1)
|
||||||
|
(yas/reload-all t)
|
||||||
|
(should (file-readable-p compiled))
|
||||||
|
(let ((new-compiled-mtime (nth 5 (file-attributes compiled))))
|
||||||
|
(should (time-less-p old-compiled-mtime
|
||||||
|
new-compiled-mtime))
|
||||||
|
(setq old-compiled-mtime new-compiled-mtime))))
|
||||||
|
;; modify a snippet file
|
||||||
|
;;
|
||||||
|
(sit-for 1)
|
||||||
|
(with-current-buffer
|
||||||
|
(find-file-noselect ".emacs.d/snippets/c-mode/stupidsnippet")
|
||||||
|
(insert "something")
|
||||||
|
(save-buffer)
|
||||||
|
(kill-buffer))
|
||||||
|
(test-compiled-snippets-mtime)
|
||||||
|
;; delete a snippet file
|
||||||
|
;;
|
||||||
|
(delete-file ".emacs.d/snippets/c-mode/stupidsnippet")
|
||||||
|
(test-compiled-snippets-mtime)
|
||||||
|
;; add a snippet file
|
||||||
|
;;
|
||||||
|
(sit-for 1)
|
||||||
|
(with-current-buffer (find-file-noselect ".emacs.d/snippets/c-mode/anotherstupidsnippet")
|
||||||
|
(insert "blablabla")
|
||||||
|
(save-buffer)
|
||||||
|
(kill-buffer))
|
||||||
|
(test-compiled-snippets-mtime))))))
|
||||||
|
|
||||||
|
|
||||||
;;; Helpers
|
;;; Helpers
|
||||||
;;;
|
;;;
|
||||||
|
|
||||||
@ -238,7 +283,7 @@ TODO: correct this bug!"
|
|||||||
(when (>= emacs-major-version 23)
|
(when (>= emacs-major-version 23)
|
||||||
(delete-directory default-directory 'recursive))))))
|
(delete-directory default-directory 'recursive))))))
|
||||||
|
|
||||||
(defmacro with-snippet-dirs (dirs &rest body)
|
(defmacro yas/with-snippet-dirs (dirs &rest body)
|
||||||
`(yas/call-with-snippet-dirs ,dirs
|
`(yas/call-with-snippet-dirs ,dirs
|
||||||
#'(lambda ()
|
#'(lambda ()
|
||||||
,@body)))
|
,@body)))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user