2015-04-06 01:01:54 +00:00
|
|
|
;;; core-configuration-layer-utest.el --- Spacemacs Unit Test File
|
2015-01-23 03:39:26 +00:00
|
|
|
;;
|
|
|
|
;; 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)
|
2015-01-27 03:51:47 +00:00
|
|
|
(require 'core-configuration-layer)
|
2015-01-25 05:01:43 +00:00
|
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
2015-07-26 02:59:54 +00:00
|
|
|
;; configuration-layer//declare-used-layers
|
2015-01-25 05:01:43 +00:00
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
2015-07-26 14:45:34 +00:00
|
|
|
(ert-deftest test-declare-used-layers--result-order-is-not-reversed ()
|
2015-07-26 22:59:25 +00:00
|
|
|
(mocker-let ((configuration-layer//make-used-layer
|
2015-01-25 05:01:43 +00:00
|
|
|
(x)
|
2015-03-03 09:15:59 +00:00
|
|
|
((:input '(layer3) :output 'layer3)
|
2015-01-25 05:01:43 +00:00
|
|
|
(:input '(layer2) :output 'layer2)
|
2015-03-03 09:15:59 +00:00
|
|
|
(:input '(layer1) :output 'layer1))))
|
2015-01-25 05:01:43 +00:00
|
|
|
(let* ((input '(layer1 layer2 layer3))
|
2015-07-26 02:59:54 +00:00
|
|
|
(result (configuration-layer//declare-used-layers input)))
|
2015-03-03 09:15:59 +00:00
|
|
|
(should (equal result input)))))
|
2015-01-25 05:01:43 +00:00
|
|
|
|
2015-07-27 00:41:06 +00:00
|
|
|
(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)))))
|
|
|
|
|
2015-01-25 05:01:43 +00:00
|
|
|
;; ---------------------------------------------------------------------------
|
2015-07-26 22:59:25 +00:00
|
|
|
;; configuration-layer//make-used-layer
|
2015-01-25 05:01:43 +00:00
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
2015-07-26 22:59:25 +00:00
|
|
|
(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/")))
|
2015-01-25 05:01:43 +00:00
|
|
|
(mocker-let ((configuration-layer/get-layer-path
|
|
|
|
(x)
|
|
|
|
((:input `(,input) :output "/a/dummy/path/"))))
|
2015-07-26 22:59:25 +00:00
|
|
|
(let ((result (configuration-layer//make-used-layer input)))
|
2015-01-25 05:01:43 +00:00
|
|
|
(should (equal result expected))))))
|
|
|
|
|
2015-07-26 22:59:25 +00:00
|
|
|
(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))))
|
2015-01-25 05:01:43 +00:00
|
|
|
(mocker-let ((configuration-layer/get-layer-path
|
|
|
|
(x)
|
|
|
|
((:input `(,(car input)) :output "/a/dummy/path/"))))
|
2015-07-26 22:59:25 +00:00
|
|
|
(let ((result (configuration-layer//make-used-layer input)))
|
2015-01-25 05:01:43 +00:00
|
|
|
(should (equal result expected))))))
|
2015-01-26 04:22:41 +00:00
|
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
;; configuration-layer//set-layers-variables
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(ert-deftest test-set-layers-variables--none ()
|
2015-07-26 22:59:25 +00:00
|
|
|
(let ((input `(,(cfgl-layer "testlayer"
|
|
|
|
:name 'testlayer
|
|
|
|
:dir "/a/path/"
|
|
|
|
:ext-dir "/a/path/extensions/")))
|
2015-01-26 04:22:41 +00:00
|
|
|
(var 'foo))
|
|
|
|
(configuration-layer//set-layers-variables input)
|
|
|
|
(should (eq var 'foo))))
|
|
|
|
|
|
|
|
(ert-deftest test-set-layers-variables--one-value ()
|
2015-07-26 22:59:25 +00:00
|
|
|
(let ((input `(,(cfgl-layer "testlayer"
|
|
|
|
:name 'testlayer
|
|
|
|
:dir "/a/path/"
|
|
|
|
:ext-dir "/a/path/extensions/"
|
|
|
|
:variables '(var1 'bar)))))
|
2015-01-26 04:22:41 +00:00
|
|
|
(setq var1 'foo)
|
|
|
|
(configuration-layer//set-layers-variables input)
|
|
|
|
(should (eq var1 'bar))))
|
|
|
|
|
|
|
|
(ert-deftest test-set-layers-variables--multiple-values ()
|
2015-07-26 22:59:25 +00:00
|
|
|
(let ((input `(,(cfgl-layer "testlayer"
|
|
|
|
:name 'testlayer
|
|
|
|
:dir "/a/path/"
|
|
|
|
:ext-dir "/a/path/extensions/"
|
|
|
|
:variables '(var1 'bar1 var2 'bar2 var3 'bar3)))))
|
2015-01-26 04:22:41 +00:00
|
|
|
(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 ()
|
2015-07-26 22:59:25 +00:00
|
|
|
(let ((input `(,(cfgl-layer "testlayer"
|
|
|
|
:name 'testlayer
|
|
|
|
:dir "/a/path/"
|
|
|
|
:ext-dir "/a/path/extensions/"
|
|
|
|
:variables '(var1 'bar var2)))))
|
2015-01-26 04:22:41 +00:00
|
|
|
(mocker-let
|
2015-04-13 06:20:03 +00:00
|
|
|
((spacemacs-buffer/warning
|
2015-01-26 04:22:41 +00:00
|
|
|
(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)))))
|
2015-06-06 02:47:23 +00:00
|
|
|
|
|
|
|
;; ---------------------------------------------------------------------------
|
|
|
|
;; 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 ()
|
2015-06-07 03:26:14 +00:00
|
|
|
(let ((input "/a/path/to/a/!cat/"))
|
2015-06-06 02:47:23 +00:00
|
|
|
(mocker-let
|
|
|
|
((file-directory-p (f)
|
|
|
|
((:record-cls 'mocker-stub-record :output t :occur 1))))
|
2015-06-07 03:26:14 +00:00
|
|
|
(should (eq 'cat (configuration-layer//get-category-from-path input))))))
|