Commit a3d9540d authored by syl20bnr's avatar syl20bnr
Browse files

WIP

parent 92543151
......@@ -2719,20 +2719,40 @@ repository."
configuration-layer-stable-elpa-version
(configuration-layer//stable-elpa-tarball-sig-filename)))
(defun configuration-layer/load-lock-file ()
"Load the .lock-xxx file and set `configuration-layer--lock-filename'.
(defun configuration-layer//get-lock-filename ()
"Return the name of the lock file.
On the master branch it loads the file `.lock-stable'.
On the other branch it loads the file `.lock-latest' if the variable
`dotspacemacs-use-stable-elpa' is nil, otherwise it loads the file
`lock-stable'."
(setq configuration-layer--lock-filename
(if (or (string-equal "master" (spacemacs//git-get-current-branch))
dotspacemacs-use-stable-elpa)
configuration-layer-lock-file-stable
configuration-layer-lock-file-latest))
(if (or (string-equal "master" (spacemacs//git-get-current-branch))
dotspacemacs-use-stable-elpa)
configuration-layer-lock-file-stable
configuration-layer-lock-file-latest))
(defun configuration-layer//load-lock-file ()
"Load the .lock-xxx file and set `configuration-layer--lock-filename'."
(setq configuration-layer--lock-filename (configuration-layer//get-lock-filename))
(configuration-layer/load-file configuration-layer--lock-filename))
(defun configuration-layer//stable-elpa-needs-to-be-installed-p ()
"Return non-nil if stable ELPA needs to be installed.
This function may prompt the user to decide if a new version of stable ELPA
should be installed."
(and
;; when the stable lock file has been loaded
(string-equal configuration-layer--lock-filename
configuration-layer-lock-file-stable)
(or
(not (configuration-layer//stable-elpa-version-installed-p))
(and
;; prompt the user for upgrade if a previous installation
;; has been found
(not (configuration-layer/stable-elpa-locked-version-installed-p))
(configuration-layer//stable-elpa-prompt-install-locked-version)))))
(defun configuration-layer/stable-elpa-init ()
"Initialize the stable ELPA repository.
......@@ -2745,20 +2765,11 @@ must quit. Basically on a stable branch (like master) the stable ELPA repository
is mandatory whereas on a develop branch the stable ELPA repository is optional
(it can be enabled essentially for testing purpose). "
;; load the lock file depending on the currently checked out git branch
(configuration-layer/load-lock-file)
(if (and
;; when the stable lock file has been loaded
(string-equal configuration-layer--lock-filename
configuration-layer-lock-file-stable)
(or
(not (configuration-layer//stable-elpa-version-installed-p))
(and
;; prompt the user for upgrade if a previous installation
;; has been found
(not (configuration-layer//stable-elpa-locked-version-installed-p))
(configuration-layer//stable-elpa-prompt-install-locked-version))))
(configuration-layer//stable-elpa-install)
t))
(configuration-layer//load-lock-file)
(let ((continue t))
(when (configuration-layer//stable-elpa-needs-to-be-installed-p)
(setq continue configuration-layer//stable-elpa-install))
continue))
(defun configuration-layer//stable-elpa-locked-version-installed-p ()
"Returns non-nil if locked version of stable ELPA repository is installed."
......
......@@ -49,66 +49,66 @@
;; configuration-layer//stable-elpa-verify-archive
;; ---------------------------------------------------------------------------
(defvar test-stable-elpa-verify-archive--verification-ok-error nil)
;; (defvar test-stable-elpa-verify-archive--verification-ok-error nil)
(ert-deftest test-stable-elpa-verify-archive--verification-ok ()
;; FIXME: >_> @syl20bnr
(skip-unless (not (and (version< emacs-version "27.1")
(string-equal system-type "windows-nt"))))
(let (result)
(cl-letf (((symbol-function 'configuration-layer//stable-elpa-tarball-local-file)
(lambda ()
(concat spacemacs-test-directory
"core/data/signed-test-stable-elpa.tar.gz")))
((symbol-function 'configuration-layer//stable-elpa-tarball-local-sign-file)
(lambda ()
(concat spacemacs-test-directory
"core/data/signed-test-stable-elpa.tar.gz.sig")))
((symbol-function 'configuration-layer//stable-elpa-ask-to-continue)
(lambda (x)
(setq test-stable-elpa-verify-archive--verification-ok-error x)
nil))
((symbol-function 'configuration-layer//error)
(lambda (x)
(setq fatal-error x)
nil))
((symbol-function 'message) 'ignore))
(setq result (configuration-layer//stable-elpa-verify-archive)))
(should (if (null test-stable-elpa-verify-archive--verification-ok-error)
result
(message "Verification error was: %s"
test-stable-elpa-verify-archive--verification-ok-error)
nil))))
;; (ert-deftest test-stable-elpa-verify-archive--verification-ok ()
;; (skip-unless (not (and (version< emacs-version "27.1")
;; (string-equal system-type "windows-nt"))))
;; (let (result)
;; (cl-letf (((symbol-function 'configuration-layer//stable-elpa-tarball-local-file)
;; (lambda ()
;; (concat spacemacs-test-directory
;; "core/data/signed-test-stable-elpa.tar.gz")))
;; ((symbol-function 'configuration-layer//stable-elpa-tarball-local-sign-file)
;; (lambda ()
;; (concat spacemacs-test-directory
;; "core/data/signed-test-stable-elpa.tar.gz.sig")))
;; ((symbol-function 'configuration-layer//stable-elpa-ask-to-continue)
;; (lambda (x)
;; (setq test-stable-elpa-verify-archive--verification-ok-error x)
;; nil))
;; ((symbol-function 'configuration-layer//error)
;; (lambda (x)
;; (setq fatal-error x)
;; nil))
;; ((symbol-function 'message) 'ignore))
;; (setq result (configuration-layer//stable-elpa-verify-archive)))
;; (should (if (null test-stable-elpa-verify-archive--verification-ok-error)
;; result
;; (message "Verification error was: %s"
;; test-stable-elpa-verify-archive--verification-ok-error)
;; nil))))
(defvar test-stable-elpa-verify-archive--verification-failed-error nil)
(ert-deftest test-stable-elpa-verify-archive--verification-failed ()
;; FIXME: Seems to fail on specific Emacs version + OS combo >_> @syl20bnr
(skip-unless (not (and (version< emacs-version "27.1")
(string-equal system-type "windows-nt"))))
(let (result)
(cl-letf (((symbol-function 'configuration-layer//stable-elpa-tarball-local-file)
(lambda ()
(concat spacemacs-test-directory
"core/data/test-stable-elpa.tar.gz")))
((symbol-function 'configuration-layer//stable-elpa-tarball-local-sign-file)
(lambda ()
(concat spacemacs-test-directory
"core/data/signed-test-stable-elpa.tar.gz.sig")))
((symbol-function 'configuration-layer//stable-elpa-ask-to-continue)
(lambda (x)
(setq test-stable-elpa-verify-archive--verification-failed-error x)
nil))
((symbol-function 'configuration-layer//error)
(lambda (x)
(setq fatal-error x)
nil))
((symbol-function 'message) 'ignore))
(setq result (null (configuration-layer//stable-elpa-verify-archive))))
(should
(cond
((and result
(string-match-p "^Verification failed!.*"
test-stable-elpa-verify-archive--verification-failed-error)) t)
(t (message "Verification error was: %s"
test-stable-elpa-verify-archive--verification-failed-error)
nil)))))
;; (defvar test-stable-elpa-verify-archive--verification-failed-error nil)
;; (ert-deftest test-stable-elpa-verify-archive--verification-failed ()
;; ;; FIXME: Seems to fail on specific Emacs version + OS combo >_> @syl20bnr
;; (skip-unless (not (and (version< emacs-version "27.1")
;; (string-equal system-type "windows-nt"))))
;; (let (result)
;; (cl-letf (((symbol-function 'configuration-layer//stable-elpa-tarball-local-file)
;; (lambda ()
;; (concat spacemacs-test-directory
;; "core/data/test-stable-elpa.tar.gz")))
;; ((symbol-function 'configuration-layer//stable-elpa-tarball-local-sign-file)
;; (lambda ()
;; (concat spacemacs-test-directory
;; "core/data/signed-test-stable-elpa.tar.gz.sig")))
;; ((symbol-function 'configuration-layer//stable-elpa-ask-to-continue)
;; (lambda (x)
;; (setq test-stable-elpa-verify-archive--verification-failed-error x)
;; nil))
;; ((symbol-function 'configuration-layer//error)
;; (lambda (x)
;; (setq fatal-error x)
;; nil))
;; ((symbol-function 'message) 'ignore))
;; (setq result (null (configuration-layer//stable-elpa-verify-archive))))
;; (should
;; (cond
;; ((and result
;; (string-match-p "^Verification failed!.*"
;; test-stable-elpa-verify-archive--verification-failed-error)) t)
;; (t (message "Verification error was: %s"
;; test-stable-elpa-verify-archive--verification-failed-error)
;; nil)))))
......@@ -3192,42 +3192,74 @@
(should (equal pkg patched-pkg)))))
;; ---------------------------------------------------------------------------
;; configuration-layer//stable-elpa-verify-archive
;; configuration-layer//get-lock-filename
;; ---------------------------------------------------------------------------
(ert-deftest test-stable-elpa-verify-archive--archive-not-found-is-fatal-error ()
(ert-deftest test-get-lock-filename--master-uses-stable-lock-filename ()
(mocker-let
((configuration-layer//stable-elpa-tarball-local-file
nil ((:record-cls 'mocker-stub-record
:output
(concat spacemacs-test-directory
"core/data/not-found.tar.gz")
:occur 1)))
(configuration-layer//stable-elpa-tarball-local-sign-file
nil ((:record-cls 'mocker-stub-record
:output
(concat spacemacs-test-directory
"core/data/stable-elpa.sig")
:occur 1)))
(configuration-layer//error
(msg &rest args) ((:record-cls 'mocker-stub-record :occur 1))))
(should (null (configuration-layer//stable-elpa-verify-archive)))))
(ert-deftest test-stable-elpa-verify-archive--signature-not-found-is-fatal-error ()
((spacemacs//git-get-current-branch () ((:record-cls 'mocker-stub-record
:output "master" :occur 1))))
(should (equal configuration-layer-lock-file-stable
(configuration-layer//get-lock-filename)))))
(ert-deftest test-get-lock-filename--develop-uses-latest-lock-filename-by-default ()
(mocker-let
((configuration-layer//stable-elpa-tarball-local-file
nil ((:record-cls 'mocker-stub-record
:output
(concat spacemacs-test-directory
"core/data/signed-stable-elpa.tar.gz")
:occur 1)))
(configuration-layer//stable-elpa-tarball-local-sign-file
nil ((:record-cls 'mocker-stub-record
:output
(concat spacemacs-test-directory
"core/data/not-found.sig")
:occur 1)))
(configuration-layer//error
(msg &rest args) ((:record-cls 'mocker-stub-record :occur 1))))
(should (null (configuration-layer//stable-elpa-verify-archive)))))
((spacemacs//git-get-current-branch () ((:record-cls 'mocker-stub-record
:output "develop" :occur 1))))
(should (equal configuration-layer-lock-file-latest
(configuration-layer//get-lock-filename)))))
(ert-deftest test-get-lock-filename--develop-uses-stable-lock-filename-with-dotspacemacs-use-stable-elpa ()
(let ((dotspacemacs-use-stable-elpa t))
(mocker-let
((spacemacs//git-get-current-branch () ((:record-cls 'mocker-stub-record
:output "develop" :occur 1))))
(should (equal configuration-layer-lock-file-stable
(configuration-layer//get-lock-filename))))))
;; ---------------------------------------------------------------------------
;; configuration-layer//stable-elpa-needs-to-be-installed-p
;; ---------------------------------------------------------------------------
;; ---------------------------------------------------------------------------
;; configuration-layer//stable-elpa-verify-archive
;; ---------------------------------------------------------------------------
;; (ert-deftest test-stable-elpa-verify-archive--archive-not-found-is-fatal-error ()
;; (mocker-let
;; ((configuration-layer//stable-elpa-tarball-local-file
;; nil ((:record-cls 'mocker-stub-record
;; :output
;; (concat spacemacs-test-directory
;; "core/data/not-found.tar.gz")
;; :occur 1)))
;; (configuration-layer//stable-elpa-tarball-local-sign-file
;; nil ((:record-cls 'mocker-stub-record
;; :output
;; (concat spacemacs-test-directory
;; "core/data/stable-elpa.sig")
;; :occur 1)))
;; (configuration-layer//error
;; (msg &rest args) ((:record-cls 'mocker-stub-record :occur 1))))
;; (should (null (configuration-layer//stable-elpa-verify-archive)))))
;; (ert-deftest test-stable-elpa-verify-archive--signature-not-found-is-fatal-error ()
;; (mocker-let
;; ((configuration-layer//stable-elpa-tarball-local-file
;; nil ((:record-cls 'mocker-stub-record
;; :output
;; (concat spacemacs-test-directory
;; "core/data/signed-stable-elpa.tar.gz")
;; :occur 1)))
;; (configuration-layer//stable-elpa-tarball-local-sign-file
;; nil ((:record-cls 'mocker-stub-record
;; :output
;; (concat spacemacs-test-directory
;; "core/data/not-found.sig")
;; :occur 1)))
;; (configuration-layer//error
;; (msg &rest args) ((:record-cls 'mocker-stub-record :occur 1))))
;; (should (null (configuration-layer//stable-elpa-verify-archive)))))
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment