Skip to content

Commit 1d68d61

Browse files
committed
Merge pull request #2289 from npostavs/ert-tests
Ert tests
2 parents 9a75a33 + 00e08b1 commit 1d68d61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+277
-169
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ install:
88
- prereqs
99
- '"$EMACS" --version'
1010
script:
11-
- byte-compile
11+
- folded_call byte-compile
12+
- folded_call ert-tests
1213
- check-recipes
1314
- check-whitespace

el-get-check.el

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
(require 'el-get-recipes)
2323
(require 'el-get-build)
2424

25+
(defvar warning-minimum-log-level)
26+
(defvar warning-minimum-level)
27+
(declare-function warning-numeric-level "warnings" (level))
28+
2529
(defvar el-get-check--last-file-or-buffer nil
2630
"The last file-or-buffer checked.")
2731

el-get-core.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ entry."
227227
((debug error)
228228
(error "Error reading file %s: %S" filename err))))
229229

230+
(defun el-get-package-is-installed (package)
231+
"Return true if PACKAGE is installed"
232+
(and (file-directory-p (el-get-package-directory package))
233+
(string= "installed"
234+
(el-get-read-package-status package))))
235+
236+
(defalias 'el-get-package-installed-p #'el-get-package-is-installed)
237+
230238

231239
;;
232240
;; Some tools

el-get-dependencies.el

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@
1616
(require 'el-get-core)
1717
(require 'el-get-recipes)
1818

19+
(eval-and-compile
20+
(unless (fboundp 'string-suffix-p) ; introduced in 24.4
21+
(defun string-suffix-p (suffix string &optional ignore-case)
22+
"Return non-nil if SUFFIX is a suffix of STRING.
23+
If IGNORE-CASE is non-nil, the comparison is done without paying
24+
attention to case differences."
25+
(let ((start-pos (- (length string) (length suffix))))
26+
(and (>= start-pos 0)
27+
(eq t (compare-strings suffix nil nil
28+
string start-pos nil ignore-case)))))))
1929
(defun el-get-dependencies (packages)
2030
"Return the list of packages to install in order."
2131
(multiple-value-bind (plist all-sorted-p non-sorted)
@@ -102,6 +112,9 @@ A `:minimum-emacs-version' property may also be present."
102112
(interactive (list (el-get-read-package-with-status "Auto-get dependencies of" "installed") t))
103113
(unless (el-get-package-installed-p package)
104114
(error "Tried to get Package-Requires of non-installed package, `%s'!" package))
115+
(eval-and-compile
116+
(require 'lisp-mnt) ; `lm-header'
117+
(require 'thingatpt)) ; `read-from-whole-string'
105118
(loop with deps and min-emacs and sub-pkgs
106119
for pdir in (el-get-load-path package)
107120
do (loop for file in (directory-files pdir t "\\.el\\'" t)

el-get.el

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,6 @@ package names."
239239
(unless (plist-member recipe :type)
240240
(error "el-get: package `%s' has incomplete recipe (no :type)" package))))
241241

242-
(defun el-get-package-is-installed (package)
243-
"Return true if PACKAGE is installed"
244-
(and (file-directory-p (el-get-package-directory package))
245-
(string= "installed"
246-
(el-get-read-package-status package))))
247-
248-
(defalias 'el-get-package-installed-p #'el-get-package-is-installed)
249-
250242
(defun el-get-read-package-name (action &optional filtered)
251243
"Ask user for a package name in minibuffer, with completion.
252244
@@ -589,11 +581,11 @@ PACKAGE may be either a string or the corresponding symbol."
589581

590582
(defun el-get-reload (package &optional package-status-alist)
591583
"Reload PACKAGE."
592-
(declare (advertised-calling-convention (package) "Feb 2015"))
593584
(interactive
594585
(progn
595586
(el-get-clear-status-cache)
596587
(list (el-get-read-package-with-status "Reload" "installed"))))
588+
(declare (advertised-calling-convention (package) "Feb 2015"))
597589
(el-get-verbose-message "el-get-reload: %s" package)
598590
(el-get-with-status-sources ()
599591
(let* ((all-features features)

test/README.md

Lines changed: 6 additions & 70 deletions

test/el-get-tests.el

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
(require 'el-get)
2+
(require 'ert nil t)
3+
4+
(eval-when-compile
5+
(require 'cl)
6+
(unless (featurep 'ert)
7+
(defmacro* ert-deftest (name () &body docstring-keys-and-body)
8+
(message "Skipping tests, ERT is not available"))))
9+
10+
(defvar el-get-test-output-buffer nil)
11+
(when noninteractive
12+
(defadvice message (around el-get-test-catch-output activate)
13+
"redirect all `message' output to `el-get-test-output-buffer'."
14+
(if el-get-test-output-buffer
15+
(with-current-buffer el-get-test-output-buffer
16+
(insert (apply #'format (ad-get-args 0)) "\n"))
17+
ad-do-it)))
18+
19+
(defconst el-get-test-files-dir
20+
(file-name-directory
21+
(or (eval-when-compile (bound-and-true-p byte-compile-file))
22+
load-file-name
23+
buffer-file-name)))
24+
25+
(defmacro el-get-with-temp-home (&rest body)
26+
"Evaluate BODY with a temporary `user-emacs-directory'.
27+
28+
In batch mode, `message' output is suppressed unless there is an
29+
error.
30+
31+
Following variables are bound to temporal values:
32+
* `user-emacs-directory'
33+
* `el-get-dir'
34+
* `el-get-status-file'
35+
* `el-get-status-cache'
36+
* `el-get-autoload-file'"
37+
(declare (debug t))
38+
`(let* ((user-emacs-directory
39+
(make-temp-file "emacs.d.el-get-testing" 'dir "/"))
40+
(el-get-dir (mapconcat #'file-name-as-directory
41+
`(,user-emacs-directory "el-get") ""))
42+
(el-get-status-file (concat el-get-dir ".status.el"))
43+
(el-get-status-cache nil)
44+
(el-get-autoload-file (concat el-get-dir ".loaddefs.el"))
45+
(el-get-test-output-buffer
46+
(when noninteractive (get-buffer-create "*el-get-test-output*"))))
47+
(unwind-protect
48+
(condition-case err
49+
(progn
50+
(make-directory el-get-dir t)
51+
,@body)
52+
(error (when el-get-test-output-buffer
53+
(with-current-buffer el-get-test-output-buffer
54+
(princ (buffer-string))))
55+
(signal (car err) (cdr err))))
56+
(let ((kill-buffer-query-functions nil))
57+
(dolist (buf (buffer-list))
58+
(with-current-buffer buf
59+
(when (string-prefix-p user-emacs-directory default-directory)
60+
(set-buffer-modified-p nil)
61+
(kill-buffer)))))
62+
(delete-directory user-emacs-directory t)
63+
(when el-get-test-output-buffer
64+
(kill-buffer el-get-test-output-buffer)))))
65+
66+
(ert-deftest el-get-recipe-dirs-test ()
67+
(let ((el-get-recipe-path
68+
`("/"
69+
,(let ((f "/foo"))
70+
(while (file-exists-p f)
71+
(setq f (concat f f))) f))))
72+
(should (equal (el-get-recipe-dirs)
73+
(loop for f in el-get-recipe-path
74+
when (file-exists-p f)
75+
collect f)))))
76+
77+
(ert-deftest el-get-trivial-install-test ()
78+
(el-get-with-temp-home
79+
(let* ((pkg 'el-get-test-package)
80+
(pkg-name (symbol-name pkg))
81+
(pkg-file (concat pkg-name ".el"))
82+
(pkg-source (expand-file-name
83+
pkg-file (concat el-get-test-files-dir "pkgs")))
84+
(pkg-destination (expand-file-name
85+
pkg-file (concat el-get-dir pkg-name)))
86+
(el-get-sources `((:name ,pkg
87+
:features (,pkg)
88+
:type http
89+
:url ,(concat "file://" pkg-source)))))
90+
(unwind-protect
91+
(progn
92+
(message "Checking %s is not loaded" pkg)
93+
(should-not (featurep pkg))
94+
(message "Installing %s" pkg)
95+
(should (progn (el-get 'sync pkg) t))
96+
(message "Verifying installed package file %s" pkg-destination)
97+
(should (file-exists-p pkg-destination))
98+
(should-not (zerop (nth 7 (file-attributes pkg-destination))))
99+
(message "Verifying package %s was loaded" pkg)
100+
(should (featurep pkg))
101+
(message "Unloading and removing package %s" pkg)
102+
(el-get-remove (symbol-name pkg))
103+
(message "Verifying package %s was unloaded and removed" pkg)
104+
(should-not (file-exists-p pkg-destination)))
105+
(when (featurep pkg)
106+
(unload-feature pkg))))))
107+
108+
(ert-deftest el-get-elpa-feature ()
109+
"`:features' option should work for ELPA type recipe."
110+
:expected-result :failed
111+
(el-get-with-temp-home
112+
(require 'package-x) ; create local package archive
113+
(let* ((pkg 'el-get-test-package)
114+
(package-archive-upload-base (expand-file-name "~/pkg-repo"))
115+
(package-archives nil)
116+
(el-get-sources
117+
`((:name package :post-init nil) ; avoid adding other repos
118+
(:name el-get-test-package
119+
:type elpa
120+
:repo ("test-repo" . ,package-archive-upload-base)
121+
:features el-get-test-package))))
122+
(make-directory package-archive-upload-base t)
123+
(package-upload-file (expand-file-name "pkgs/el-get-test-package.el"
124+
el-get-test-files-dir))
125+
(should-not (featurep pkg))
126+
(el-get 'sync (mapcar 'el-get-source-name el-get-sources))
127+
(should (featurep pkg)))))

test/issues/README.md

Lines changed: 73 additions & 0 deletions

0 commit comments

Comments
 (0)