Skip to content

Commit

Permalink
Fix a bug in combination of a single source directory and any plugin;…
Browse files Browse the repository at this point in the history
… add more tests.
  • Loading branch information
doublep committed Nov 16, 2023
1 parent 2aefc4d commit 5f8889e
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 2 deletions.
2 changes: 1 addition & 1 deletion eldev-plugins.el
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Since 0.3."
;; Autoloads.

(defun eldev--autoloads-source-dir ()
(if eldev-project-source-dirs (file-name-as-directory (car eldev-project-source-dirs)) ""))
(if eldev-project-source-dirs (file-name-as-directory (car (eldev-listify eldev-project-source-dirs))) ""))

(defvar eldev--collect-autoloads-from
;; FIXME: Here we explicitly use only one (the first) source directory. Should that be
Expand Down
17 changes: 17 additions & 0 deletions test/autoloads.el
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,28 @@
(ert-deftest eldev-autoloads-6 ()
;; This project has special source directories and activates `autoloads' plugin.
(let ((eldev--test-project "project-l"))
(eldev--test-delete-cache)
(eldev--test-run nil ("eval" "--dont-require" `(project-l-hello))
(should (string= stdout "\"Hello\"\n"))
(should (= exit-code 0)))
(eldev--test-run nil ("eval" "--dont-require" `(project-l-misc-hello))
(should (string= stdout "\"Hello\"\n"))
(should (= exit-code 0)))
;; It's a dependency of the project, and also has autoloaded functions.
(eldev--test-run nil ("eval" "--dont-require" `(dependency-d-autoloaded) `(dependency-d-stable))
(should (string= stdout (eldev--test-lines "\"Loaded automatically\"" "t")))
(should (= exit-code 0)))
;; Make sure this works also with local dependencies.
(eldev--test-run nil ("--setup" `(eldev-use-local-dependency "../dependency-d")
"eval" "--dont-require" `(dependency-d-autoloaded) `(dependency-d-stable))
(should (string= stdout (eldev--test-lines "\"Loaded automatically\"" "nil")))
(should (= exit-code 0)))))

(ert-deftest eldev-autoloads-7 ()
;; This dependency library has a special source directory and activates `autoloads' plugin.
(let ((eldev--test-project "dependency-d"))
(eldev--test-run nil ("eval" "--dont-require" `(dependency-d-autoloaded))
(should (string= stdout "\"Loaded automatically\"\n"))
(should (= exit-code 0)))))


Expand Down
1 change: 1 addition & 0 deletions test/dependency-d/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/lisp/dependency-d-autoloads.el
3 changes: 3 additions & 0 deletions test/dependency-d/Eldev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
(setf eldev-project-source-dirs "lisp")

(eldev-use-plugin 'autoloads)
17 changes: 17 additions & 0 deletions test/dependency-d/lisp/dependency-d.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
;;; dependency-d.el --- Dependency test package D with a special source directory

;; Version: 1.0.99

(defun dependency-d-hello ()
"Hello")

(defun dependency-d-stable ()
nil)

;;;###autoload
(defun dependency-d-autoloaded ()
"Loaded automatically")

(provide 'dependency-d)

;;; dependency-d.el ends here
17 changes: 17 additions & 0 deletions test/local-dependencies.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@
(should (string= stdout (eldev--test-lines "t" "t" "(1 0)" "(1 0)")))
(should (= exit-code 0)))))

(ert-deftest eldev-local-dependencies-3 ()
(let ((eldev--test-project "project-l"))
(eldev--test-delete-cache)
;; `dependency-d' uses a source directory. Make sure it is handled correctly when it
;; is loaded as a local. Explicitly requiring the dependency feature since the
;; project doesn't do that for autoload testing.
(eldev--test-run nil ("--quiet" "eval" `(progn (require 'dependency-d) (dependency-d-stable)) `(package-desc-version (eldev-find-package-descriptor 'dependency-d)))
(should (string= stdout (eldev--test-lines "t" "(1 0)")))
(should (= exit-code 0)))
(eldev--test-run nil ("--setup" `(eldev-use-local-dependency "../dependency-d")
"eval" `(progn (require 'dependency-d) (dependency-d-stable)) `(package-desc-version (eldev-find-package-descriptor 'dependency-d)))
(should (string= stdout (eldev--test-lines "nil" "(1 0 99)")))
(should (= exit-code 0)))
(eldev--test-run nil ("--quiet" "eval" `(progn (require 'dependency-d) (dependency-d-stable)) `(package-desc-version (eldev-find-package-descriptor 'dependency-d)))
(should (string= stdout (eldev--test-lines "t" "(1 0)")))
(should (= exit-code 0)))))


(ert-deftest eldev-local-dependency-fixes-missing-dependency-1 ()
(eldev--test-run "dependency-a" ("clean")
Expand Down
1 change: 1 addition & 0 deletions test/package-archive-a/archive-contents
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(1
(dependency-a . [(1 0) nil "Dependency test package A" single nil])
(dependency-b . [(1 0) ((dependency-a (0))) "Dependency test package B" single nil])
(dependency-d . [(1 0) nil "Dependency test package D with a special source directory" single nil])
(dummy-lint . [(1 0) nil "Dummy linter" single nil])
(misc-a . [(1 0) nil "Miscellaneous package A" single nil])
(project-i . [(1 0) nil "Test project with autoload cookies in multiple files" tar nil])
Expand Down
17 changes: 17 additions & 0 deletions test/package-archive-a/dependency-d-1.0.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
;;; dependency-d.el --- Dependency test package D with a special source directory

;; Version: 1.0

(defun dependency-d-hello ()
"Hello")

(defun dependency-d-stable ()
t)

;;;###autoload
(defun dependency-d-autoloaded ()
"Loaded automatically")

(provide 'dependency-d)

;;; dependency-d.el ends here
2 changes: 1 addition & 1 deletion test/project-l/src/project-l.el
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
;;; project-l.el --- Test project where source code is contained in a subdirectory of project root; and with autoloads

;; Version: 1.0
;; Package-Requires: ((dependency-a "0.1"))
;; Package-Requires: ((dependency-a "0.1") (dependency-d "1.0"))
;; Homepage: https://example.com/

;;; Commentary:
Expand Down

0 comments on commit 5f8889e

Please sign in to comment.