Skip to content

Commit

Permalink
[CI] Add tests for exordium-require
Browse files Browse the repository at this point in the history
  • Loading branch information
pkryger committed Nov 17, 2024
1 parent 3eb9c28 commit 496f271
Show file tree
Hide file tree
Showing 3 changed files with 201 additions and 0 deletions.
1 change: 1 addition & 0 deletions .ci/unit-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ${EMACS} -Q --batch \
(load-file "'"${EMACS_DIR}"'/modules/init-forge.t.el")
(load-file "'"${EMACS_DIR}"'/modules/init-util.t.el")
(load-file "'"${EMACS_DIR}"'/modules/init-lib.t.el")
(load-file "'"${EMACS_DIR}"'/modules/init-require.t.el")
(let ((print-level 50)
(eval-expression-print-level 50)
(eval-expression-print-length 1000)
Expand Down
10 changes: 10 additions & 0 deletions modules/init-require.t-dummy.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
;;; init-require.t-dummy.el --- Dummy feature for init-require.t

;;; Commentary:
;;

;;; Code:

(provide 'init-require.t-dummy)

;;; init-require.t-dummy.el ends here
190 changes: 190 additions & 0 deletions modules/init-require.t.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
;;; init-require.t.el --- Tests for exordium-require -*- lexical-binding: t -*-

;;; Commentary:
;;
;; To run all tests:
;; M-x eval-buffer
;; M-x ert

;;; Code:

(eval-when-compile
(unless (featurep 'init-require)
(load (file-name-concat (locate-user-emacs-file "modules") "init-require"))))
(use-package use-package
:autoload (use-package-statistics-convert
use-package-reset-statistics))


(ert-deftest exordium-require-basic-call ()
(use-package-reset-statistics)
(ignore-errors (unload-feature 'init-require.t-dummy))
(let* ((byte-compile-current-file nil)
(use-package-compute-statistics nil))
(should (eq 'init-require.t-dummy
(eval '(exordium-require 'init-require.t-dummy)))))
(should (featurep 'init-require.t-dummy))
(should-error (use-package-statistics-convert 'init-require.t-dummy)))


(macroexpand '(ert-deftest exordium-require-while-byte-compile ()
(use-package-reset-statistics)
(ignore-errors (unload-feature 'init-require.t-dummy))
(let* ((byte-compile-current-file t)
(use-package-compute-statistics nil))
(should (eq 'init-require.t-dummy
(eval '(exordium-require 'init-require.t-dummy)))))
(should (featurep 'init-require.t-dummy))
(should-error (use-package-statistics-convert 'init-require.t-dummy))))

(ert-deftest exordium-require-with-stats ()
(use-package-reset-statistics)
(ignore-errors (unload-feature 'init-require.t-dummy))
(let* ((byte-compile-current-file nil)
(use-package-compute-statistics t))
(should (eq 'init-require.t-dummy
(eval '(exordium-require 'init-require.t-dummy)))))
(should (featurep 'init-require.t-dummy))
(should (use-package-statistics-convert 'init-require.t-dummy)))

(ert-deftest exordium-require-with-stats-while-byte-compile ()
(use-package-reset-statistics)
(ignore-errors (unload-feature 'init-require.t-dummy))
(let* ((byte-compile-current-file t)
(use-package-compute-statistics t))
(should (eq 'init-require.t-dummy
(eval '(exordium-require 'init-require.t-dummy)))))
(should (featurep 'init-require.t-dummy))
(should (use-package-statistics-convert 'init-require.t-dummy)))

(ert-deftest exordium-require-with-location ()
;; delay `exordium-require' macro expansion to test execution
(ignore-errors (unload-feature 'init-require.t-dummy))
(should (eq 'init-require.t-dummy
(eval '(exordium-require 'init-require.t-dummy "modules"))))
(should (featurep 'init-require.t-dummy)))


(ert-deftest exordium-require-swallow-error-when-called-with-non-existing-feature ()
(ignore-errors (unload-feature 'no-such-feature))
(let* ((debug-on-error nil))
(should-not (eq 'no-such-feature
(eval '(exordium-require 'no-such-feature)))))
(should-not (featurep 'no-such-feature)))

(ert-deftest exordium-require-signals-error-with-non-existing-feature-while-debug ()
"TODO: the `should-error' is not catching a file-missing signaled from `load'."
:expected-result :failed
(ignore-errors (unload-feature 'no-such-feature))
(let* ((debug-on-error t))
(should-error (eval '(exordium-require 'no-such-feature))))
(should-not (featurep 'no-such-feature)))

(ert-deftest exordium-require-swallow-error-when-called-with-non-existing-location ()
(ignore-errors (unload-feature 'init-require.t-dummy))
(let* ((debug-on-error nil))
(should-not (eq 'init-require.t-dummy
(eval '(exordium-require 'init-require.t-dummy "themes")))))
(should-not (featurep 'init-require.t-dummy)))

(ert-deftest exordium-require-signals-error-with-non-existing-location-while-debug ()
"TODO: the `should-error' is not catching a file-missing signaled from `load'."
:expected-result :failed
(ignore-errors (unload-feature 'init-require.t-dummy))
(let* ((debug-on-error t))
(should-error (eval '(exordium-require 'init-require.t-dummy "themes"))))
(should-not (featurep 'init-require.t-dummy)))


(ert-deftest exordium-require-signals-error-with-wrong-feature-type ()
(should-error (eval '(exordium-require nil)))
(should-error (eval '(exordium-require t)))
(should-error (eval '(exordium-require 42)))
(should-error (eval '(exordium-require ? )))
(should-error (eval '(exordium-require init-require.t-dummy)))
(should-error (eval '(exordium-require "init-require.t-dummy")))
(should-error (eval '(exordium-require
(if t 'init-require.t-dummy
init-require.t-dummy)))))

(ert-deftest exordium-require-signals-error-with-wrong-location-type ()
(should-error (eval '(exordium-require 'init-require.t-dummy t)))
(should-error (eval '(exordium-require 'init-require.t-dummy 42)))
(should-error (eval '(exordium-require 'init-require.t-dummy ? )))
(should-error (eval '(exordium-require 'init-require.t-dummy 'modules)))
(should-error (eval '(exordium-require
'init-require.t-dummy
(if t "modules" "themes")))))


(ert-deftest exordium-require-signals-error-with-wrong-defines-type ()
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines (nil))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines (t))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines (42))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines ("var"))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines ('var))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:defines ((if t 'var 'var))))))

(ert-deftest exordium-require-signals-error-with-wrong-functions-type ()
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (nil))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (t))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (42))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ("fn"))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ('fn))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (nil . (arg)))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (t . (arg)))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions (42 . (arg)))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ("fn" . (arg)))))
(should-error (eval '(exordium-require
'init-require.t-dummy
"modules"
:functions ('fn . (arg))))))

(provide 'init-require.t)

;;; init-require.t.el ends here

0 comments on commit 496f271

Please sign in to comment.