From 57350a3b4872a92c41c9b944635621951aab2b08 Mon Sep 17 00:00:00 2001 From: syl20bnr Date: Mon, 20 Jun 2016 20:48:25 -0400 Subject: [PATCH] core: reimplement :packages keyword and update documentation Old implementation excluded package that were not selected, this implementation does not excluded them, it simply ignore it in the layer where they are not selected. This reimplementation comes from a refactor of the way packages.el files are loaded, instead of loading these files at the moment of resolving the list of used packages, they are now loaded when making the layer objects. A neat consequence is that side effects is better confined and the configuration-layer/get-packages is now pure (at least a lot more pure than before). In the `cfgl-layer` class the slot `:user-packages` has been renamed to `:selected-packages` which defaults to `'all` meaning that all the packages in `:packages` are selected. `:selected-packages` value is given by the new function `configuration-layer//select-packages`. Effectively selected packages are given by a new method for `cfgl-layer` class called `cfgl-layer-get-packages`. Tests have been updated to reflect the changes. Also documentation on configuration layer declaration in the dotfile section of DOCUMENTATION.org has been greatly improved (I hope) and reflect the last feature added to the `dotspacemacs-configuration-layers` list. --- core/core-configuration-layer.el | 194 ++++--- doc/DOCUMENTATION.org | 162 ++++-- tests/core/core-configuration-layer-ftest.el | 13 +- tests/core/core-configuration-layer-utest.el | 560 ++++++++++++------- 4 files changed, 584 insertions(+), 345 deletions(-) diff --git a/core/core-configuration-layer.el b/core/core-configuration-layer.el index 78bc1e808..519b4b0fe 100644 --- a/core/core-configuration-layer.el +++ b/core/core-configuration-layer.el @@ -64,10 +64,11 @@ :initform nil :type list :documentation "List of package symbols declared in this layer.") - (user-packages :initarg :user-packages - :initform nil - :type list - :documentation "List of package symbols declared by user.") + (selected-packages :initarg :selected-packages + :initform 'all + :type (satisfies (lambda (x) (or (and (symbolp x) (eq 'all x)) + (listp x)))) + :documentation "List of selected package symbols.") (variables :initarg :variables :initform nil :type list @@ -97,6 +98,16 @@ LAYER has to be installed for this method to work properly." "Accept nil as argument and return nil." nil) +(defmethod cfgl-layer-get-packages ((layer cfgl-layer)) + "Return the list of packages for LAYER." + (if (eq 'all (oref layer :selected-packages)) + (oref layer :packages) + (delq nil (mapcar + (lambda (x) + (let ((pkg-name (if (listp x) (car x) x))) + (when (memq pkg-name (oref layer :selected-packages)) x))) + (oref layer :packages))))) + (defclass cfgl-package () ((name :initarg :name :type symbol @@ -155,8 +166,7 @@ LAYER has to be installed for this method to work properly." ;; Note: for packages in `configuration-layer--packages' the owner is always ;; the car of the `:owners' slot. ;; An example where it is not necessarily the case is in - ;; `helm-spacemacs-help-all-packages' which we can find in the helm - ;; layer. + ;; `helm-spacemacs-help-all-packages' in the helm layer. ;; For performance reason `cfgl-package-get-safe-owner' is not used in the ;; layer system itself. This functions should be only used outside of the ;; system in order to safely get the true owner of a layer. @@ -413,6 +423,29 @@ layer directory." (configuration-layer//copy-template name "README.org" layer-dir)) (message "Configuration layer \"%s\" successfully created." name))))) +(defun configuration-layer//select-packages (layer packages) + "Return the selected packages for LAYER from given PACKAGES list." + (let* ((value (when (listp layer) (spacemacs/mplist-get layer :packages))) + (selected-packages (if (and (not (null (car value))) + (listp (car value))) + (car value) + value))) + (cond + ;; select packages + ((and selected-packages + (not (memq (car selected-packages) '(all not)))) + selected-packages) + ;; unselect packages + ((and selected-packages + (eq 'not (car selected-packages))) + (delq nil (mapcar (lambda (x) + (let ((pkg-name (if (listp x) (car x) x))) + (unless (memq pkg-name selected-packages) + pkg-name))) + packages))) + ;; no package selections or all package selected + (t 'all)))) + (defun configuration-layer/make-layer (layer) "Return a `cfgl-layer' object based on LAYER." (let* ((name-sym (if (listp layer) (car layer) layer)) @@ -421,18 +454,23 @@ layer directory." (disabled (when (listp layer) (spacemacs/mplist-get layer :disabled-for))) (variables (when (listp layer) - (spacemacs/mplist-get layer :variables))) - (user-packages (when (listp layer) - (car-safe - (spacemacs/mplist-get layer :packages))))) + (spacemacs/mplist-get layer :variables)))) (if base-dir - (let* ((dir (format "%s%s/" base-dir name-str))) + (let* ((dir (format "%s%s/" base-dir name-str)) + (packages-file (concat dir "packages.el")) + (packages + (when (file-exists-p packages-file) + (load packages-file) + (symbol-value (intern (format "%S-packages" name-sym))))) + (selected-packages (configuration-layer//select-packages + layer packages))) (cfgl-layer name-str :name name-sym :dir dir :disabled-for disabled :variables variables - :user-packages user-packages)) + :packages packages + :selected-packages selected-packages)) (configuration-layer//warning "Cannot find layer %S !" name-sym) nil))) @@ -664,85 +702,61 @@ no-op." (defun configuration-layer/get-packages (layers &optional dotfile) "Read the package lists of LAYERS and dotfile and return a list of packages." (dolist (layer layers) - (let* ((layer-name (oref layer :name)) - (layer-dir (oref layer :dir)) - (include-packages - (when (and (oref layer :user-packages) - (not (eq 'not (car (oref layer :user-packages))))) - (oref layer :user-packages))) - (exclude-packages - (when (and (oref layer :user-packages) - (eq 'not (car (oref layer :user-packages)))) - (cdr (oref layer :user-packages)))) - (packages-file (concat layer-dir "packages.el"))) - ;; packages - (when (file-exists-p packages-file) - ;; required for lazy-loading of unused layers - ;; for instance for helm-spacemacs-help - (eval `(defvar ,(intern (format "%S-packages" layer-name)) nil)) - (load packages-file) - (dolist (pkg (symbol-value (intern (format "%S-packages" - layer-name)))) - (let* ((pkg-name (if (listp pkg) (car pkg) pkg)) - (init-func (intern (format "%S/init-%S" - layer-name pkg-name))) - (pre-init-func (intern (format "%S/pre-init-%S" - layer-name pkg-name))) - (post-init-func (intern (format "%S/post-init-%S" - layer-name pkg-name))) - (ownerp (fboundp init-func)) - (obj (object-assoc pkg-name - :name configuration-layer--packages)) - (excluded (or (and include-packages - (not (memq pkg-name include-packages))) - (and exclude-packages - (memq pkg-name exclude-packages))))) - (cl-pushnew pkg-name (oref layer :packages)) - (if obj - (setq obj (configuration-layer/make-package pkg obj ownerp)) - (setq obj (configuration-layer/make-package pkg nil ownerp)) - (when excluded - (oset obj :excluded t)) - (push obj configuration-layer--packages)) - (when ownerp - ;; last owner wins over the previous one, - ;; still warn about mutliple owners - (when (and (oref obj :owners) - (not (memq layer-name (oref obj :owners)))) - (configuration-layer//warning - (format (concat "More than one init function found for " - "package %S. Previous owner was %S, " - "replacing it with layer %S.") - pkg-name (car (oref obj :owners)) layer-name))) - (push layer-name (oref obj :owners))) - ;; if no function at all is found for the package, then check - ;; again this layer later to resolve `package-usedp' usage in - ;; `packages.el' files - (unless (or ownerp - (fboundp pre-init-func) - (fboundp post-init-func) - (oref obj :excluded)) - (unless (object-assoc layer-name :name - configuration-layer--delayed-layers) - (configuration-layer//warning - (format (concat "package %s not initialized in layer %s, " - "you may consider removing this package from " - "the package list or use the :toggle keyword " - "instead of a `when' form.") - pkg-name layer-name)) - (push layer configuration-layer--delayed-layers))) - ;; check if toggle can be applied - (when (and (not ownerp) - (listp pkg) - (spacemacs/mplist-get pkg :toggle)) + (let ((layer-name (oref layer :name))) + (dolist (pkg (cfgl-layer-get-packages layer)) + (let* ((pkg-name (if (listp pkg) (car pkg) pkg)) + (init-func (intern (format "%S/init-%S" + layer-name pkg-name))) + (pre-init-func (intern (format "%S/pre-init-%S" + layer-name pkg-name))) + (post-init-func (intern (format "%S/post-init-%S" + layer-name pkg-name))) + (ownerp (fboundp init-func)) + (obj (object-assoc pkg-name + :name configuration-layer--packages))) + (if obj + (setq obj (configuration-layer/make-package pkg obj ownerp)) + (setq obj (configuration-layer/make-package pkg nil ownerp)) + (push obj configuration-layer--packages)) + (when ownerp + ;; last owner wins over the previous one, + ;; still warn about mutliple owners + (when (and (oref obj :owners) + (not (memq layer-name (oref obj :owners)))) (configuration-layer//warning - (format (concat "Ignoring :toggle for package %s because " - "layer %S does not own it.") - pkg-name layer-name))) - (when (fboundp pre-init-func) - (push layer-name (oref obj :pre-layers))) - (when (fboundp post-init-func) - (push layer-name (oref obj :post-layers)))))))) + (format (concat "More than one init function found for " + "package %S. Previous owner was %S, " + "replacing it with layer %S.") + pkg-name (car (oref obj :owners)) layer-name))) + (push layer-name (oref obj :owners))) + ;; if no function at all is found for the package, then check + ;; again this layer later to resolve `package-usedp' usage in + ;; `packages.el' files + (unless (or ownerp + (fboundp pre-init-func) + (fboundp post-init-func) + (oref obj :excluded)) + (unless (object-assoc layer-name :name + configuration-layer--delayed-layers) + (configuration-layer//warning + (format (concat "package %s not initialized in layer %s, " + "you may consider removing this package from " + "the package list or use the :toggle keyword " + "instead of a `when' form.") + pkg-name layer-name)) + (push layer configuration-layer--delayed-layers))) + ;; check if toggle can be applied + (when (and (not ownerp) + (listp pkg) + (spacemacs/mplist-get pkg :toggle)) + (configuration-layer//warning + (format (concat "Ignoring :toggle for package %s because " + "layer %S does not own it.") + pkg-name layer-name))) + (when (fboundp pre-init-func) + (push layer-name (oref obj :pre-layers))) + (when (fboundp post-init-func) + (push layer-name (oref obj :post-layers))))))) ;; additional and excluded packages from dotfile (when dotfile (dolist (pkg dotspacemacs-additional-packages) diff --git a/doc/DOCUMENTATION.org b/doc/DOCUMENTATION.org index 125e012b8..a221c0ce1 100644 --- a/doc/DOCUMENTATION.org +++ b/doc/DOCUMENTATION.org @@ -39,11 +39,13 @@ - [[#synchronization-of-dotfile-changes][Synchronization of dotfile changes]] - [[#testing-the-dotfile][Testing the dotfile]] - [[#dotfile-contents][Dotfile Contents]] - - [[#using-configuration-layers][Using configuration layers]] - - [[#setting-configuration-layers-variables][Setting configuration layers variables]] - - [[#excluding-packages][Excluding packages]] - [[#configuration-functions][Configuration functions]] - [[#custom-variables][Custom variables]] + - [[#declaring-configuration-layers][Declaring Configuration layers]] + - [[#setting-configuration-layers-variables][Setting configuration layers variables]] + - [[#disabling-layer-services-in-other-layers][Disabling layer services in other layers]] + - [[#selectingignoring-packages-of-a-layer][Selecting/Ignoring packages of a layer]] + - [[#excluding-packages][Excluding packages]] - [[#concepts][Concepts]] - [[#editing-styles][Editing Styles]] - [[#vim][Vim]] @@ -534,21 +536,54 @@ declared layers can be found and that the variables have sensible values. These tests are also run automatically when you synchronize with ~SPC f e R~. ** Dotfile Contents -*** Using configuration layers -To use a configuration layer, add it to the =dotspacemacs-configuration-layers= -variable of your =~/.spacemacs=. +*** Configuration functions +Three special functions in the =~/.spacemacs= file can be used to perform +configuration at the beginning and end of Spacemacs loading process: + +- =dotspacemacs/layers= is called at the very startup of Spacemacs initilialization, + this is where you set the Spacemacs distribution and declare layers to be used + in your configuration. You can also add or excluded packages of your choice + and tweak some behavior of Spacemacs loading. +- =dotspacemacs/init= is called at the very startup of Spacemacs initialization + before layers configuration. *You should not put any user code* in there + besides modifying the Spacemacs variable values prefixed with =dotspacemacs-=. +- =dotspacemacs/user-init= is called immediately after =dotspacemacs/init=, + before layer configuration. This function is mostly useful for variables + that need to be set before packages are loaded. +- =dotspacemacs/user-config= is called at the very end of Spacemacs + initialization after layers configuration. This is the place where most of + your configurations should be done. Unless it is explicitly specified that a + variable should be set before a package is loaded, you should place your code + here. + +*** Custom variables +Custom variables configuration from =M-x customize-group= built-in Emacs feature +are automatically saved by Emacs at the end of your =~/.spacemacs= file. + +** Declaring Configuration layers +To use a configuration layer, declare it in your dotfile by adding it to the +=dotspacemacs-configuration-layers= variable of your =~/.spacemacs=. + +*Note:* In this documentation a =used layer= is equivalent to a =declared +layer=. For instance, [[Thank you][RMS]] can add his private configuration layer like this: #+BEGIN_SRC emacs-lisp -(setq-default dotspacemacs-configuration-layers '(rms)) +(setq-default dotspacemacs-configuration-layers + '( + ;; other layers + ;; rms layer added at the end of the list + rms + )) #+END_SRC -Configuration layers are expected to be stored in =~/.emacs.d/private= or -=~/.emacs.d/layers=. But you are free to keep them somewhere else by declaring -additional paths where Spacemacs can look for configuration layers. This is -done by setting the list =dotspacemacs-configuration-layer-path= in your -=~/.spacemacs=: +Official layers shipped with Spacemacs are stored in =~/.emacs.d/layers=. The +directory =~/.emacs.d/private= is a drop-in location for your private layers. +It is possible to put layers at the location of your choice provided you tell +Spacemacs where to look for them. This is done by setting the list +=dotspacemacs-configuration-layer-path= in your =~/.spacemacs=. For instance +to add some layers in =~/.myconfig=, set the variable like this: #+BEGIN_SRC emacs-lisp (setq-default dotspacemacs-configuration-layer-path '("~/.myconfig/")) @@ -562,29 +597,70 @@ can be set directly in the =dotspacemacs-configuration-layers= like this: #+BEGIN_SRC emacs-lisp (defun dotspacemacs/layers () ;; List of configuration layers to load. - (setq-default dotspacemacs-configuration-layers '(auto-completion - (git :variables - git-magit-status-fullscreen t) - smex))) + (setq-default dotspacemacs-configuration-layers + '(auto-completion + (git :variables + git-magit-status-fullscreen t + git-variable-example nil) + smex))) #+END_SRC -*** Selecting packages on a per layer basis -The packages loaded within the layer can be selected on a per package basis with -the =:packages= property. Following the =:packages= declaration in a layer -declaration, the user can provide a list of packages to initialize which are -defined in that layer. All other packages defined will not be loaded. -Alternatively, when the =:packages= declaration list is preceeded with a =not= -the included packages will not be excluded from loading. - +The =:variables= keyword is a convenience to keep layer configuration close to +their declaration. Setting layer variables in the =dotspacemacs/user-init= +function of your dotfile is also a perfectly valid way to configure a layer. + +*** Disabling layer services in other layers +Often layers enable services that other layers can use. For instance if you use +the layer =auto-completion= then every other layers supporting =auto-completion= +will have this feature enabled. + +Sometimes you may want to disable a service added by a layer in some specific +layers. Say you want to disable =auto-completion= in =org= and =git= layers, +you can do it with the following layer declaration. + #+BEGIN_SRC emacs-lisp (defun dotspacemacs/layers () ;; List of configuration layers to load. - (setq-default dotspacemacs-configuration-layers '(auto-completion - (spacemacs-ui-visual - :packages (not neotree)))) + (setq-default dotspacemacs-configuration-layers + '(org + (auto-completion :disabled-for org git)))) #+END_SRC -*** Excluding packages globally +*** Selecting/Ignoring packages of a layer +By default a declared layer installs/configures all its associated packages. You +may want to select only some of them or ignoring some of them. This is possible +with the =:packages= keyword. + +For instance to ignore the =neotree= and =fancy-battery= packages from +=spacemacs-ui-visual= layer: + +#+BEGIN_SRC emacs-lisp +(defun dotspacemacs/layers () + ;; List of configuration layers to load. + (setq-default dotspacemacs-configuration-layers + '(auto-completion + (spacemacs-ui-visual :packages (not neotree fancy-battery)))) +#+END_SRC + +The opposite would be to ignore all packages except =neotree= and +=fancy-battery=: + +#+BEGIN_SRC emacs-lisp +(defun dotspacemacs/layers () + ;; List of configuration layers to load. + (setq-default dotspacemacs-configuration-layers + '(auto-completion + (spacemacs-ui-visual :packages neotree fancy-battery))) +#+END_SRC + +*Note:* Ignoring a package from a layer is different than excluding a package. +An excluded packages is completely removed from your configuration whereas an +ignored package is ignored only for a given layer but it can remain on your +system. It happens that if the given layer is the owner of the package then +ignoring this package is the same as excluding it (because the package becomes +orphan so it is considered unused by Spacemacs). + +*** Excluding packages You can exclude packages you don't want to install with the variable =dotspacemacs-excluded-packages= (see [[Configuration layers][Configuration layers]] for more info on packages). @@ -596,28 +672,16 @@ For instance, to disable the =rainbow-delimiters= package: #+END_SRC When you exclude a package, Spacemacs will automatically delete it for you the -next time you launch Emacs. All the orphan dependencies are also deleted -automatically. +next time you launch Emacs or at the next dotfile synchronization. All the +orphan dependencies are also deleted automatically. Excluding a package +effectively remove _all_ references to it in Spacemacs without breaking the rest +of the configuration, this is a powerful feature which allows you to quickly +remove any feature from Spacemacs. -*** Configuration functions -Three special functions in the =~/.spacemacs= file can be used to perform -configuration at the beginning and end of Spacemacs loading process: - -- =dotspacemacs/init= is called at the very startup of Spacemacs initialization - before layers configuration. You should not put any user code in there - besides modifying the Spacemacs variable values. -- =dotspacemacs/user-init= is called immediately after =dotspacemacs/init=, - before layer configuration executes. This function is mostly useful for - variables that need to be set before packages are loaded. -- =dotspacemacs/user-config= is called at the very end of Spacemacs - initialization after layers configuration. This is the place where most of - your configurations should be done. Unless it is explicitly specified that a - variable should be set before a package is loaded, you should place you code - here. - -*** Custom variables -Custom variables configuration from =M-x customize-group= which are -automatically saved by Emacs are stored at the end of your =~/.spacemacs= file. +*Note:* A few packages are essential for Spacemacs to correctly operate, those +packages are protected and cannot be excluded or unsintalled even if they become +orphans or are excluded. =use-package= is an example of a protected package that +cannot be removed from Spacemacs. * Concepts ** Editing Styles diff --git a/tests/core/core-configuration-layer-ftest.el b/tests/core/core-configuration-layer-ftest.el index dbeebec42..f5208f468 100644 --- a/tests/core/core-configuration-layer-ftest.el +++ b/tests/core/core-configuration-layer-ftest.el @@ -17,14 +17,11 @@ (ert-deftest test-declare-layers--bootstrap-layer-always-first () (let ((dotspacemacs-distribution 'spacemacs) (dotspacemacs-configuration-layers '(emacs-lisp - (git :variables foo 'bar))) - (mocker-mock-default-record-cls 'mocker-stub-record)) - (mocker-let - ((load (f) ((:output nil)))) - (let (configuration-layer--layers) - (configuration-layer//declare-layers) - (should (eq 'spacemacs-bootstrap - (oref (first configuration-layer--layers) :name))))))) + (git :variables foo 'bar)))) + (let (configuration-layer--layers) + (configuration-layer//declare-layers) + (should (eq 'spacemacs-bootstrap + (oref (first configuration-layer--layers) :name)))))) (ert-deftest test-declare-layers--distribution-layer-is-second () (let ((dotspacemacs-distribution 'spacemacs-base) diff --git a/tests/core/core-configuration-layer-utest.el b/tests/core/core-configuration-layer-utest.el index b8523adac..84417762e 100644 --- a/tests/core/core-configuration-layer-utest.el +++ b/tests/core/core-configuration-layer-utest.el @@ -16,6 +16,8 @@ ;; class cfgl-layer ;; --------------------------------------------------------------------------- +;; method: cfgl-layer-owned-packages + (ert-deftest test-cfgl-layer-owned-packages--owns-packages () (let ((layer1 (cfgl-layer "layer1" :name 'layer1 @@ -32,6 +34,60 @@ (ert-deftest test-cfgl-layer-owned-packages--nil-layer-returns-nil () (should (null (cfgl-layer-owned-packages nil)))) +;; method: cfgl-layer-get-packages + +(ert-deftest test-cfgl-layer-get-packages--all-packages-selected-default () + (let ((layer (cfgl-layer "layer" + :name 'layer + :packages '((pkg1 :location local) + pkg2 + (pkg3 :location built-in))))) + (should (equal '((pkg1 :location local) pkg2 (pkg3 :location built-in)) + (cfgl-layer-get-packages layer))))) + +(ert-deftest test-cfgl-layer-get-packages--all-packages-selected-explicitly () + (let ((layer (cfgl-layer "layer" + :name 'layer + :packages '((pkg1 :location local) + pkg2 + (pkg3 :location built-in)) + :selected-packages 'all))) + (should (equal '((pkg1 :location local) pkg2 (pkg3 :location built-in)) + (cfgl-layer-get-packages layer))))) + +(ert-deftest test-cfgl-layer-get-packages--selected-packages () + (let ((layer (cfgl-layer "layer" + :name 'layer + :packages '((pkg1 :location local) + pkg2 + (pkg3 :location built-in)) + :selected-packages '(pkg1 pkg2)))) + (should (equal '((pkg1 :location local) pkg2) + (cfgl-layer-get-packages layer))))) + +(ert-deftest test-cfgl-layer-get-packages--selected-packages-ignore-unknown () + (let ((layer (cfgl-layer "layer" + :name 'layer + :packages '((pkg1 :location local) + pkg2 + (pkg3 :location built-in)) + :selected-packages '(pkg1 pkg2 pkg-unknown)))) + (should (equal '((pkg1 :location local) pkg2) + (cfgl-layer-get-packages layer))))) + +(ert-deftest test-cfgl-layer-get-packages--nil-packages-return-nil () + (let ((layer (cfgl-layer "layer" + :name 'layer + :packages '()))) + (should (null (cfgl-layer-get-packages layer))))) + +(ert-deftest test-cfgl-layer-get-packages--nil-packages-with-unknown-selected-packages-return-nil () + (let ((layer (cfgl-layer "layer" + :name 'layer + :packages '() + :selected-packages '(pkg-unknown)))) + (should (null (cfgl-layer-get-packages layer))))) + ;; --------------------------------------------------------------------------- ;; class cfgl-package ;; --------------------------------------------------------------------------- @@ -148,6 +204,47 @@ ((symbol-function 'message) 'ignore)) (configuration-layer/retrieve-package-archives)))) +;; --------------------------------------------------------------------------- +;; configuration-layer//select-packages +;; --------------------------------------------------------------------------- + +(ert-deftest test-select-packages--all-is-default () + (let ((layer '(layer :variables var1 t var2 t)) + (packages '((pkg1 :location local) pkg2))) + (should (eq 'all (configuration-layer//select-packages layer packages))))) + +(ert-deftest test-select-packages--all-returns-all () + (let ((layer '(layer :variables var1 t var2 t :packages all)) + (packages '((pkg1 :location local) pkg2))) + (should (eq 'all (configuration-layer//select-packages layer packages))))) + +(ert-deftest test-select-packages--select-packages () + (let ((layer '(layer :variables var1 t var2 t :packages pkg1 pkg3)) + (packages '((pkg1 :location local) + pkg2 + pkg3 + (pkg4 :location built-in)))) + (should (equal '(pkg1 pkg3) + (configuration-layer//select-packages layer packages))))) + +(ert-deftest test-select-packages--unselect-packages-with-a-list () + (let ((layer '(layer :variables var1 t var2 t :packages (not pkg1 pkg3))) + (packages '((pkg1 :location local) + pkg2 + pkg3 + (pkg4 :location built-in)))) + (should (equal '(pkg2 pkg4) + (configuration-layer//select-packages layer packages))))) + +(ert-deftest test-select-packages--unselect-packages-without-a-list () + (let ((layer '(layer :variables var1 t var2 t :packages not pkg1 pkg3)) + (packages '((pkg1 :location local) + pkg2 + pkg3 + (pkg4 :location built-in)))) + (should (equal '(pkg2 pkg4) + (configuration-layer//select-packages layer packages))))) + ;; --------------------------------------------------------------------------- ;; configuration-layer//make-layers ;; --------------------------------------------------------------------------- @@ -351,77 +448,71 @@ ;; --------------------------------------------------------------------------- (ert-deftest test-get-packages--symbols-only () - (let* ((layer1 (cfgl-layer "layer1" :name 'layer1 :dir "/path/")) - (layers (list layer1)) - (layer1-packages '(pkg1 pkg2 pkg3)) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (let* ((layer1 (cfgl-layer "layer1" + :name 'layer1 + :dir "/path/" + :packages '(pkg1 pkg2 pkg3))) + (layers (list layer1))) (defun layer1/init-pkg1 nil) (defun layer1/init-pkg2 nil) (defun layer1/init-pkg3 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 1))) - (load (f) ((:output nil :occur 1)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers) - (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer1)) - (cfgl-package "pkg2" :name 'pkg2 :owners '(layer1)) - (cfgl-package "pkg1" :name 'pkg1 :owners '(layer1))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer1)) + (cfgl-package "pkg2" :name 'pkg2 :owners '(layer1)) + (cfgl-package "pkg1" :name 'pkg1 :owners '(layer1))) + configuration-layer--packages))))) (ert-deftest test-get-packages--lists-only () - (let* ((layer1 (cfgl-layer "layer1" :name 'layer1 :dir "/path/")) - (layers (list layer1)) - (layer1-packages '((pkg1 :location elpa :excluded t) - (pkg2 :location (recipe blahblah)) - (pkg3 :location local :step pre))) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (let* ((layer1 (cfgl-layer "layer1" + :name 'layer1 + :dir "/path/" + :packages '((pkg1 :location elpa :excluded t) + (pkg2 :location (recipe blahblah)) + (pkg3 :location local :step pre)))) + (layers (list layer1))) (defun layer1/init-pkg1 nil) (defun layer1/init-pkg2 nil) (defun layer1/init-pkg3 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 1))) - (load (f) ((:output nil :occur 1)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers) - (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer1) :location 'local :step 'pre) - (cfgl-package "pkg2" :name 'pkg2 :owners '(layer1) :location '(recipe blahblah)) - (cfgl-package "pkg1" :name 'pkg1 :owners '(layer1) :excluded t)) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer1) :location 'local :step 'pre) + (cfgl-package "pkg2" :name 'pkg2 :owners '(layer1) :location '(recipe blahblah)) + (cfgl-package "pkg1" :name 'pkg1 :owners '(layer1) :excluded t)) + configuration-layer--packages))))) (ert-deftest test-get-packages--symbols-and-lists () - (let* ((layer1 (cfgl-layer "layer1" :name 'layer1 :dir "/path/")) - (layers (list layer1)) - (layer1-packages '(pkg1 - (pkg2 :location (recipe blahblah)) - (pkg3 :location local :step pre) - pkg4)) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (let* ((layer1 (cfgl-layer "layer1" + :name 'layer1 + :dir "/path/" + :packages '(pkg1 + (pkg2 :location (recipe blahblah)) + (pkg3 :location local :step pre) + pkg4))) + (layers (list layer1))) (defun layer1/init-pkg1 nil) (defun layer1/init-pkg2 nil) (defun layer1/init-pkg3 nil) (defun layer1/init-pkg4 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 1))) - (load (f) ((:output nil :occur 1)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers) - (should (equal (list (cfgl-package "pkg4" :name 'pkg4 :owners '(layer1)) - (cfgl-package "pkg3" :name 'pkg3 :owners '(layer1) :location 'local :step 'pre) - (cfgl-package "pkg2" :name 'pkg2 :owners '(layer1) :location '(recipe blahblah)) - (cfgl-package "pkg1" :name 'pkg1 :owners '(layer1))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg4" :name 'pkg4 :owners '(layer1)) + (cfgl-package "pkg3" :name 'pkg3 :owners '(layer1) :location 'local :step 'pre) + (cfgl-package "pkg2" :name 'pkg2 :owners '(layer1) :location '(recipe blahblah)) + (cfgl-package "pkg1" :name 'pkg1 :owners '(layer1))) + configuration-layer--packages))))) (ert-deftest test-get-packages--pkg2-has-no-owner-because-no-init-function () - (let* ((layer2 (cfgl-layer "layer2" :name 'layer2 :dir "/path/")) + (let* ((layer2 (cfgl-layer "layer2" + :name 'layer2 + :dir "/path/" + :packages '(pkg1 pkg2 pkg3))) (layers (list layer2)) - (layer2-packages '(pkg1 pkg2 pkg3)) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer2/init-pkg1 nil) (defun layer2/init-pkg3 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 1))) - (configuration-layer//warning (m) ((:output nil))) - (load (f) ((:output nil :occur 1)))) + ((configuration-layer//warning (m) ((:output nil)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer2)) @@ -430,70 +521,76 @@ configuration-layer--packages)))))) (ert-deftest test-get-packages--pre-init-function () - (let* ((layer3 (cfgl-layer "layer3" :name 'layer3 :dir "/path/")) - (layer4 (cfgl-layer "layer4" :name 'layer4 :dir "/path/")) - (layers (list layer3 layer4)) - (layer3-packages '(pkg1)) - (layer4-packages '(pkg1)) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (let* ((layer3 (cfgl-layer "layer3" + :name 'layer3 + :dir "/path/" + :packages '(pkg1))) + (layer4 (cfgl-layer "layer4" + :name 'layer4 + :dir "/path/" + :packages '(pkg1))) + (layers (list layer3 layer4))) (defun layer3/init-pkg1 nil) (defun layer4/pre-init-pkg1 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers) - (should (equal (list (cfgl-package "pkg1" :name 'pkg1 :owners '(layer3) :pre-layers '(layer4))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg1" :name 'pkg1 :owners '(layer3) :pre-layers '(layer4))) + configuration-layer--packages))))) (ert-deftest test-get-packages--post-init-function () - (let* ((layer3 (cfgl-layer "layer3" :name 'layer3 :dir "/path/")) - (layer5 (cfgl-layer "layer5" :name 'layer5 :dir "/path/")) - (layers (list layer3 layer5)) - (layer3-packages '(pkg1)) - (layer5-packages '(pkg1)) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (let* ((layer3 (cfgl-layer "layer3" + :name 'layer3 + :dir "/path/" + :packages '(pkg1))) + (layer5 (cfgl-layer "layer5" + :name 'layer5 + :dir "/path/" + :packages '(pkg1))) + (layers (list layer3 layer5))) (defun layer3/init-pkg1 nil) (defun layer5/post-init-pkg1 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers) - (should (equal (list (cfgl-package "pkg1" :name 'pkg1 :owners '(layer3) :post-layers '(layer5))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg1" :name 'pkg1 :owners '(layer3) :post-layers '(layer5))) + configuration-layer--packages))))) (ert-deftest test-get-packages--pre-and-post-init-functions () - (let* ((layer3 (cfgl-layer "layer3" :name 'layer3 :dir "/path/")) - (layer6 (cfgl-layer "layer6" :name 'layer6 :dir "/path/")) - (layers (list layer3 layer6)) - (layer3-packages '(pkg1)) - (layer6-packages '(pkg1)) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (let* ((layer3 (cfgl-layer "layer3" + :name 'layer3 + :dir "/path/" + :packages '(pkg1))) + (layer6 (cfgl-layer "layer6" + :name 'layer6 + :dir "/path/" + :packages '(pkg1))) + (layers (list layer3 layer6))) (defun layer3/init-pkg1 nil) (defun layer6/pre-init-pkg1 nil) (defun layer6/post-init-pkg1 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers) - (should (equal (list (cfgl-package "pkg1" :name 'pkg1 :owners '(layer3) :pre-layers '(layer6) :post-layers '(layer6))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg1" + :name 'pkg1 + :owners '(layer3) + :pre-layers '(layer6) + :post-layers '(layer6))) + configuration-layer--packages))))) (ert-deftest test-get-packages--several-init-functions-last-one-is-the-owner () - (let* ((layer7 (cfgl-layer "layer7" :name 'layer7 :dir "/path/")) - (layer8 (cfgl-layer "layer8" :name 'layer8 :dir "/path/")) + (let* ((layer7 (cfgl-layer "layer7" + :name 'layer7 + :dir "/path/" + :packages '(pkg1))) + (layer8 (cfgl-layer "layer8" + :name 'layer8 + :dir "/path/" + :packages '(pkg1))) (layers (list layer7 layer8)) - (layer7-packages '(pkg1)) - (layer8-packages '(pkg1)) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer7/init-pkg1 nil) (defun layer8/init-pkg1 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2))) - (configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) + ((configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg1" @@ -502,75 +599,74 @@ configuration-layer--packages)))))) (ert-deftest test-get-packages--layer-10-excludes-pkg2-in-layer-9 () - (let* ((layer9 (cfgl-layer "layer9" :name 'layer9 :dir "/path/")) - (layer10 (cfgl-layer "layer10" :name 'layer10 :dir "/path/")) - (layers (list layer9 layer10)) - (layer9-packages '(pkg1 pkg2)) - (layer10-packages '(pkg3 (pkg2 :excluded t))) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (let* ((layer9 (cfgl-layer "layer9" + :name 'layer9 + :dir "/path/" + :packages '(pkg1 pkg2))) + (layer10 (cfgl-layer "layer10" + :name 'layer10 + :dir "/path/" + :packages '(pkg3 (pkg2 :excluded t)))) + (layers (list layer9 layer10))) (defun layer9/init-pkg1 nil) (defun layer9/init-pkg2 nil) (defun layer10/init-pkg3 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers) - (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer10)) - (cfgl-package "pkg2" :name 'pkg2 :owners '(layer9) :excluded t) - (cfgl-package "pkg1" :name 'pkg1 :owners '(layer9))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer10)) + (cfgl-package "pkg2" :name 'pkg2 :owners '(layer9) :excluded t) + (cfgl-package "pkg1" :name 'pkg1 :owners '(layer9))) + configuration-layer--packages))))) (ert-deftest test-get-packages--dotfile-excludes-pkg2-in-layer-11 () - (let* ((layer11 (cfgl-layer "layer11" :name 'layer11 :dir "/path/")) + (let* ((layer11 (cfgl-layer "layer11" + :name 'layer11 + :dir "/path/" + :packages '(pkg1 pkg2 pkg3))) (layers (list layer11)) - (layer11-packages '(pkg1 pkg2 pkg3)) (dotspacemacs-excluded-packages '(pkg2)) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer11/init-pkg1 nil) (defun layer11/init-pkg2 nil) (defun layer11/init-pkg3 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 1))) - (load (f) ((:output nil :occur 1)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers t) - (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer11)) - (cfgl-package "pkg2" :name 'pkg2 :owners '(layer11) :excluded t) - (cfgl-package "pkg1" :name 'pkg1 :owners '(layer11))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers t) + (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(layer11)) + (cfgl-package "pkg2" :name 'pkg2 :owners '(layer11) :excluded t) + (cfgl-package "pkg1" :name 'pkg1 :owners '(layer11))) + configuration-layer--packages))))) (ert-deftest test-get-packages--dotfile-declares-and-owns-one-additional-package () - (let* ((layer12 (cfgl-layer "layer12" :name 'layer12 :dir "/path/")) + (let* ((layer12 (cfgl-layer "layer12" + :name 'layer12 + :dir "/path/" + :packages '(pkg1 pkg2))) (layers (list layer12)) - (layer12-packages '(pkg1 pkg2)) - (dotspacemacs-additional-packages '(pkg3)) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (dotspacemacs-additional-packages '(pkg3))) (defun layer12/init-pkg1 nil) (defun layer12/init-pkg2 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 1))) - (load (f) ((:output nil :occur 1)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers t) - (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(dotfile)) - (cfgl-package "pkg2" :name 'pkg2 :owners '(layer12)) - (cfgl-package "pkg1" :name 'pkg1 :owners '(layer12))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers t) + (should (equal (list (cfgl-package "pkg3" :name 'pkg3 :owners '(dotfile)) + (cfgl-package "pkg2" :name 'pkg2 :owners '(layer12)) + (cfgl-package "pkg1" :name 'pkg1 :owners '(layer12))) + configuration-layer--packages))))) (ert-deftest test-get-packages--last-owner-can-overwrite-location () - (let* ((layer13 (cfgl-layer "layer13" :name 'layer13 :dir "/path/")) - (layer14 (cfgl-layer "layer14" :name 'layer14 :dir "/path/")) + (let* ((layer13 (cfgl-layer "layer13" + :name 'layer13 + :dir "/path/" + :packages '((pkg1 :location elpa)))) + (layer14 (cfgl-layer "layer14" + :name 'layer14 + :dir "/path/" + :packages '((pkg1 :location local)))) (layers (list layer13 layer14)) - (layer13-packages '((pkg1 :location elpa))) - (layer14-packages '((pkg1 :location local))) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer13/init-pkg1 nil) (defun layer14/init-pkg1 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2))) - (configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) + ((configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg1" @@ -580,18 +676,20 @@ configuration-layer--packages)))))) (ert-deftest test-get-packages--last-owner-can-overwrite-step-nil-to-pre () - (let* ((layer15 (cfgl-layer "layer15" :name 'layer15 :dir "/path/")) - (layer16 (cfgl-layer "layer16" :name 'layer16 :dir "/path/")) + (let* ((layer15 (cfgl-layer "layer15" + :name 'layer15 + :dir "/path/" + :packages '((pkg1 :step nil)))) + (layer16 (cfgl-layer "layer16" + :name 'layer16 + :dir "/path/" + :packages '((pkg1 :step pre)))) (layers (list layer15 layer16)) - (layer15-packages '((pkg1 :step nil))) - (layer16-packages '((pkg1 :step pre))) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer15/init-pkg1 nil) (defun layer16/init-pkg1 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2))) - (configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) + ((configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg1" @@ -601,18 +699,20 @@ configuration-layer--packages)))))) (ert-deftest test-get-packages--last-owner-cannot-overwrite-step-pre-to-nil () - (let* ((layer15 (cfgl-layer "layer15" :name 'layer15 :dir "/path/")) - (layer16 (cfgl-layer "layer16" :name 'layer16 :dir "/path/")) + (let* ((layer15 (cfgl-layer "layer15" + :name 'layer15 + :dir "/path/" + :packages '((pkg1 :step pre)))) + (layer16 (cfgl-layer "layer16" + :name 'layer16 + :dir "/path/" + :packages '((pkg1 :step nil)))) (layers (list layer15 layer16)) - (layer15-packages '((pkg1 :step pre))) - (layer16-packages '((pkg1 :step nil))) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer15/init-pkg1 nil) (defun layer16/init-pkg1 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2))) - (configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) + ((configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg1" @@ -622,18 +722,21 @@ configuration-layer--packages)))))) (ert-deftest test-get-packages--last-owner-can-overwrite-exclude () - (let* ((layer17 (cfgl-layer "layer17" :name 'layer17 :dir "/path/")) - (layer18 (cfgl-layer "layer18" :name 'layer18 :dir "/path/")) + (let* ((layer17 (cfgl-layer "layer17" + :name 'layer17 + :dir "/path/" + :packages '(pkg1))) + (layer18 (cfgl-layer "layer18" + :name 'layer18 + :dir "/path/" + :packages '((pkg1 :excluded t)) + )) (layers (list layer17 layer18)) - (layer17-packages '(pkg1)) - (layer18-packages '((pkg1 :excluded t))) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer17/init-pkg1 nil) (defun layer18/init-pkg1 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2))) - (configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) + ((configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg1" @@ -643,35 +746,35 @@ configuration-layer--packages)))))) (ert-deftest test-get-packages--owner-layer-can-define-toggle () - (let* ((layer19 (cfgl-layer "layer19" :name 'layer19 :dir "/path/")) - (layers (list layer19)) - (layer19-packages '((pkg1 :toggle (foo-toggle)))) - (mocker-mock-default-record-cls 'mocker-stub-record)) + (let* ((layer19 (cfgl-layer "layer19" + :name 'layer19 + :dir "/path/" + :packages '((pkg1 :toggle (foo-toggle))))) + (layers (list layer19))) (defun layer19/init-pkg1 nil) - (mocker-let - ((file-exists-p (f) ((:output t :occur 1))) - (load (f) ((:output nil :occur 1)))) - (let (configuration-layer--packages) - (configuration-layer/get-packages layers) - (should (equal (list (cfgl-package "pkg1" - :name 'pkg1 - :owners '(layer19) - :toggle '(foo-toggle))) - configuration-layer--packages)))))) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg1" + :name 'pkg1 + :owners '(layer19) + :toggle '(foo-toggle))) + configuration-layer--packages))))) (ert-deftest test-get-packages--not-owner-layer-cannot-define-toggle () - (let* ((layer20 (cfgl-layer "layer20" :name 'layer20 :dir "/path/")) - (layer21 (cfgl-layer "layer21" :name 'layer21 :dir "/path/")) + (let* ((layer20 (cfgl-layer "layer20" + :name 'layer20 + :dir "/path/" + :packages '(pkg1))) + (layer21 (cfgl-layer "layer21" + :name 'layer21 + :dir "/path/" + :packages '((pkg1 :toggle (foo-toggle))))) (layers (list layer20 layer21)) - (layer20-packages '((pkg1))) - (layer21-packages '((pkg1 :toggle (foo-toggle)))) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer20/init-pkg1 nil) (defun layer21/post-init-pkg1 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2))) - (configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) + ((configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg1" @@ -682,18 +785,20 @@ configuration-layer--packages)))))) (ert-deftest test-get-packages--new-owner-layer-can-override-toggle () - (let* ((layer22 (cfgl-layer "layer22" :name 'layer22 :dir "/path/")) - (layer23 (cfgl-layer "layer23" :name 'layer23 :dir "/path/")) + (let* ((layer22 (cfgl-layer "layer22" + :name 'layer22 + :dir "/path/" + :packages '((pkg1 :toggle (foo-toggle))))) + (layer23 (cfgl-layer "layer23" + :name 'layer23 + :dir "/path/" + :packages '((pkg1 :toggle (bar-toggle))))) (layers (list layer22 layer23)) - (layer22-packages '((pkg1 :toggle (foo-toggle)))) - (layer23-packages '((pkg1 :toggle (bar-toggle)))) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer22/init-pkg1 nil) (defun layer23/init-pkg1 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2))) - (configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) + ((configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg1" @@ -703,18 +808,20 @@ configuration-layer--packages)))))) (ert-deftest test-get-packages--dotfile-additional-pkg-can-override-toggle () - (let* ((layer22 (cfgl-layer "layer22" :name 'layer22 :dir "/path/")) - (layer23 (cfgl-layer "layer23" :name 'layer23 :dir "/path/")) + (let* ((layer22 (cfgl-layer "layer22" + :name 'layer22 + :dir "/path/" + :packages '((pkg1 :toggle (foo-toggle))))) + (layer23 (cfgl-layer "layer23" + :name 'layer23 + :dir "/path/" + :packages '((pkg1 :toggle (bar-toggle))))) (layers (list layer22 layer23)) - (layer22-packages '((pkg1 :toggle (foo-toggle)))) - (layer23-packages '((pkg1 :toggle (bar-toggle)))) (mocker-mock-default-record-cls 'mocker-stub-record)) (defun layer22/init-pkg1 nil) (defun layer23/init-pkg1 nil) (mocker-let - ((file-exists-p (f) ((:output t :occur 2))) - (load (f) ((:output nil :occur 2))) - (configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) + ((configuration-layer//warning (msg &rest args) ((:output nil :occur 1)))) (let (configuration-layer--packages) (configuration-layer/get-packages layers) (should (equal (list (cfgl-package "pkg1" @@ -723,6 +830,63 @@ :toggle '(bar-toggle))) configuration-layer--packages)))))) +(ert-deftest test-get-packages--not-selected-packages-are-not-excluded () + (let* ((layer24 (cfgl-layer "layer24" + :name 'layer24 + :dir "/path/" + :packages '(pkg1 (pkg2 :location local)) + :selected-packages '(pkg2))) + (layer25 (cfgl-layer "layer25" + :name 'layer25 + :dir "/path/" + :packages '(pkg1 (pkg2 :location local)) + :selected-packages '(pkg1))) + (layers (list layer24 layer25))) + (defun layer24/post-init-pkg1 nil) + (defun layer24/init-pkg2 nil) + (defun layer25/init-pkg1 nil) + (defun layer25/post-init-pkg2 nil) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg1" + :name 'pkg1 + :owners '(layer25) + :excluded nil) + (cfgl-package "pkg2" + :name 'pkg2 + :owners '(layer24) + :location 'local + :excluded nil)) + configuration-layer--packages))))) + +(ert-deftest test-get-packages--not-selected-package-in-a-layer-can-still-be-created-with-no-owner () + (let* ((layer26 (cfgl-layer "layer26" + :name 'layer26 + :dir "/path/" + :packages '(pkg1 (pkg2 :location local)) + :selected-packages '(pkg2))) + (layer27 (cfgl-layer "layer27" + :name 'layer27 + :dir "/path/" + :packages '(pkg1 pkg2))) + (layers (list layer26 layer27))) + (defun layer26/init-pkg1 nil) + (defun layer26/init-pkg2 nil) + (defun layer27/post-init-pkg1 nil) + (defun layer27/post-init-pkg2 nil) + (let (configuration-layer--packages) + (configuration-layer/get-packages layers) + (should (equal (list (cfgl-package "pkg1" + :name 'pkg1 + :post-layers '(layer27) + :owners nil) + (cfgl-package "pkg2" + :name 'pkg2 + :owners '(layer26) + :post-layers '(layer27) + :location 'local)) + configuration-layer--packages))))) + ;; --------------------------------------------------------------------------- ;; configuration-layer/get-all-packages ;; ---------------------------------------------------------------------------