2018-06-15 03:31:54 +02:00
|
|
|
;; -*- no-byte-compile: t; -*-
|
|
|
|
;;; core/test/test-core.el
|
|
|
|
|
2018-08-17 04:03:07 +02:00
|
|
|
(describe "core"
|
2020-05-25 02:58:07 -04:00
|
|
|
:var (doom-interactive-p)
|
2019-09-03 00:41:03 -04:00
|
|
|
(before-each
|
2020-05-25 02:58:07 -04:00
|
|
|
(setq doom-interactive-p nil))
|
2019-09-03 00:41:03 -04:00
|
|
|
|
|
|
|
(describe "initialization"
|
|
|
|
(describe "doom-initialize"
|
|
|
|
:var (doom-init-p)
|
2018-08-17 04:03:07 +02:00
|
|
|
(before-each
|
2019-09-03 00:41:03 -04:00
|
|
|
(setq doom-init-p nil))
|
|
|
|
|
|
|
|
(it "initializes once"
|
2019-12-05 19:50:38 -05:00
|
|
|
(expect (doom-initialize nil 'noerror))
|
|
|
|
(expect (not (doom-initialize nil 'noerror)))
|
|
|
|
(expect (not (doom-initialize nil 'noerror)))
|
2019-09-03 00:41:03 -04:00
|
|
|
(expect doom-init-p))
|
|
|
|
|
|
|
|
(it "initializes multiple times, if forced"
|
2019-12-05 19:50:38 -05:00
|
|
|
(expect (doom-initialize nil 'noerror))
|
|
|
|
(expect (not (doom-initialize nil 'noerror)))
|
|
|
|
(expect (doom-initialize 'force 'noerror)))
|
2019-09-03 00:41:03 -04:00
|
|
|
|
|
|
|
(describe "package initialization"
|
2018-08-17 04:03:07 +02:00
|
|
|
(before-each
|
2019-09-03 00:41:03 -04:00
|
|
|
(spy-on 'doom-initialize-packages :and-return-value t))
|
2018-08-17 04:03:07 +02:00
|
|
|
|
2019-09-03 00:41:03 -04:00
|
|
|
(it "initializes packages if core autoload file doesn't exist"
|
|
|
|
(let ((doom-autoload-file "doesnotexist"))
|
2019-12-05 19:50:38 -05:00
|
|
|
(expect (doom-initialize nil 'noerror))
|
2019-09-03 00:41:03 -04:00
|
|
|
(expect 'doom-initialize-packages :to-have-been-called))
|
2018-08-17 04:03:07 +02:00
|
|
|
|
2019-09-03 00:41:03 -04:00
|
|
|
(it "doesn't initialize packages if core autoload file was loaded"
|
2020-05-25 02:58:07 -04:00
|
|
|
(let ((doom-interactive-p t))
|
2019-09-03 00:41:03 -04:00
|
|
|
(spy-on 'doom-load-autoloads-file :and-return-value t)
|
2019-12-05 19:50:38 -05:00
|
|
|
(doom-initialize nil 'noerror)
|
2019-09-03 00:41:03 -04:00
|
|
|
(expect 'doom-load-autoloads-file :to-have-been-called-with doom-package-autoload-file)
|
|
|
|
(expect 'doom-initialize-packages :to-have-been-called)))
|
2018-08-17 04:03:07 +02:00
|
|
|
|
2019-09-03 00:41:03 -04:00
|
|
|
(it "initializes packages when forced"
|
2019-12-05 19:50:38 -05:00
|
|
|
(doom-initialize 'force 'noerror)
|
2019-09-03 00:41:03 -04:00
|
|
|
(expect 'doom-initialize-packages :to-have-been-called)))
|
2018-08-17 04:03:07 +02:00
|
|
|
|
2019-09-03 00:41:03 -04:00
|
|
|
(describe "autoloads files"
|
2018-08-17 04:03:07 +02:00
|
|
|
(before-each
|
2019-09-03 00:41:03 -04:00
|
|
|
(spy-on 'doom-load-autoloads-file)
|
|
|
|
(spy-on 'warn :and-return-value t))
|
|
|
|
|
2019-11-07 21:36:18 -05:00
|
|
|
(it "loads autoloads files"
|
2019-12-05 19:50:38 -05:00
|
|
|
(ignore-errors (doom-initialize nil 'noerror))
|
2019-09-03 00:41:03 -04:00
|
|
|
(expect 'doom-load-autoloads-file
|
|
|
|
:to-have-been-called-with doom-autoload-file)
|
|
|
|
(expect 'doom-load-autoloads-file
|
|
|
|
:to-have-been-called-with doom-package-autoload-file))
|
|
|
|
|
2019-12-05 19:50:38 -05:00
|
|
|
(it "throws doom-autoload-error when autoload files don't exist"
|
|
|
|
(let ((doom-autoload-file "doesnotexist")
|
2019-09-03 00:41:03 -04:00
|
|
|
(doom-package-autoload-file "doesnotexist"))
|
|
|
|
(expect (doom-initialize) :to-throw 'doom-autoload-error)))))
|
|
|
|
|
|
|
|
(describe "doom-initialize-core"
|
|
|
|
(before-each
|
|
|
|
(spy-on 'require))
|
|
|
|
|
|
|
|
(it "loads all doom core libraries"
|
|
|
|
(doom-initialize-core)
|
|
|
|
(expect 'require :to-have-been-called-with 'core-keybinds)
|
|
|
|
(expect 'require :to-have-been-called-with 'core-ui)
|
|
|
|
(expect 'require :to-have-been-called-with 'core-projects)
|
|
|
|
(expect 'require :to-have-been-called-with 'core-editor))))
|
|
|
|
|
|
|
|
(describe "doom-load-autoloads-file"
|
2019-11-07 21:36:18 -05:00
|
|
|
:var (doom-autoload-file doom-alt-autoload-file result)
|
2019-09-03 00:41:03 -04:00
|
|
|
(before-each
|
2019-11-07 21:36:18 -05:00
|
|
|
(setq doom-autoload-file (make-temp-file "doom-autoload" nil ".el"))
|
2019-11-15 02:14:42 -05:00
|
|
|
(with-temp-file doom-autoload-file)
|
2019-11-07 21:36:18 -05:00
|
|
|
(byte-compile-file doom-autoload-file))
|
|
|
|
(after-each
|
|
|
|
(delete-file doom-autoload-file)
|
|
|
|
(delete-file (byte-compile-dest-file doom-autoload-file)))
|
2019-09-03 00:41:03 -04:00
|
|
|
|
2019-11-07 21:36:18 -05:00
|
|
|
(it "loads the byte-compiled autoloads file if available"
|
2019-09-03 00:41:03 -04:00
|
|
|
(doom-load-autoloads-file doom-autoload-file)
|
2019-11-15 00:56:58 -05:00
|
|
|
(expect (caar load-history) :to-equal-file
|
2019-11-07 21:36:18 -05:00
|
|
|
(byte-compile-dest-file doom-autoload-file))
|
|
|
|
|
|
|
|
(delete-file (byte-compile-dest-file doom-autoload-file))
|
|
|
|
(doom-load-autoloads-file doom-autoload-file)
|
2019-11-15 00:56:58 -05:00
|
|
|
(expect (caar load-history) :to-equal-file doom-autoload-file))
|
2019-11-07 21:36:18 -05:00
|
|
|
|
|
|
|
(it "returns non-nil if successful"
|
|
|
|
(expect (doom-load-autoloads-file doom-autoload-file)))
|
|
|
|
|
|
|
|
(it "returns nil on failure or error, non-fatally"
|
|
|
|
(expect (doom-load-autoloads-file "/does/not/exist") :to-be nil)))
|
2019-09-03 00:41:03 -04:00
|
|
|
|
|
|
|
(describe "doom-load-envvars-file"
|
2019-11-07 21:36:18 -05:00
|
|
|
:var (doom-env-file process-environment)
|
2019-09-03 00:41:03 -04:00
|
|
|
(before-each
|
2019-11-07 21:36:18 -05:00
|
|
|
(setq process-environment nil
|
|
|
|
doom-env-file (make-temp-file "doom-env"))
|
2019-09-03 00:41:03 -04:00
|
|
|
(with-temp-file doom-env-file
|
2019-11-07 21:36:18 -05:00
|
|
|
(insert "A=1\nB=2\nC=3\n")))
|
2019-09-03 00:41:03 -04:00
|
|
|
(after-each
|
|
|
|
(delete-file doom-env-file))
|
|
|
|
|
|
|
|
(it "throws a file-error if file doesn't exist"
|
|
|
|
(expect (doom-load-envvars-file "/tmp/envvardoesnotexist")
|
|
|
|
:to-throw 'file-error))
|
|
|
|
|
|
|
|
(it "to fail silently if NOERROR is non-nil"
|
|
|
|
(expect (doom-load-envvars-file "/tmp/envvardoesnotexist" 'noerror)
|
|
|
|
:not :to-throw))
|
|
|
|
|
2019-11-07 21:36:18 -05:00
|
|
|
(it "returns the new value for `process-environment'"
|
2019-09-03 00:41:03 -04:00
|
|
|
(expect (doom-load-envvars-file doom-env-file)
|
2019-11-21 17:14:10 -05:00
|
|
|
:to-have-same-items-as '("A" "B" "C")))
|
2019-11-07 21:36:18 -05:00
|
|
|
|
|
|
|
(it "alters environment variables"
|
|
|
|
(dolist (key '("A" "B" "C"))
|
|
|
|
(expect (getenv key) :not :to-be-truthy))
|
|
|
|
(expect (doom-load-envvars-file doom-env-file))
|
|
|
|
(expect (getenv "A") :to-equal "1")
|
|
|
|
(expect (getenv "B") :to-equal "2")
|
|
|
|
(expect (getenv "C") :to-equal "3"))))
|