[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/buttercup fce5fa5 313/340: Optionally fail when loading ol
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/buttercup fce5fa5 313/340: Optionally fail when loading old elc files |
Date: |
Thu, 16 Dec 2021 14:59:57 -0500 (EST) |
branch: elpa/buttercup
commit fce5fa53592990f00289044adb037744cc1b8df0
Author: Ola Nilsson <ola.nilsson@gmail.com>
Commit: Ola Nilsson <ola.nilsson@gmail.com>
Optionally fail when loading old elc files
The new --stale-file-error option can be used to activate a hook that
will signal an error if a stale .elc file is loaded. Stale means
older than its originating .el file.
Fixes #142.
---
bin/buttercup | 8 +++++++-
buttercup-compat.el | 11 +++++++++++
buttercup.el | 29 +++++++++++++++++++++++++++++
tests/test-buttercup.el | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 96 insertions(+), 1 deletion(-)
diff --git a/bin/buttercup b/bin/buttercup
index 92a94fc..8562905 100755
--- a/bin/buttercup
+++ b/bin/buttercup
@@ -56,6 +56,8 @@ Buttercup options:
frame with a lambda or M to indicate whether
it is a normal function call or a
macro/special form.
+
+--stale-file-error Fail the test run if stale .elc files are loaded.
EOF
}
@@ -81,7 +83,7 @@ do
shift
shift
;;
- "-c"|"--no-color"|"--no-skip"|"--only-error")
+ "-c"|"--no-color"|"--no-skip"|"--only-error"|"--stale-file-error")
BUTTERCUP_ARGS+=("$1")
shift
;;
@@ -100,3 +102,7 @@ done
# `--' is needed so that Buttercup options don't get parsed by Emacs itself.
exec "$EMACS_BIN" -batch "${EMACS_ARGS[@]}" -l buttercup -f
buttercup-run-discover -- "${BUTTERCUP_ARGS[@]}"
+
+# Local Variables:
+# indent-tabs-mode: nil
+# End:
diff --git a/buttercup-compat.el b/buttercup-compat.el
index d70bd62..792a8c8 100644
--- a/buttercup-compat.el
+++ b/buttercup-compat.el
@@ -109,6 +109,17 @@ If INCLUDE-DIRECTORIES, also include directories that have
matching names."
(<= (car here) delay)))
(concat (format "%.2f" (/ delay (car (cddr here)))) (cadr
here)))))))
+;;;;;;;;;;;;;;;;;;;;;
+;; Introduced in 26.1
+
+(unless (fboundp 'file-attribute-modification-time)
+ (defsubst file-attribute-modification-time (attributes)
+ "The modification time in ATTRIBUTES returned by `file-attributes'.
+This is the time of the last change to the file's contents, and
+is a Lisp timestamp in the style of `current-time'."
+ (nth 5 attributes)))
+
+
(provide 'buttercup-compat)
;;; buttercup-compat.el ends here
diff --git a/buttercup.el b/buttercup.el
index c10c3b4..cbfa04e 100644
--- a/buttercup.el
+++ b/buttercup.el
@@ -1386,6 +1386,9 @@ current directory."
(push 'pending buttercup-reporter-batch-quiet-statuses)
(push 'passed buttercup-reporter-batch-quiet-statuses)
(setq args (cdr args)))
+ ((equal (car args) "--stale-file-error")
+ (buttercup-install-old-elc-error)
+ (setq args (cdr args)))
(t
(push (car args) dirs)
(setq args (cdr args)))))
@@ -2003,6 +2006,32 @@ With buttercup minor mode active the following is
activated:
(cl-dolist (form imenu-forms)
(setq imenu-generic-expression (delete form
imenu-generic-expression))))))
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;;; Signal errors when files have to be recompiled
+
+(defun buttercup-check-for-stale-elc (elc-file)
+ "Raise an error when ELC-FILE is an elc-file and older than its el-file."
+ (when (string= (file-name-extension elc-file) "elc")
+ (let ((el-file (substring elc-file 0 -1)))
+ (when (and (file-exists-p el-file)
+ (time-less-p
+ (file-attribute-modification-time (file-attributes elc-file))
+ (file-attribute-modification-time (file-attributes
el-file))))
+ (error "%s is newer than %s" el-file elc-file)))))
+
+(defun buttercup-error-on-stale-elc (&optional arg)
+ "Activate errors when an stale (older than .el) .elc-file is loaded.
+
+Enable the functionality if ARG is omitted or nil, toggle it if
+ARG is ‘toggle’; disable otherwise."
+ (cond ((null arg)
+ (add-hook 'after-load-functions #'buttercup-check-for-stale-elc))
+ ((eq arg 'toggle)
+ (if (memq 'buttercup-check-for-stale-elc after-load-functions)
+ (remove-hook 'after-load-functions
#'buttercup-check-for-stale-elc)
+ (add-hook 'after-load-functions #'buttercup-check-for-stale-elc)))
+ (t (remove-hook 'after-load-functions
#'buttercup-check-for-stale-elc))))
+
;; Local Variables:
;; indent-tabs-mode: nil
;; sentence-end-double-space: nil
diff --git a/tests/test-buttercup.el b/tests/test-buttercup.el
index 41236aa..b9fbf54 100644
--- a/tests/test-buttercup.el
+++ b/tests/test-buttercup.el
@@ -1649,6 +1649,55 @@ text properties using `ansi-color-apply'."
(expect (length (cdr specs)) :to-equal 1)
(expect (cl-caadr specs) :to-equal "should fontify special
keywords")))))
+;;;;;;;;;;;;;;;;;;;
+;;; Stale elc files
+
+(describe "For stale `elc' file checks"
+ (describe "`buttercup-check-for-stale-elc'"
+ :var (el-time elc-time)
+ (before-each
+ (spy-on 'file-attributes :and-call-fake
+ (lambda (filename &optional id-format)
+ (make-list
+ 10
+ (make-list 4
+ (pcase (file-name-extension filename)
+ ("elc" elc-time)
+ ("el" el-time)))))))
+ (it "should do nothing for `el' files"
+ (setq el-time 2 ;; elc is older than el
+ elc-time 1)
+ (expect (buttercup-check-for-stale-elc "buttercup.el") :not :to-throw))
+ (it "should signal error when `elc' is older than `el'"
+ (setq el-time 2 ;; elc is older than el
+ elc-time 1)
+ (expect (buttercup-check-for-stale-elc "buttercup.elc") :to-throw))
+ (it "should not signal error when `elc' is newer than `el'"
+ (setq el-time 2 ;; elc is older than el
+ elc-time 3)
+ (expect (buttercup-check-for-stale-elc "buttercup.elc") :not :to-throw))
+ (it "should do nothing if the `el' file does not exist"
+ (setq el-time 3 ;; el is older than elc
+ elc-time 2)
+ (spy-on 'file-exists-p)
+ (expect (buttercup-check-for-stale-elc "buttercup.elc") :not :to-throw)))
+
+ (describe "`buttercup-error-on-stale-elc'"
+ (it "should activate with no argument"
+ (let (after-load-functions)
+ (buttercup-error-on-stale-elc)
+ (expect after-load-functions :to-contain
'buttercup-check-for-stale-elc)))
+ (it "should deactivate with almost any argument"
+ (let ((after-load-functions '(buttercup-check-for-stale-elc)))
+ (buttercup-error-on-stale-elc 2)
+ (expect after-load-functions :not :to-contain
'buttercup-check-for-stale-elc)))
+ (it "should toggle when given `toggle' as argument"
+ (let (after-load-functions)
+ (buttercup-error-on-stale-elc 'toggle)
+ (expect after-load-functions :to-contain
'buttercup-check-for-stale-elc)
+ (buttercup-error-on-stale-elc 'toggle)
+ (expect after-load-functions :not :to-contain
'buttercup-check-for-stale-elc)))))
+
;; Local Variables:
;; indent-tabs-mode: nil
;; sentence-end-double-space: nil
- [nongnu] elpa/buttercup 243b71f 245/340: Merge branch 'spy-scope-error', (continued)
- [nongnu] elpa/buttercup 243b71f 245/340: Merge branch 'spy-scope-error', ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f3c2b00 261/340: test: Move with-local-buttercup to top of file, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0dbd474 263/340: Bump version: 1.20 → 1.21, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 1c9c82f 265/340: Fixed misspelling in the documentation, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 360953b 266/340: test: Only run tests found in the tests/ directory, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 25bc00d 273/340: test: Set up suite "The batch reporter" to use fake terminal, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 5c9f80d 279/340: test: Add color tests for buttercup-suite-started and -done, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 2be9ad3 280/340: test: Add color tests for spec-done, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 0e94f6e 303/340: Lift buttercup-done handling into buttercup-reporter-batch, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f1f403b 308/340: Remove buttercup-reporter-batch-color, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup fce5fa5 313/340: Optionally fail when loading old elc files,
ELPA Syncer <=
- [nongnu] elpa/buttercup 6c3bb75 318/340: Accept a list of regexes in buttercup-mark-skipped, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 9dda405 320/340: Document use with Eldev, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 06201f2 335/340: Print :to-have-been-called-with args as sexp for consistency, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 459bffb 282/340: test: Add color tests for buttercup-done, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a1c7bff 101/340: Do not ignore errors when after-each succeeds, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup b120003 108/340: Merge pull request #60 from howdoicomputer/feature/windows-bin-support, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup 06c9699 104/340: Merge pull request #58 from Fuco1/to-equal-as-set, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup a6d9bde 105/340: Support more emacs parameters useful for pre-test initialization, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup abf2abe 109/340: Exclude hidden files and dirs in test root, ELPA Syncer, 2021/12/16
- [nongnu] elpa/buttercup f60ed2a 119/340: Bump version: 1.5 → 1.6, ELPA Syncer, 2021/12/16