From 18c5a08dfb377d13afe463f5892ee2aa575b9e66 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 6 Nov 2014 09:00:10 +0000 Subject: Add tests for the question-list --- test/tests.el | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index efad2d0..9bf63fd 100644 --- a/test/tests.el +++ b/test/tests.el @@ -6,7 +6,10 @@ (unintern symbol))))) ;;; Tests -(defvar stack-test-data-dir "data-samples/" +(defvar stack-test-data-dir + (expand-file-name + "data-samples/" + (or load-file-name "./")) "") (defun stack-test-sample-data (method &optional directory) @@ -31,10 +34,11 @@ (require 'stack-core) (require 'stack-question) +(require 'stack-question-list) (ert-deftest test-basic-request () - "Test basic request functionality" - (should (stack-core-make-request "sites"))) + "Test basic request functionality" + (should (stack-core-make-request "sites"))) (ert-deftest test-question-retrieve () "Test the ability to receive a list of questions." @@ -53,7 +57,7 @@ '((1 . t) (2 . [1 2]) (3)) (stack-core-filter-data '((0 . 3) (1 . t) (a . five) (2 . [1 2]) ("5" . bop) (3) (p . 4)) - '(1 2 3)))) + '(1 2 3)))) ;; complex (should (equal @@ -97,3 +101,16 @@ (delete-file (stack-cache-get-file-name stack-filter-cache-file)))) + +(ert-deftest question-list-display () + (cl-letf (((symbol-function 'stack-core-make-request) + (lambda (&rest _) stack-test-data-questions))) + (call-interactively 'list-questions)) + (goto-char (point-min)) + (should (looking-at " 1 0 Focus-hook: attenuate colours when losing focus [0-9]+d ago \\[frames\\] \\[hooks\\] \\[focus\\]")) + (stack-question-list-next 5) + (should (looking-at " 0 1 Babel doesn't wrap results in verbatim [0-9]+d ago \\[org-mode\\]")) + (call-interactively 'stack-question-list-display-question) + (should (equal (buffer-name) "*stack-question*")) + (stack-question-list-previous 4) + (should (looking-at " 2 1 "Making tag completion table" Freezes/Blocks -- how to disable [0-9]+d ago \\[autocomplete\\]"))) -- cgit v1.2.3 From d09556032b645d05bcb2a0164c8bb0e6f8ebf25f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 6 Nov 2014 11:40:59 +0000 Subject: Fix question list tests --- test/tests.el | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index 9bf63fd..b8001ae 100644 --- a/test/tests.el +++ b/test/tests.el @@ -107,10 +107,18 @@ (lambda (&rest _) stack-test-data-questions))) (call-interactively 'list-questions)) (goto-char (point-min)) - (should (looking-at " 1 0 Focus-hook: attenuate colours when losing focus [0-9]+d ago \\[frames\\] \\[hooks\\] \\[focus\\]")) + (should (equal (buffer-name) "*question-list*")) + (should (string-match + "^ 1 0 Focus-hook: attenuate colours when losing focus [ 0-9]+[ydhms] ago \\[frames\\] \\[hooks\\] \\[focus\\]" + (thing-at-point 'line))) (stack-question-list-next 5) - (should (looking-at " 0 1 Babel doesn't wrap results in verbatim [0-9]+d ago \\[org-mode\\]")) + (should (string-match + "^ 0 1 Babel doesn't wrap results in verbatim [ 0-9]+[ydhms] ago \\[org-mode\\]" + (thing-at-point 'line))) (call-interactively 'stack-question-list-display-question) (should (equal (buffer-name) "*stack-question*")) + (switch-to-buffer "*question-list*") (stack-question-list-previous 4) - (should (looking-at " 2 1 "Making tag completion table" Freezes/Blocks -- how to disable [0-9]+d ago \\[autocomplete\\]"))) + (should (string-match + "^ 2 1 "Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+[ydhms] ago \\[autocomplete\\]" + (thing-at-point 'line)))) -- cgit v1.2.3 From 299a0ac21a7bc65383a1cd9a000c9d4cc8750d2d Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 6 Nov 2014 13:47:01 +0000 Subject: Fix question list testing (for real). --- test/tests.el | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index b8001ae..8a9f5e1 100644 --- a/test/tests.el +++ b/test/tests.el @@ -9,7 +9,7 @@ (defvar stack-test-data-dir (expand-file-name "data-samples/" - (or load-file-name "./")) + (or (file-name-directory load-file-name) "./")) "") (defun stack-test-sample-data (method &optional directory) @@ -35,6 +35,7 @@ (require 'stack-core) (require 'stack-question) (require 'stack-question-list) +(require 'cl-lib) (ert-deftest test-basic-request () "Test basic request functionality" @@ -102,23 +103,29 @@ (stack-cache-get-file-name stack-filter-cache-file)))) +(defmacro line-should-match (regexp) + "" + `(let ((line (buffer-substring-no-properties + (line-beginning-position) + (line-end-position)))) + (message "Line here is: %S" line) + (should (string-match ,regexp line)))) + (ert-deftest question-list-display () - (cl-letf (((symbol-function 'stack-core-make-request) + (cl-letf (((symbol-function #'stack-core-make-request) (lambda (&rest _) stack-test-data-questions))) - (call-interactively 'list-questions)) - (goto-char (point-min)) - (should (equal (buffer-name) "*question-list*")) - (should (string-match - "^ 1 0 Focus-hook: attenuate colours when losing focus [ 0-9]+[ydhms] ago \\[frames\\] \\[hooks\\] \\[focus\\]" - (thing-at-point 'line))) - (stack-question-list-next 5) - (should (string-match - "^ 0 1 Babel doesn't wrap results in verbatim [ 0-9]+[ydhms] ago \\[org-mode\\]" - (thing-at-point 'line))) - (call-interactively 'stack-question-list-display-question) - (should (equal (buffer-name) "*stack-question*")) - (switch-to-buffer "*question-list*") - (stack-question-list-previous 4) - (should (string-match - "^ 2 1 "Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+[ydhms] ago \\[autocomplete\\]" - (thing-at-point 'line)))) + (list-questions nil) + (switch-to-buffer "*question-list*") + (goto-char (point-min)) + (should (equal (buffer-name) "*question-list*")) + (line-should-match + "^ 1 0 Focus-hook: attenuate colours when losing focus [ 0-9]+[ydhms] ago \\[frames\\] \\[hooks\\] \\[focus\\]") + (stack-question-list-next 5) + (line-should-match + "^ 0 1 Babel doesn't wrap results in verbatim [ 0-9]+[ydhms] ago \\[org-mode\\]") + (call-interactively 'stack-question-list-display-question) + (should (equal (buffer-name) "*stack-question*")) + (switch-to-buffer "*question-list*") + (stack-question-list-previous 4) + (line-should-match + "^ 2 1 "Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+[ydhms] ago \\[autocomplete\\]"))) -- cgit v1.2.3 From 9ba2bece6b1fcfca5c55fca431775d3e25e1ce2f Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 6 Nov 2014 13:54:26 +0000 Subject: package-initialize on tests --- test/tests.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index 8a9f5e1..c632adf 100644 --- a/test/tests.el +++ b/test/tests.el @@ -32,10 +32,14 @@ stack-test-data-sites (stack-test-sample-data "sites")) +(setq package-user-dir + (expand-file-name (format "../../.cask/%s/elpa" emacs-version) + stack-test-data-dir)) +(package-initialize) +(require 'cl-lib) (require 'stack-core) (require 'stack-question) (require 'stack-question-list) -(require 'cl-lib) (ert-deftest test-basic-request () "Test basic request functionality" -- cgit v1.2.3 From 6ff3660dedd1310709460ece74b6079f33e91c57 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 6 Nov 2014 14:40:30 +0000 Subject: Fix test regexp --- test/tests.el | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index c632adf..7f7395a 100644 --- a/test/tests.el +++ b/test/tests.el @@ -123,13 +123,13 @@ (goto-char (point-min)) (should (equal (buffer-name) "*question-list*")) (line-should-match - "^ 1 0 Focus-hook: attenuate colours when losing focus [ 0-9]+[ydhms] ago \\[frames\\] \\[hooks\\] \\[focus\\]") + "^\\s-+1\\s-+0\\s-+Focus-hook: attenuate colours when losing focus [ 0-9]+[ydhms] ago\\s-+\\[frames\\] \\[hooks\\] \\[focus\\]") (stack-question-list-next 5) (line-should-match - "^ 0 1 Babel doesn't wrap results in verbatim [ 0-9]+[ydhms] ago \\[org-mode\\]") + "^\\s-+0\\s-+1\\s-+Babel doesn't wrap results in verbatim [ 0-9]+[ydhms] ago\\s-+\\[org-mode\\]") (call-interactively 'stack-question-list-display-question) (should (equal (buffer-name) "*stack-question*")) (switch-to-buffer "*question-list*") (stack-question-list-previous 4) (line-should-match - "^ 2 1 "Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+[ydhms] ago \\[autocomplete\\]"))) + "^\\s-+2\\s-+1\\s-+"Making tag completion table" Freezes/Blocks -- how to disable [ 0-9]+[ydhms] ago\\s-+\\[autocomplete\\]"))) -- cgit v1.2.3 From d3139e8e478e46c5b125eb8a9327beaacf439b50 Mon Sep 17 00:00:00 2001 From: Artur Malabarba Date: Thu, 6 Nov 2014 14:44:30 +0000 Subject: Comment out "*stack-question*" buffer test --- test/tests.el | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index 7f7395a..74ef158 100644 --- a/test/tests.el +++ b/test/tests.el @@ -127,8 +127,9 @@ (stack-question-list-next 5) (line-should-match "^\\s-+0\\s-+1\\s-+Babel doesn't wrap results in verbatim [ 0-9]+[ydhms] ago\\s-+\\[org-mode\\]") - (call-interactively 'stack-question-list-display-question) - (should (equal (buffer-name) "*stack-question*")) + ;; ;; Use this when we have a real stack-question buffer. + ;; (call-interactively 'stack-question-list-display-question) + ;; (should (equal (buffer-name) "*stack-question*")) (switch-to-buffer "*question-list*") (stack-question-list-previous 4) (line-should-match -- cgit v1.2.3