branch: externals/realgud commit 8beb4f5f2b2fd893dee853d23b09b979dcd30ba3 Merge: ad333ac 83d471f Author: R. Bernstein <ro...@users.noreply.github.com> Commit: GitHub <nore...@github.com>
Merge pull request #182 from roymath/master fixed unload; added ert-based tests for realgud --- realgud.el | 42 ++++++++----------------------- test/test-realgud.el | 70 ++++++++++++++++++++++++++++++---------------------- 2 files changed, 50 insertions(+), 62 deletions(-) diff --git a/realgud.el b/realgud.el index dde1b50..eb370df 100644 --- a/realgud.el +++ b/realgud.el @@ -113,42 +113,20 @@ ) (defun realgud:loaded-features() - "Return a list of loaded debugger features. These are the -features that start with 'realgud-' and also include standalone debugger features -like 'pydbgr'." - (let ((result nil) - (feature-str)) - (dolist (feature features result) - (setq feature-str (symbol-name feature)) - (cond ((eq 't - (string-prefix-p feature-str "realgud-")) - (setq result (cons feature-str result))) - ((eq 't - (string-prefix-p feature-str "nodejs")) - (setq result (cons feature-str result))) - ((eq 't - ;; No trailing '-' to get a plain "trepan". - (string-prefix-p feature-str "trepan")) - (setq result (cons feature-str result))) - ((eq 't - ;; No trailing '-' to get a plain "trepanx". - (string-prefix-p feature-str "trepanx")) - (setq result (cons feature-str result))) - ('t nil)) - ) - ) -) + "Return a list of loaded debugger features. These are the features +that start with 'realgud-' and 'realgud:'" + + (delq nil + (mapcar (lambda (x) (and (string-match-p "^\\(realgud:\\|realgud-\\)" (symbol-name x)) x)) + features))) (defun realgud:unload-features() "Remove all features loaded from this package. Used in `realgud:reload-features'. See that." - (interactive "") - (let ((result (realgud:loaded-features))) - (dolist (feature result result) - (unless (symbolp feature) (setq feature (make-symbol feature))) - (if (featurep feature) - (unload-feature feature) 't)) - )) + (let ((removal-set (realgud:loaded-features))) + (dolist (feature removal-set) + (unload-feature feature t)) + removal-set)) ; return removed set (defun realgud:reload-features() "Reload all features loaded from this package. Useful if have diff --git a/test/test-realgud.el b/test/test-realgud.el index 2e7d09e..6cb1cab 100644 --- a/test/test-realgud.el +++ b/test/test-realgud.el @@ -1,31 +1,41 @@ -;; Press C-x C-e at the end of the next line to run this file test non-interactively -;; (test-simple-run "emacs -batch -L %s -l %s" (file-name-directory (locate-library "test-simple.elc")) buffer-file-name) +;; Manually run these tests as follows: +;; +;; emacs --batch --no-site-file --no-splash \ +;; --script setup.el --chdir PACAKGESDIR/realgud \ +;; -l test/test-realgud.el -f ert-run-tests-batch-and-exit +;; +;; where setup.el looks something like: +;; (let ((elpa-dir (expand-file-name "~/.emacs.d/elpa"))) +;; (add-to-list 'load-path (concat elpa-dir "/test-simple-20170117.411")) +;; (add-to-list 'load-path (concat elpa-dir "/load-relative-20160716.438")) +;; (add-to-list 'load-path (concat elpa-dir "/loc-changes-20160801.1008"))) + +(defun realgud-test-helper() + (delq nil + (mapcar (lambda (x) (and (string-match-p "^\\(realgud:\\|realgud-\\)" (symbol-name x)) x)) + features))) + +(ert-deftest test-feature-unload() + + ;; no realgud features exist by default + (should (= 0 (length (realgud-test-helper)))) + (should-not (member 'realgud-pdb features)) + + (load-file "realgud.el") ; manually load the first time + + ;; we should now have realgud features; + (should-not (= 0 (length (realgud-test-helper)))) + (should (member 'realgud-pdb features)) + ;; test at least 1 by name + (should (member 'realgud-pdb features)) + + ;; unload all and test + (let ((removed (realgud:unload-features))) + (should-not (= 0 (length removed)))) ; check that we return removed values + (let ((removed (realgud:unload-features))) ; should not err out if called on empty. + (should (= 0 (length removed)))) + + (realgud:load-features) ; load and test + (should-not (= 0 (length (realgud-test-helper)))) + (should (member 'realgud-pdb features))) -(require 'test-simple) -(load-file "../realgud.el") - -(declare-function realgud:loaded-features 'realgud) -(declare-function realgud:unload-features 'realgud-regexp) -(declare-function __FILE__ 'load-relative) - -(test-simple-start) - -(eval-when-compile - (defvar test-realgud:features) -) - -(note "realgud") - -(note "realgud:loaded-features") -(set (make-local-variable 'test-realgud:features) (realgud:loaded-features)) -;; (dolist (feature '(realgud-trepan -;; realgud-core)) -;; (assert-t (not (not (member feature test-realgud:features)))) ) - -(note "realgud-unload-features") -(load-file "../realgud.el") -(assert-nil (not (realgud:loaded-features))) -(assert-nil (not (realgud:unload-features))) -(realgud:loaded-features) - -(end-tests)