aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew White <mehw.is.me@inventati.org>2021-07-10 04:11:28 +0000
committerMatthew White <mehw.is.me@inventati.org>2021-10-20 23:01:53 +0200
commit6aa369c1ea7694b1dd5a4e1d9cb5f64564e04234 (patch)
tree302a30ed4324e1bd4d2bfd402a8efabfcb87205f
parent4408cf4674c9f3e85b029e704799a6bd95cb541a (diff)
basic-persp-creation-deletion: test killing all perspectives
Test 'persp-current-name' and also killing the main perspective. When killing the main perspective, preserve the *ert* buffer when the tests are run interactively, and always preserve *Messages*, because it's an ert's requirement for properly executing tests.
-rw-r--r--CHANGELOG.md1
-rw-r--r--test/test-perspective.el51
2 files changed, 48 insertions, 4 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 95f530d..71dbab9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### ERT tests changed
+- `basic-persp-creation-deletion`: test killing all perspectives, main perspective included.
- `persp-test-with-persp`: `unwind-protect` BODY to ensure a proper cleanup upon failures.
- `persp-test-with-persp`: kill other perspectives than the main perspective when cleaning up.
diff --git a/test/test-perspective.el b/test/test-perspective.el
index 16feb5f..28798a0 100644
--- a/test/test-perspective.el
+++ b/test/test-perspective.el
@@ -639,16 +639,59 @@ local value of it is a mistake."
(kill-buffer "*dummy*")))
(ert-deftest basic-persp-creation-deletion ()
+ "Switching to a non-existing perspective should create the new
+perspective. Switching to an existing perspective should not
+duplicate the perspective. Creating a new perspective should
+not automatically switch to the perspective."
(persp-test-with-persp
- (should (equal (list "main") (persp-names)))
+ (should (equal (persp-current-name) "main"))
+ (should (equal (list "main") (sort (persp-names) #'string-lessp)))
+ ;; test if switching to a non-existing perspective also creates it
(persp-switch "A")
+ (should (equal (persp-current-name) "A"))
(should (equal (list "A" "main") (sort (persp-names) #'string-lessp)))
+ ;; test if creating a new perspective switches to it automatically
+ (persp-new "B")
+ (should (equal (persp-current-name) "A"))
+ (should (equal (list "A" "B" "main") (sort (persp-names) #'string-lessp)))
+ ;; test if switching to an existing perspective duplicates it
(persp-switch "B")
+ (should (equal (persp-current-name) "B"))
(should (equal (list "A" "B" "main") (sort (persp-names) #'string-lessp)))
- (persp-kill "A")
+ (persp-switch "A")
+ (should (equal (persp-current-name) "A"))
+ (should (equal (list "A" "B" "main") (sort (persp-names) #'string-lessp)))
+ ;; kill the current perspective to see where we land
+ (persp-kill (persp-current-name))
+ (should (equal (persp-current-name) "B"))
(should (equal (list "B" "main") (sort (persp-names) #'string-lessp)))
- (persp-kill "B")
- (should (equal (list "main") (persp-names)))))
+ (persp-kill (persp-current-name))
+ (should (equal (persp-current-name) "main"))
+ (should (equal (list "main") (sort (persp-names) #'string-lessp)))
+ ;; sanity checks before killing the main perspective
+ (should (get-buffer "*Messages*"))
+ (should (get-buffer-create "*scratch*"))
+ (persp-set-buffer (get-buffer "*scratch*"))
+ (let ((ert-buffer (get-buffer "*ert*"))
+ (msg-buffer (get-buffer "*Messages*")))
+ ;; interactively run ert requires the *ert* buffer
+ (setf (persp-current-buffers) (remq ert-buffer (persp-current-buffers)))
+ ;; the *Messages* buffer is also ert's requiremet
+ (setf (persp-current-buffers) (remq msg-buffer (persp-current-buffers)))
+ ;; *scratch* is in main, not *ert* and *Messages*
+ (should (persp-test-buffer-in-persps "*scratch*" "main"))
+ (should-not (persp-test-buffer-in-persps ert-buffer "main"))
+ (should-not (persp-test-buffer-in-persps msg-buffer "main"))
+ ;; kill the main perspective except above buffers
+ (persp-kill (persp-current-name))
+ ;; the *scratch* buffer should have been killed
+ (should-not (get-buffer "*scratch*"))
+ ;; *ert* is needed by interactively run tests
+ (should (eq ert-buffer (get-buffer "*ert*")))
+ ;; the *Messages* buffer is needed by ert
+ (should (eq msg-buffer (get-buffer "*Messages*")))))
+ ;; cleanup
+ (should (get-buffer-create "*scratch*")))
(ert-deftest basic-persp-switching ()
(persp-test-with-persp