234 lines
10 KiB
EmacsLisp
234 lines
10 KiB
EmacsLisp
;;; core-configuration-layer-utest.el --- Spacemacs Unit Test File
|
|
;;
|
|
;; Copyright (c) 2012-2014 Sylvain Benner
|
|
;; Copyright (c) 2014-2015 Sylvain Benner & Contributors
|
|
;;
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
;;
|
|
;; This file is not part of GNU Emacs.
|
|
;;
|
|
;;; License: GPLv3
|
|
(require 'mocker)
|
|
(require 'core-configuration-layer)
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; configuration-layer//declare-used-layers
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(ert-deftest test-declare-used-layers--result-order-is-not-reversed ()
|
|
(mocker-let ((configuration-layer//make-used-layer
|
|
(x)
|
|
((:input '(layer3) :output 'layer3)
|
|
(:input '(layer2) :output 'layer2)
|
|
(:input '(layer1) :output 'layer1))))
|
|
(let* ((input '(layer1 layer2 layer3))
|
|
(result (configuration-layer//declare-used-layers input)))
|
|
(should (equal result input)))))
|
|
|
|
(ert-deftest test-declare-used-layers--ignore-not-found-layer ()
|
|
(mocker-let ((configuration-layer//make-used-layer
|
|
(x)
|
|
((:input '(layer3) :output 'layer3)
|
|
(:input '(layer2-not-found) :output nil)
|
|
(:input '(layer1) :output 'layer1))))
|
|
(let* ((input '(layer1 layer2-not-found layer3))
|
|
(expected '(layer1 layer3))
|
|
(result (configuration-layer//declare-used-layers input)))
|
|
(should (equal result expected)))))
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; configuration-layer//make-used-layer
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(ert-deftest test-make-used-layer--input-is-a-symbol ()
|
|
(let ((input 'testlayer)
|
|
(expected (cfgl-layer "testlayer"
|
|
:name 'testlayer
|
|
:dir "/a/dummy/path/testlayer/"
|
|
:ext-dir "/a/dummy/path/testlayer/extensions/")))
|
|
(mocker-let ((configuration-layer/get-layer-path
|
|
(x)
|
|
((:input `(,input) :output "/a/dummy/path/"))))
|
|
(let ((result (configuration-layer//make-used-layer input)))
|
|
(should (equal result expected))))))
|
|
|
|
(ert-deftest test-make-used-layer--input-is-a-list ()
|
|
(let ((input '(testlayer :variables var1 t var2 nil))
|
|
(expected (cfgl-layer "testlayer"
|
|
:name 'testlayer
|
|
:dir "/a/dummy/path/testlayer/"
|
|
:ext-dir "/a/dummy/path/testlayer/extensions/"
|
|
:variables '(var1 t var2 nil))))
|
|
(mocker-let ((configuration-layer/get-layer-path
|
|
(x)
|
|
((:input `(,(car input)) :output "/a/dummy/path/"))))
|
|
(let ((result (configuration-layer//make-used-layer input)))
|
|
(should (equal result expected))))))
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; configuration-layer//set-layers-variables
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(ert-deftest test-set-layers-variables--none ()
|
|
(let ((input `(,(cfgl-layer "testlayer"
|
|
:name 'testlayer
|
|
:dir "/a/path/"
|
|
:ext-dir "/a/path/extensions/")))
|
|
(var 'foo))
|
|
(configuration-layer//set-layers-variables input)
|
|
(should (eq var 'foo))))
|
|
|
|
(ert-deftest test-set-layers-variables--one-value ()
|
|
(let ((input `(,(cfgl-layer "testlayer"
|
|
:name 'testlayer
|
|
:dir "/a/path/"
|
|
:ext-dir "/a/path/extensions/"
|
|
:variables '(var1 'bar)))))
|
|
(setq var1 'foo)
|
|
(configuration-layer//set-layers-variables input)
|
|
(should (eq var1 'bar))))
|
|
|
|
(ert-deftest test-set-layers-variables--multiple-values ()
|
|
(let ((input `(,(cfgl-layer "testlayer"
|
|
:name 'testlayer
|
|
:dir "/a/path/"
|
|
:ext-dir "/a/path/extensions/"
|
|
:variables '(var1 'bar1 var2 'bar2 var3 'bar3)))))
|
|
(setq var1 'foo)
|
|
(setq var2 'foo)
|
|
(setq var3 'foo)
|
|
(configuration-layer//set-layers-variables input)
|
|
(should (eq var1 'bar1))
|
|
(should (eq var2 'bar2))
|
|
(should (eq var3 'bar3))))
|
|
|
|
(ert-deftest test-set-layers-variables--odd-number-of-values ()
|
|
(let ((input `(,(cfgl-layer "testlayer"
|
|
:name 'testlayer
|
|
:dir "/a/path/"
|
|
:ext-dir "/a/path/extensions/"
|
|
:variables '(var1 'bar var2)))))
|
|
(mocker-let
|
|
((spacemacs-buffer/warning
|
|
(msg &rest args)
|
|
((:record-cls 'mocker-stub-record :output nil :occur 1))))
|
|
(setq var1 'foo)
|
|
(setq var2 'foo)
|
|
(configuration-layer//set-layers-variables input)
|
|
(should (eq var1 'bar))
|
|
(should (eq var2 'foo)))))
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; configuration-layer//directory-type
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(ert-deftest test-directory-type--input-is-a-file ()
|
|
(let ((input "/a/path/to/a/layer/file"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output nil :occur 1))))
|
|
(should (null (configuration-layer//directory-type input))))))
|
|
|
|
(ert-deftest test-directory-type--category ()
|
|
(let ((input (concat configuration-layer-contrib-directory "!vim/")))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1))))
|
|
(should (eq 'category (configuration-layer//directory-type input))))))
|
|
|
|
(ert-deftest test-directory-type--input-is-an-empty-directory ()
|
|
(let ((input "/a/path/to/a/layer/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1)))
|
|
(directory-files
|
|
(directory &optional full match nosort)
|
|
((:record-cls 'mocker-stub-record :output nil :occur 1))))
|
|
(should (null (configuration-layer//directory-type input))))))
|
|
|
|
(ert-deftest test-directory-type--input-is-directory-and-not-a-layer ()
|
|
(let ((input "/a/path/to/a/layer/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1)))
|
|
(directory-files
|
|
(directory &optional full match nosort)
|
|
((:record-cls 'mocker-stub-record :output '("toto.el" "tata.el") :occur 1))))
|
|
(should (null (configuration-layer//directory-type input))))))
|
|
|
|
(ert-deftest test-directory-type--layer-with-packages.el ()
|
|
(let ((input "/a/path/to/a/layer/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1)))
|
|
(directory-files
|
|
(directory &optional full match nosort)
|
|
((:record-cls 'mocker-stub-record :output '("packages.el") :occur 1))))
|
|
(should (eq 'layer (configuration-layer//directory-type input))))))
|
|
|
|
(ert-deftest test-directory-type--layer-with-extensions.el ()
|
|
(let ((input "/a/path/to/a/layer/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1)))
|
|
(directory-files
|
|
(directory &optional full match nosort)
|
|
((:record-cls 'mocker-stub-record :output '("extensions.el") :occur 1))))
|
|
(should (eq 'layer (configuration-layer//directory-type input))))))
|
|
|
|
(ert-deftest test-directory-type--layer-with-config.el ()
|
|
(let ((input "/a/path/to/a/layer/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1)))
|
|
(directory-files
|
|
(directory &optional full match nosort)
|
|
((:record-cls 'mocker-stub-record :output '("config.el") :occur 1))))
|
|
(should (eq 'layer (configuration-layer//directory-type input))))))
|
|
|
|
(ert-deftest test-directory-type--layer-with-keybindings.el ()
|
|
(let ((input "/a/path/to/a/layer/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1)))
|
|
(directory-files
|
|
(directory &optional full match nosort)
|
|
((:record-cls 'mocker-stub-record :output '("keybindings.el") :occur 1))))
|
|
(should (eq 'layer (configuration-layer//directory-type input))))))
|
|
|
|
(ert-deftest test-directory-type--layer-with-funcs.el ()
|
|
(let ((input "/a/path/to/a/layer/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1)))
|
|
(directory-files
|
|
(directory &optional full match nosort)
|
|
((:record-cls 'mocker-stub-record :output '("funcs.el") :occur 1))))
|
|
(should (eq 'layer (configuration-layer//directory-type input))))))
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
;; configuration-layer//get-category-from-path
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
(ert-deftest test-get-category-from-path--input-is-a-file ()
|
|
(let ((input "/a/path/to/a/file"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output nil :occur 1))))
|
|
(should (null (configuration-layer//get-category-from-path input))))))
|
|
|
|
(ert-deftest test-get-category-from-path--input-is-a-regular-directory ()
|
|
(let ((input "/a/path/to/a/layer/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1))))
|
|
(should (null (configuration-layer//get-category-from-path input))))))
|
|
|
|
(ert-deftest test-get-category-from-path--return-category ()
|
|
(let ((input "/a/path/to/a/!cat/"))
|
|
(mocker-let
|
|
((file-directory-p (f)
|
|
((:record-cls 'mocker-stub-record :output t :occur 1))))
|
|
(should (eq 'cat (configuration-layer//get-category-from-path input))))))
|