spacemacs/tests/core/core-configuration-layer-ft...

108 lines
5.3 KiB
EmacsLisp
Raw Normal View History

;;; core-configuration-layer-ftest.el --- Spacemacs Functional Test File
;;
;; Copyright (c) 2012-2022 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
(require 'core-configuration-layer)
;; ---------------------------------------------------------------------------
core: refactor layer system TL;DR Should get 20~25% speed improvement on startup, should get a big improvement when using ivy or helm SPC h SPC. Users with layers.el files in their layers must use `configuration-layer/declare-used-layer` instead of `configuration-layer/declare-layer` The implementation of the layer system made heavy use of `object-assoc` and `object-assoc-list` functions which are not efficient. This PR mainly replaces those object lists with hash maps in order to index the objects by their name and achieve an O(1) access time. The old object lists `configuration-layer--layers` and `configuration-layer--packages` have been each by two variables each: - `configuration-layer--indexed-layers` which is a hash-map of all the layer objects and `configuration-layer--used-layers` which is a list of all _used_ layers symbols, - symmetrically `configuration-layer--indexed-packages` which is a hash-map of all the package objects and `configuration-layer--used-packages` which is a list of all _used_ packages symbols. The hash map `configuration-layer--layer-paths` is gone, now we create directly layer objects when discovering the layers and set the :dir property. Note that previously the layer paths were the parent directory of the layer, now :dir is the layer path. The function `configuration-layer//make-layer` is now similar to its counterpart `configuration-layer//make-package` in the sense that it takes an optional `obj` to be able to override its properties. The functions `configuration-layer/declare-layer` and `configuration-layer/declare-layers` now takes an optional parameter `usedp` in order to declare used or not used layers. For convenience new functions have been added: `configuration-layer/declare-used-layer` and `configuration-layer/declare-used-layers`, users _must_ update all occurrences of `configuration-layer/declare-layer` by `configuration-layer/declare-used-layers` in their `layers.el` files. `helm-spacemacs-help` and `ivy-spacemacs-help` are updated to match the changes in `core-configuration-layer.el`. Rename some variables to make them more explicit: `configuration-layer-no-layer` -> `configuration-layer-exclude-all-layers` `configuration-layer-distribution` -> `configuration-layer-force-distribution`
2016-07-17 19:00:43 +00:00
;; configuration-layer//declare-used-layers
;; ---------------------------------------------------------------------------
(ert-deftest test-declare-layers--bootstrap-layer-always-first ()
(let ((dotspacemacs-distribution 'spacemacs)
(dotspacemacs-configuration-layers '(emacs-lisp
core: refactor layer system TL;DR Should get 20~25% speed improvement on startup, should get a big improvement when using ivy or helm SPC h SPC. Users with layers.el files in their layers must use `configuration-layer/declare-used-layer` instead of `configuration-layer/declare-layer` The implementation of the layer system made heavy use of `object-assoc` and `object-assoc-list` functions which are not efficient. This PR mainly replaces those object lists with hash maps in order to index the objects by their name and achieve an O(1) access time. The old object lists `configuration-layer--layers` and `configuration-layer--packages` have been each by two variables each: - `configuration-layer--indexed-layers` which is a hash-map of all the layer objects and `configuration-layer--used-layers` which is a list of all _used_ layers symbols, - symmetrically `configuration-layer--indexed-packages` which is a hash-map of all the package objects and `configuration-layer--used-packages` which is a list of all _used_ packages symbols. The hash map `configuration-layer--layer-paths` is gone, now we create directly layer objects when discovering the layers and set the :dir property. Note that previously the layer paths were the parent directory of the layer, now :dir is the layer path. The function `configuration-layer//make-layer` is now similar to its counterpart `configuration-layer//make-package` in the sense that it takes an optional `obj` to be able to override its properties. The functions `configuration-layer/declare-layer` and `configuration-layer/declare-layers` now takes an optional parameter `usedp` in order to declare used or not used layers. For convenience new functions have been added: `configuration-layer/declare-used-layer` and `configuration-layer/declare-used-layers`, users _must_ update all occurrences of `configuration-layer/declare-layer` by `configuration-layer/declare-used-layers` in their `layers.el` files. `helm-spacemacs-help` and `ivy-spacemacs-help` are updated to match the changes in `core-configuration-layer.el`. Rename some variables to make them more explicit: `configuration-layer-no-layer` -> `configuration-layer-exclude-all-layers` `configuration-layer-distribution` -> `configuration-layer-force-distribution`
2016-07-17 19:00:43 +00:00
(git :variables foo 'bar)))
configuration-layer--used-layers
(configuration-layer--indexed-layers (make-hash-table :size 1024)))
(configuration-layer/discover-layers 'refresh-index)
(configuration-layer//declare-used-layers dotspacemacs-configuration-layers)
core: refactor layer system TL;DR Should get 20~25% speed improvement on startup, should get a big improvement when using ivy or helm SPC h SPC. Users with layers.el files in their layers must use `configuration-layer/declare-used-layer` instead of `configuration-layer/declare-layer` The implementation of the layer system made heavy use of `object-assoc` and `object-assoc-list` functions which are not efficient. This PR mainly replaces those object lists with hash maps in order to index the objects by their name and achieve an O(1) access time. The old object lists `configuration-layer--layers` and `configuration-layer--packages` have been each by two variables each: - `configuration-layer--indexed-layers` which is a hash-map of all the layer objects and `configuration-layer--used-layers` which is a list of all _used_ layers symbols, - symmetrically `configuration-layer--indexed-packages` which is a hash-map of all the package objects and `configuration-layer--used-packages` which is a list of all _used_ packages symbols. The hash map `configuration-layer--layer-paths` is gone, now we create directly layer objects when discovering the layers and set the :dir property. Note that previously the layer paths were the parent directory of the layer, now :dir is the layer path. The function `configuration-layer//make-layer` is now similar to its counterpart `configuration-layer//make-package` in the sense that it takes an optional `obj` to be able to override its properties. The functions `configuration-layer/declare-layer` and `configuration-layer/declare-layers` now takes an optional parameter `usedp` in order to declare used or not used layers. For convenience new functions have been added: `configuration-layer/declare-used-layer` and `configuration-layer/declare-used-layers`, users _must_ update all occurrences of `configuration-layer/declare-layer` by `configuration-layer/declare-used-layers` in their `layers.el` files. `helm-spacemacs-help` and `ivy-spacemacs-help` are updated to match the changes in `core-configuration-layer.el`. Rename some variables to make them more explicit: `configuration-layer-no-layer` -> `configuration-layer-exclude-all-layers` `configuration-layer-distribution` -> `configuration-layer-force-distribution`
2016-07-17 19:00:43 +00:00
(should (eq 'spacemacs-bootstrap
2021-01-09 13:50:52 +00:00
(car configuration-layer--used-layers)))))
(ert-deftest test-declare-layers--defaults-layer-is-second-for-base-distribution ()
(let ((dotspacemacs-distribution 'spacemacs-base)
(dotspacemacs-configuration-layers '(emacs-lisp
(git :variables foo 'bar)))
configuration-layer--used-layers
(configuration-layer--indexed-layers (make-hash-table :size 1024)))
(configuration-layer/discover-layers 'refresh-index)
(configuration-layer//declare-used-layers dotspacemacs-configuration-layers)
2021-01-09 13:50:52 +00:00
(should (eq 'spacemacs-defaults (cadr configuration-layer--used-layers)))))
(ert-deftest test-declare-layers--base-layer-is-third-for-base-distribution ()
(let ((dotspacemacs-distribution 'spacemacs-base)
(dotspacemacs-configuration-layers '(emacs-lisp
core: refactor layer system TL;DR Should get 20~25% speed improvement on startup, should get a big improvement when using ivy or helm SPC h SPC. Users with layers.el files in their layers must use `configuration-layer/declare-used-layer` instead of `configuration-layer/declare-layer` The implementation of the layer system made heavy use of `object-assoc` and `object-assoc-list` functions which are not efficient. This PR mainly replaces those object lists with hash maps in order to index the objects by their name and achieve an O(1) access time. The old object lists `configuration-layer--layers` and `configuration-layer--packages` have been each by two variables each: - `configuration-layer--indexed-layers` which is a hash-map of all the layer objects and `configuration-layer--used-layers` which is a list of all _used_ layers symbols, - symmetrically `configuration-layer--indexed-packages` which is a hash-map of all the package objects and `configuration-layer--used-packages` which is a list of all _used_ packages symbols. The hash map `configuration-layer--layer-paths` is gone, now we create directly layer objects when discovering the layers and set the :dir property. Note that previously the layer paths were the parent directory of the layer, now :dir is the layer path. The function `configuration-layer//make-layer` is now similar to its counterpart `configuration-layer//make-package` in the sense that it takes an optional `obj` to be able to override its properties. The functions `configuration-layer/declare-layer` and `configuration-layer/declare-layers` now takes an optional parameter `usedp` in order to declare used or not used layers. For convenience new functions have been added: `configuration-layer/declare-used-layer` and `configuration-layer/declare-used-layers`, users _must_ update all occurrences of `configuration-layer/declare-layer` by `configuration-layer/declare-used-layers` in their `layers.el` files. `helm-spacemacs-help` and `ivy-spacemacs-help` are updated to match the changes in `core-configuration-layer.el`. Rename some variables to make them more explicit: `configuration-layer-no-layer` -> `configuration-layer-exclude-all-layers` `configuration-layer-distribution` -> `configuration-layer-force-distribution`
2016-07-17 19:00:43 +00:00
(git :variables foo 'bar)))
configuration-layer--used-layers
(configuration-layer--indexed-layers (make-hash-table :size 1024)))
(configuration-layer/discover-layers 'refresh-index)
(configuration-layer//declare-used-layers dotspacemacs-configuration-layers)
2021-01-09 13:50:52 +00:00
(should (eq 'spacemacs-base (caddr configuration-layer--used-layers)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//stable-elpa-verify-archive
;; ---------------------------------------------------------------------------
;; FIXME: Always fail. >_> @syl20bnr
;; (ert-deftest test-stable-elpa-verify-archive--verification-ok ()
;; (cl-letf (((symbol-function 'configuration-layer//stable-elpa-tarball-local-file)
;; (lambda ()
;; (concat spacemacs-test-directory
;; "core/data/signed-test-stable-elpa.tar.gz")))
;; ((symbol-function 'configuration-layer//stable-elpa-tarball-local-sign-file)
;; (lambda ()
;; (concat spacemacs-test-directory
;; "core/data/signed-test-stable-elpa.tar.gz.sig")))
;; ((symbol-function 'configuration-layer//stable-elpa-ask-to-continue)
;; (lambda (x)
;; (message "Verification Error: %s" x)
;; nil))
;; ((symbol-function 'configuration-layer//error)
;; (lambda (x)
;; (message "Fatal Error: %s" x)
;; nil))
;; ((symbol-function 'message) 'ignore))
;; (should (equal t (configuration-layer//stable-elpa-verify-archive)))))
(ert-deftest test-stable-elpa-verify-archive--verification-failed ()
(let (verification-error)
(cl-letf (((symbol-function 'configuration-layer//stable-elpa-tarball-local-file)
(lambda ()
(concat spacemacs-test-directory
"core/data/test-stable-elpa.tar.gz")))
((symbol-function 'configuration-layer//stable-elpa-tarball-local-sign-file)
(lambda ()
(concat spacemacs-test-directory
"core/data/signed-test-stable-elpa.tar.gz.sig")))
((symbol-function 'configuration-layer//stable-elpa-ask-to-continue)
(lambda (x)
(setq verification-error x)
nil))
((symbol-function 'configuration-layer//error)
(lambda (x)
(message "Fatal Error: %s" x)
nil))
((symbol-function 'message) 'ignore))
(should (and (null (configuration-layer//stable-elpa-verify-archive))
(string-match-p "^Verification failed!.*"
verification-error))))))