-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for hywconfig #416
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,15 @@ | ||
2023-12-07 Mats Lidell <[email protected]> | ||
|
||
* test/hywconfig-tests.el (hywconfig-tests--remove-ring) | ||
(hywconfig-tests--remove-names): Support functions for clearing the | ||
window config per frame. | ||
(hywconfig--inital-ring-is-empty, hywconfig--not-empty-if-ring-save) | ||
(hywconfig--number-of-configs-are-store-up-to-a-max) | ||
(hywconfig--empty-after-pop-ring-with-one-config) | ||
(hywconfig--max-minus-one-after-pop-ring-with-max-config) | ||
(hywconfig--get-not-existing-config-fails, hywconfig--add-by-name) | ||
(hywconfig--delete-by-name): Tests. | ||
|
||
2023-12-01 Mats Lidell <[email protected]> | ||
|
||
* hmouse-tag.el (ibtype:def-symbol): Declare function to silence warning. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
;;; hywconfig-tests.el --- unit tests for hywconfig -*- lexical-binding: t; -*- | ||
|
||
;; Author: Mats Lidell <[email protected]> | ||
;; | ||
;; Orig-Date: 30-Jan-21 at 12:00:00 | ||
;; Last-Mod: 7-Dec-23 at 23:17:36 by Mats Lidell | ||
;; | ||
;; SPDX-License-Identifier: GPL-3.0-or-later | ||
;; | ||
;; Copyright (C) 2023 Free Software Foundation, Inc. | ||
;; See the "HY-COPY" file for license information. | ||
;; | ||
;; This file is part of GNU Hyperbole. | ||
|
||
;;; Commentary: | ||
|
||
;; Unit tests for "../hywconfig.el" | ||
|
||
;;; Code: | ||
|
||
(require 'hywconfig) | ||
(require 'ert) | ||
|
||
(defun hywconfig-tests--remove-ring () | ||
"Remove ring from frame parameters." | ||
(set-frame-parameter nil 'hywconfig-ring nil)) | ||
|
||
(defun hywconfig-tests--remove-names () | ||
"Remove names from frame parameters." | ||
(set-frame-parameter nil 'hywconfig-names nil)) | ||
|
||
(ert-deftest hywconfig--inital-ring-is-empty () | ||
"Verify an initial ring is empty." | ||
(hywconfig-tests--remove-ring) | ||
(should (hywconfig-ring-empty-p))) | ||
|
||
(ert-deftest hywconfig--not-empty-if-ring-save () | ||
"Verify ring is not empty after saving a configuration." | ||
(hywconfig-tests--remove-ring) | ||
(hywconfig-ring-save) | ||
(should-not (hywconfig-ring-empty-p))) | ||
|
||
(ert-deftest hywconfig--number-of-configs-are-store-up-to-a-max () | ||
"Verify there is a max of number of configuration that can be saved." | ||
(let ((hywconfig-ring-max 2)) | ||
(hywconfig-tests--remove-ring) | ||
(hywconfig-ring-save) | ||
(hywconfig-ring-save) | ||
(should (= (ring-length (hywconfig-get-ring)) hywconfig-ring-max)) | ||
(hywconfig-ring-save) | ||
(should (= (ring-length (hywconfig-get-ring)) hywconfig-ring-max)))) | ||
|
||
(ert-deftest hywconfig--empty-after-pop-ring-with-one-config () | ||
"Verify ring is not empty after saving a configuration." | ||
(hywconfig-tests--remove-ring) | ||
(hywconfig-ring-save) | ||
(hywconfig-delete-pop) | ||
(should (hywconfig-ring-empty-p))) | ||
|
||
(ert-deftest hywconfig--max-minus-one-after-pop-ring-with-max-config () | ||
"Verify ring is not empty after saving a configuration." | ||
(let ((hywconfig-ring-max 2)) | ||
(hywconfig-tests--remove-ring) | ||
(hywconfig-ring-save) | ||
(hywconfig-ring-save) | ||
(hywconfig-delete-pop) | ||
(should (= (ring-length (hywconfig-get-ring)) (1- hywconfig-ring-max))))) | ||
|
||
(ert-deftest hywconfig--get-not-existing-config-errors () | ||
"Verify retrieving a config that has not been saved gives an error message." | ||
(hywconfig-tests--remove-names) | ||
(let ((err (should-error (hywconfig-restore-by-name "config") :type 'error))) | ||
(should (string-match-p "No window configuration for this frame named" (cadr err))))) | ||
|
||
(ert-deftest hywconfig--add-by-name () | ||
"Verify config is added by name." | ||
:expected-result :failed | ||
;; See backtrace for the error - (wrong-type-argument listp #<window-configuration>) | ||
;; set:member("config" (#<window-configuration>)) | ||
;; set:get("config" (#<window-configuration>)) | ||
;; (let ((wconfig (set:get name (hywconfig-get-names)))) (if wconfig (progn (hywconfig-set-window-configuration wconfig) (if (called-interactively-p 'interactive) (progn (message "Window configuration `%s' is now active." name)))) (error "(hywconfig-restore-by-name): No window configuration for this frame named `%s'" name))) | ||
;; (cond ((null name) (message "There is no named window configuration to restore.")) ((not (stringp name)) (error "(hywconfig-restore-by-name): `name' argument is not a string: %s" name)) (t (let ((wconfig (set:get name (hywconfig-get-names)))) (if wconfig (progn (hywconfig-set-window-configuration wconfig) (if (called-interactively-p 'interactive) (progn (message "Window configuration `%s' is now active." name)))) (error "(hywconfig-restore-by-name): No window configuration for this frame named `%s'" name))))) | ||
;; hywconfig-restore-by-name("config") | ||
;; [...] | ||
(hywconfig-tests--remove-names) | ||
(hywconfig-add-by-name "config") | ||
(should (hywconfig-restore-by-name "config"))) | ||
|
||
(ert-deftest hywconfig--delete-by-name () | ||
"Verify config can be deleted by name." | ||
:expected-result :failed | ||
;; Same error as above | ||
(hywconfig-tests--remove-names) | ||
(hywconfig-add-by-name "config") | ||
(hywconfig-delete-by-name "config") | ||
(let ((err (should-error (hywconfig-restore-by-name "config") :type 'error))) | ||
(should (string--p "No window configuration for this frame named" (cadr err))))) | ||
|
||
(provide 'hywconfig-tests) | ||
;;; hywconfig-tests.el ends here |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is the error. set:member gets a list instead of a single window-config!? Sounds related to the error in the current TODOs.
Both failing test cases are set with :expected-result :failed to not break the CI-build and make it easier to merge the PR for later updates related to the error. i.e. if you approve of the tests they can go in and then we can work on the fix in a separate PR.