Skip to content

Commit 65fcdf9

Browse files
committed
Let projects optionally restrict which files are used for which testing framework; can speed up testing in some cases when multiple frameworks are used.
1 parent bbb2add commit 65fcdf9

File tree

2 files changed

+74
-18
lines changed

2 files changed

+74
-18
lines changed

eldev.el

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,18 +3001,37 @@ Functions are called with SELECTORS as argument.
30013001

30023002
Since Eldev 0.2.")
30033003

3004+
(defvar eldev-test-ert-fileset nil
3005+
"Test files that contain project's ERT tests.
3006+
Only important if the project contains tests of different types.
3007+
3008+
Since Eldev 0.10.")
3009+
30043010
(defvar eldev-test-buttercup-hook nil
30053011
"Hook executed before running Buttercup tests.
30063012
Functions are called with SELECTORS as argument.
30073013

30083014
Since Eldev 0.2.")
30093015

3016+
(defvar eldev-test-buttercup-fileset nil
3017+
"Test files that contain project's Buttercup tests.
3018+
Only important if the project contains tests of different types.
3019+
3020+
Since Eldev 0.10.")
3021+
30103022
(defvar eldev-test-ecukes-hook nil
30113023
"Hook executed before running Ecukes tests.
30123024
Functions are called with SELECTORS as argument.
30133025

30143026
Since Eldev 0.10.")
30153027

3028+
(defvar eldev-test-ecukes-fileset nil
3029+
"Test files that contain project's Ecukes tests.
3030+
For Ecukes it's currently never important, since only this
3031+
framework uses `.feature' files.
3032+
3033+
Since Eldev 0.10.")
3034+
30163035
(defvar eldev--test-runners nil)
30173036

30183037
(defvar eldev-test-file-patterns nil
@@ -3172,9 +3191,19 @@ for details."
31723191
(used-by-frameworks (nth 0 (cdr entry)))
31733192
(file-description (nth 1 (cdr entry)))
31743193
(files (nth 2 (cdr entry)))
3175-
(files-looked-up (listp files)))
3194+
(files-looked-up (listp files))
3195+
framework-filesets
3196+
disregard-framework-filesets)
31763197
(unless files-looked-up
3177-
(setf files (eldev-find-and-trace-files `(:and ,(eldev-standard-fileset 'test) ,fileset) file-description))
3198+
(dolist (framework used-by-frameworks)
3199+
(let* ((variable (intern (format "eldev-test-%s-fileset" framework)))
3200+
(fileset (when (boundp variable) (symbol-value variable))))
3201+
(if fileset
3202+
(push fileset framework-filesets)
3203+
(setf disregard-framework-filesets t))))
3204+
(setf files (eldev-find-and-trace-files `(:and ,(eldev-standard-fileset 'test) ,fileset ,@(when (and framework-filesets (not disregard-framework-filesets))
3205+
`((:or ,(nreverse framework-filesets)))))
3206+
file-description))
31783207
(when filter-patterns
31793208
(setf files (eldev-filter-files files (reverse filter-patterns)))
31803209
(eldev-trace "%s" (eldev-message-enumerate-files (format "Remaining %s after applying `--file' filter(s): %%s (%%d)" file-description) files)))
@@ -3253,6 +3282,10 @@ for details."
32533282
(defun eldev--test-autoinstalling-framework (enabled callback)
32543283
;; If framework is specified explicitly, ensure it is installed first. Otherwise
32553284
;; appropriate framework will be installed from `require' advice below.
3285+
;;
3286+
;; FIXME: Why do we need this? Drawback example: when multiple frameworks are used
3287+
;; (since 0.10) and you explicitly test with only one, the second one also gets
3288+
;; installed because of the below code.
32563289
(when (and enabled eldev-test-framework)
32573290
(dolist (framework (eldev-listify eldev-test-framework))
32583291
(unless (eldev-test-get-framework-entry framework 'fileset)

test/integration/buttercup.el

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,51 @@
2020
;; `project-i' has two ERT and two Buttercup tests. Make sure that this combination works
2121
;; both in autodetermined and explicit ways.
2222

23-
(eldev-ert-defargtest eldev-test-buttercup-project-i-1 (command explicitly-configured)
24-
(('test nil)
25-
('test t)
26-
('test-ert nil)
27-
('test-ert t)
28-
('test-buttercup nil)
29-
('test-buttercup t))
30-
(eldev--test-run "project-i" (:eval `(,@(if explicitly-configured
31-
'("--setup" (setf eldev-test-framework '(ert buttercup)))
32-
'("--setup" (setf eldev-test-framework nil)))
33-
,command))
34-
;; Make sure that the exact tests executed match the issued command.
35-
(let ((ran-ert (string-match-p "Running 2 tests" stdout))
36-
(ran-buttercup (string-match-p "Running 2 specs" stdout))
37-
(ran-both (string-match-p "Testing summary: 4 test(s)" stdout)))
23+
(eldev-ert-defargtest eldev-test-buttercup-project-i-1 (command frameworks-configured with-ert-fileset)
24+
;; Test most combinations.
25+
(('test nil nil)
26+
('test t nil)
27+
('test t t)
28+
('test-ert nil nil)
29+
('test-ert nil t)
30+
('test-ert t nil)
31+
('test-ert t t)
32+
('test-buttercup nil nil)
33+
('test-buttercup t nil)
34+
('test-buttercup t t))
35+
(let ((eldev--test-project "project-i")
36+
testing
37+
ran-ert
38+
ran-buttercup
39+
ran-both)
40+
(eldev--test-delete-cache)
41+
(eldev--test-run nil ("--setup" `(setf eldev-test-framework ,(when frameworks-configured ''(ert buttercup)))
42+
"--setup" `(setf eldev-test-ert-fileset ,(when with-ert-fileset "ert.el"))
43+
command)
44+
(setf testing call-info)
45+
;; Make sure that the exact tests executed match the issued command.
46+
(setf ran-ert (string-match-p "Running 2 tests" stdout)
47+
ran-buttercup (string-match-p "Running 2 specs" stdout)
48+
ran-both (string-match-p "Testing summary: 4 test(s)" stdout))
3849
(pcase command
3950
(`test (should (and ran-ert ran-buttercup ran-both)))
4051
(`test-ert (should ran-ert)
4152
(should-not (or ran-buttercup ran-both)))
4253
(`test-buttercup (should ran-buttercup)
4354
(should-not (or ran-ert ran-both))))
44-
(should (= exit-code 0)))))
55+
(should (= exit-code 0)))
56+
;; Currently disabled, see comments in `eldev--test-autoinstalling-framework'. I
57+
;; don't want to change this now, not for a patch release. So, in this test Buttercup
58+
;; always gets installed if `frameworks-configured' is non-nil and we don't count that
59+
;; as a failure yet.
60+
(when nil
61+
(unless ran-buttercup
62+
;; If we run only ERT tests, Buttercup should not be even installed (depending on
63+
;; test parameters), thanks to setting variable `eldev-test-ert-fileset' above,
64+
;; which prevents the test file with form `(require 'buttercup)' from loading.
65+
(eldev--test-run nil ("version" "buttercup")
66+
:previous-call "Testing command" testing
67+
(should (= exit-code (if with-ert-fileset 1 0))))))))
4568

4669

4770
(ert-deftest eldev-test-buttercup-erroneous-backtrace-1 ()

0 commit comments

Comments
 (0)