Skip to content

Commit 251177d

Browse files
committed
When compiling or otherwise building project test files, also load test-specific dependencies.
1 parent 807ff5f commit 251177d

File tree

5 files changed

+38
-7
lines changed

5 files changed

+38
-7
lines changed

eldev-build.el

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,12 +381,14 @@ This function may only be called while inside the body of a
381381
(unless eldev-normal-dependency-management
382382
(setf dont-touch-packages t))
383383
(unless dont-touch-packages
384-
(let ((eldev-project-loading-mode 'as-is))
385-
;; FIXME: Is root injection actually needed here? It will also be done from the
386-
;; call to `eldev-build-find-targets' just a few lines below.
384+
(let ((eldev-project-loading-mode 'as-is)
385+
(extra-dependencies '(build)))
387386
(when (memq 'test (eldev--effective-standard-filesets eldev-build-sets))
387+
(push 'test extra-dependencies)
388+
;; FIXME: Is root injection actually needed here? It will also be done from the
389+
;; call to `eldev-build-find-targets' just a few lines below.
388390
(eldev--inject-loading-roots 'test))
389-
(eldev-load-project-dependencies 'build nil t)))
391+
(eldev-load-project-dependencies extra-dependencies nil t)))
390392
(let ((all-targets (apply #'eldev-build-find-targets (or eldev-build-sets '(main))))
391393
target-list
392394
target-fileset

test/compile.el

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,22 +72,34 @@
7272

7373
(eldev-ert-defargtest eldev-compile-test-files-1 (everything)
7474
(nil t)
75-
(eldev--test-without-files "project-a" (:eval `(,@(when everything '("project-a.elc")) "test/project-a.elc"))
75+
(eldev--test-without-files "project-a" ("project-a.elc" "test/project-a.elc")
7676
(eldev--test-run nil ("compile" "--set" (if everything "all" "test"))
7777
(eldev--test-assert-files project-dir preexisting-files (when everything "project-a.elc") "test/project-a.elc")
7878
(should (= exit-code 0)))))
7979

8080
(eldev-ert-defargtest eldev-compile-test-files-2 (everything)
8181
(nil t)
8282
;; This project has an additional loading root for tests.
83-
(eldev--test-without-files "project-g" (:eval `(,@(when everything '("project-g.elc" "project-g-util.elc"))
84-
"test/test-g-1.elc" "test/test-g-integration.elc" "test/test-g-util.elc"))
83+
(eldev--test-without-files "project-g" ("project-g.elc" "project-g-util.elc"
84+
"test/test-g-1.elc" "test/test-g-integration.elc" "test/test-g-util.elc")
8585
(eldev--test-run nil ("compile" "--set" (if everything "all" "test"))
8686
(eldev--test-assert-files project-dir preexisting-files
8787
(when everything '("project-g.elc" "project-g-util.elc"))
8888
"test/test-g-1.elc" "test/test-g-integration.elc" "test/test-g-util.elc")
8989
(should (= exit-code 0)))))
9090

91+
(eldev-ert-defargtest eldev-compile-test-files-3 (everything)
92+
(nil t)
93+
;; This project has an additional dependency for tests. It is needed not only to run,
94+
;; but also to compile them.
95+
(eldev--test-without-files "project-j" ("project-j-autoloads.el" "project-j.elc" "project-j-advanced.elc"
96+
"test/project-j.elc")
97+
(eldev--test-run nil ("compile" "--set" (if everything "all" "test"))
98+
(eldev--test-assert-files project-dir preexisting-files
99+
(when everything '("project-j-autoloads.el" "project-j.elc" "project-j-advanced.elc"))
100+
"test/project-j.elc")
101+
(should (= exit-code 0)))))
102+
91103

92104
(ert-deftest eldev-compile-doesnt-load-when-not-asked-1 ()
93105
;; `project-e-misc.el' is somewhat broken in that it cannot be

test/project-j/Eldev

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
(eldev-use-package-archive `("archive-a" . ,(expand-file-name "../package-archive-a")))
22

33
(eldev-use-plugin 'autoloads)
4+
5+
(eldev-add-extra-dependencies 'test 'dependency-a)

test/project-j/test/project-j.el

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
;; `dependency-a' is declared as an additional test-only dependency in this project's file `Eldev'.
2+
(require 'dependency-a)
3+
4+
(ert-deftest project-j-test-dependency ()
5+
(should (string= (dependency-a-hello) "Hello")))
6+
7+
(provide 'test/project-j)

test/test.el

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@
5353
(should (string-match-p "Ran 2 tests" stdout))
5454
(should (= exit-code 0))))
5555

56+
(ert-deftest eldev-test-project-j-1 ()
57+
;; Only one passing test. Most importantly, there is a test-only dependency in the
58+
;; project's file `Eldev' without which the test wouldn't run.
59+
(eldev--test-run "project-j" ("test")
60+
(should (string-match-p "passed.+project-j-test-dependency" stdout))
61+
(should (string-match-p "Ran 1 test" stdout))
62+
(should (= exit-code 0))))
63+
5664
(eldev-ert-defargtest eldev-test-project-l-1 (loading-mode)
5765
('source 'byte-compiled 'packaged)
5866
;; Project with special source directories. One of the tests needs a resource located

0 commit comments

Comments
 (0)