[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/bash-completion a789093cd3 155/313: Run tests on older ver
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/bash-completion a789093cd3 155/313: Run tests on older versions of Emacs. |
Date: |
Sat, 3 Dec 2022 10:59:26 -0500 (EST) |
branch: elpa/bash-completion
commit a789093cd32b2007cb64943de30aca51d5b3106b
Author: Stephane Zermatten <szermatt@gmx.net>
Commit: Stephane Zermatten <szermatt@gmx.net>
Run tests on older versions of Emacs.
While bash-completion.el is supposed to run under Emacs 22, 23, 24 or
25, the tests rely on features that are not available on older
versions, especially ERT.
This commit introduces just enough macros and helpers to run the tests
under Emacs 22, in test/pre24.el. It is loaded when tests are run
under older versions of Emacs. Running tests under Emacs 22 works best
when tests are started from the command-line.
---
test/bash-completion-integration-test.el | 11 +++-
test/bash-completion-test.el | 4 +-
test/pre24.el | 105 +++++++++++++++++++++++++++++++
3 files changed, 117 insertions(+), 3 deletions(-)
diff --git a/test/bash-completion-integration-test.el
b/test/bash-completion-integration-test.el
index 9f8b1fe5f8..98b2b6c2cc 100644
--- a/test/bash-completion-integration-test.el
+++ b/test/bash-completion-integration-test.el
@@ -30,7 +30,12 @@
;;; Code:
(require 'bash-completion)
-(require 'ert)
+(require 'dired)
+
+(if (>= emacs-major-version 24)
+ (require 'ert)
+ (require 'pre24)
+ (require 'dired))
(defmacro bash-completion_test-harness (&rest body)
`(progn
@@ -99,7 +104,9 @@ for testing completion."
(defun bash-completion_test-teardown-env (test-env-dir)
"Deletes everything `bash-completion_test-setup-env' set up."
(when test-env-dir
- (delete-directory test-env-dir 'recursive)))
+ (if (>= emacs-major-version 24)
+ (delete-directory test-env-dir 'recursive)
+ (dired-delete-file test-env-dir 'always))))
(ert-deftest bash-completion-integration-test ()
(skip-unless (file-executable-p bash-completion-prog))
diff --git a/test/bash-completion-test.el b/test/bash-completion-test.el
index fb4f098662..5983e5e775 100644
--- a/test/bash-completion-test.el
+++ b/test/bash-completion-test.el
@@ -31,7 +31,9 @@
;;; Code:
(require 'bash-completion)
(require 'cl)
-(require 'ert)
+(if (>= emacs-major-version 24)
+ (require 'ert)
+ (require 'pre24))
(defmacro bash-completion-test-with-buffer (content &rest body)
"Create a temporary buffer with CONTENT and execute BODY.
diff --git a/test/pre24.el b/test/pre24.el
new file mode 100644
index 0000000000..240d711967
--- /dev/null
+++ b/test/pre24.el
@@ -0,0 +1,105 @@
+;;; pre24.el --- run bash-completion tests under Emacs 22 and 23
+
+;; Copyright (C) 2017 Stephane Zermatten
+
+;; Author: Stephane Zermatten <szermatt@gmx.net>
+
+;; This program is free software: you can redistribute it and/or
+;; modify it under the terms of the GNU General Public License as
+;; published by the Free Software Foundation; either version 2 of the
+;; License, or (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see
+;; `http://www.gnu.org/licenses/'.
+
+
+;;; Commentary:
+;;
+;; This file defines just enough macros and functions to run the
+;; bash-completion tests on Emacs 22 and 23 from the command line, using
+;; run_tests.sh.
+;;
+;; When this is used, the tests are run immediately, as they are
+;; defined. This file isn't meant to be used from an interactive emacs
+;; session.
+;;
+
+;;; Code:
+(require 'cl)
+(require 'dired)
+
+(if (>= emacs-major-version 24)
+ (error "Don't use pre24.el with Emacs 24 or later."))
+
+(defvar pre24-error-count 0
+ "Number of errors encountered by `ert-deftest'.
+
+`ert-run-tests-batch-and-exit' relies on this to exit with the
+appropriate return code.")
+
+(defmacro ert-deftest (name args &rest body)
+ "Run a test and reports the result."
+ `(let ((pre24-test (symbol-name (quote ,name))))
+ (princ (format "%s..." pre24-test))
+ (princ (catch 'pre24-return (prog1 "OK" (progn ,@body))))
+ (princ "\n")))
+
+(defmacro should (&rest body)
+ "Fail the containing `ert-deftest' unless BODY is t."
+ `(unless (progn ,@body)
+ (setq pre24-error-count (1+ pre24-error-count))
+ (throw 'pre24-return
+ (format "FAILED\n (should %s)\n\n"
+ (quote ,@body)))))
+
+(defmacro should-not (&rest body)
+ "Fail the containing `ert-deftest' unless BODY is not t."
+ `(when (progn ,@body)
+ (error "Test failed")))
+
+(defun skip-unless (condition)
+ "Skip the test if CONDITION doesn't hold."
+ (unless condition (throw 'pre24-return "SKIP")))
+
+(defmacro cl-letf (definitions &rest body)
+ "Backward-compatibility adapter for cl-letf.
+
+This macro only supports redefining symbol functions."
+ `(flet ,(mapcar
+ (lambda (def)
+ ;; ((symbol-function ',name) (lambda ,args ,func-body))
+ (let ((lhs (car def)) (rhs (cadr def)))
+ (unless (and (eq 'symbol-function (car lhs))
+ (eq 'quote (car (nth 1 lhs)))
+ (eq 'lambda (car rhs)))
+ "Unsupported pattern")
+ (cons (cadr (cadr (car def))) ; name
+ (cons
+ (car (cdr (cadr def))) ; args
+ (cdr (cdr (cadr def))) ; func-body
+ ))))
+ definitions)
+ ,@body))
+
+
+(defun ert-run-tests-batch-and-exit ()
+ "Exit tests.
+
+Exit status is 1 if at least on test run with `ert-deftest'
+failed."
+ (if (> pre24-error-count 0)
+ (progn
+ (princ "FAIL")
+ (kill-emacs 1)))
+ (progn
+ (princ "PASS\n")
+ (kill-emacs 0)))
+
+(provide 'pre24)
+;;; pre24.el ends here
- [nongnu] elpa/bash-completion 5209200f3b 120/313: Using cl-letf instead of flet., (continued)
- [nongnu] elpa/bash-completion 5209200f3b 120/313: Using cl-letf instead of flet., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9588a9c0dd 125/313: Updated README, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion c5f2b2756f 129/313: Define sz-testutils as a global variable., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f085c41d8d 131/313: Add defcustom for bash-completion-args, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 8ca917f428 133/313: Stop escaping = in completion. fixes #18, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 319886faa9 138/313: Add / after directory names - even if they contain spaces or special, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f2ea2b65df 141/313: Detect directories when expanding commands and add a slash instead of a, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 44bc73449e 144/313: Fixes strange behavior when completing --., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion b4757884b0 145/313: Expand the tests to better cover wordbreak and command argument, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 6ab1fe406b 148/313: Always quote the stub before passing it to compgen., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion a789093cd3 155/313: Run tests on older versions of Emacs.,
ELPA Syncer <=
- [nongnu] elpa/bash-completion 5e05365dc8 153/313: Cleanup tests, split them into unit and integration tests., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 09c93ffbdb 165/313: Explicitly disable support for Emacs version older than 24.1., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 62c6567af6 158/313: Complete argument rename, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 5eb85cf1fc 166/313: Remove obsolete functions bash-completion-dynamic-complete-0 and, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 9b94818f88 167/313: Remove support for pre-Emacs24.1 backward compatibility., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 912e1e8153 170/313: Add an option to disable default Readline completion when no matches are found (#29), ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 959e27dae3 171/313: Add remote shell support, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 68f7d937b7 175/313: Make wordbreak completion work with bash-completion-enable-caching., ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion 2cf76221c2 178/313: Rely on compgen for default completion, instead of doing it with, ELPA Syncer, 2022/12/03
- [nongnu] elpa/bash-completion f01d8726de 179/313: Remove support filenames options., ELPA Syncer, 2022/12/03