This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/core/tests/core-configuration-layer-utest.el
syl20bnr 2db488ad37 core: add support for spacemacs update
Move release management suff to newly created core-release-management.el
2015-06-06 23:26:14 -04:00

225 lines
9.4 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-layers
;; ---------------------------------------------------------------------------
(ert-deftest test-declare-layers--result-order-is-not-reversed ()
(mocker-let ((configuration-layer//declare-layer
(x)
((:input '(layer3) :output 'layer3)
(:input '(layer2) :output 'layer2)
(:input '(layer1) :output 'layer1))))
(let* ((input '(layer1 layer2 layer3))
(result (configuration-layer//declare-layers input)))
(should (equal result input)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//declare-layer
;; ---------------------------------------------------------------------------
(ert-deftest test-declare-layers--input-is-a-symbol ()
(let ((input 'testlayer))
(mocker-let ((configuration-layer/get-layer-path
(x)
((:input `(,input) :output "/a/dummy/path/"))))
(let ((result (configuration-layer//declare-layer input))
(expected '(testlayer :dir "/a/dummy/path/testlayer/"
:ext-dir "/a/dummy/path/testlayer/extensions/")))
(should (equal result expected))))))
(ert-deftest test-declare-layers--input-is-a-list ()
(let ((input '(testlayer :variables
var1 t
var2 nil
:excluded-packages
excludedlayer)))
(mocker-let ((configuration-layer/get-layer-path
(x)
((:input `(,(car input)) :output "/a/dummy/path/"))))
(let ((result (configuration-layer//declare-layer input))
(expected '(testlayer :dir "/a/dummy/path/testlayer/"
:ext-dir "/a/dummy/path/testlayer/extensions/"
:variables
var1 t
var2 nil
:excluded-packages
excludedlayer
)))
(should (equal result expected))))))
;; ---------------------------------------------------------------------------
;; configuration-layer//set-layers-variables
;; ---------------------------------------------------------------------------
(ert-deftest test-set-layers-variables--none ()
(let ((input '((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 '((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 '((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 '((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))))))