From 7d461a7d4f62d357a224741b9e808f1abada8d15 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 2 Nov 2014 11:52:08 -0500 Subject: Introduce persistent storage for filters --- test/tests.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index 44b0de0..fa60364 100644 --- a/test/tests.el +++ b/test/tests.el @@ -75,3 +75,22 @@ ((should-not-go)) ((1 . alpha) (2 . beta))] '(1 2 3))))) + +(ert-deftest test-filters () + ;; Ensure the file is empty + (ignore-errors + (delete-file + (stack-cache-get-file-name + stack-filter-cache-file))) + + (should-error (stack-filter-store "names must be symbols" + "this is a filter")) + ;; basic use + (should (equal '((test . "filter")) + (stack-filter-store 'test "filter"))) + ;; aggregation + (should (equal '((test2 . "filter2") (test . "filter")) + (stack-filter-store 'test2 "filter2"))) + ;; mutation + (should (equal '((test2 . "filter2") (test . "filter-test")) + (stack-filter-store 'test "filter-test")))) -- cgit v1.2.3 From 39a78ea40772a30678dcd947fc4b8735d356edfb Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 2 Nov 2014 12:02:46 -0500 Subject: Fix test cases re file persistence Every time the test was getting run, it would create the file, but not delete it. This meant that tests were not idempotent and artifacts from previous tests were persisting into the next ones. Use `make-temp-file' to let-bind `stack-filter-cache-file' to a temporary file. It is guaranteed to be empty when the tests begin. --- test/tests.el | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index fa60364..9c9438d 100644 --- a/test/tests.el +++ b/test/tests.el @@ -77,20 +77,19 @@ '(1 2 3))))) (ert-deftest test-filters () - ;; Ensure the file is empty - (ignore-errors + (let ((stack-filter-cache-file (make-temp-file "stack-test-"))) + (should-error (stack-filter-store "names must be symbols" + "this is a filter")) + ;; basic use + (should (equal '((test . "filter")) + (stack-filter-store 'test "filter"))) + ;; aggregation + (should (equal '((test2 . "filter2") (test . "filter")) + (stack-filter-store 'test2 "filter2"))) + ;; mutation + (should (equal '((test2 . "filter2") (test . "filter-test")) + (stack-filter-store 'test "filter-test"))) + ;; clean up (note: the file should exist) (delete-file (stack-cache-get-file-name - stack-filter-cache-file))) - - (should-error (stack-filter-store "names must be symbols" - "this is a filter")) - ;; basic use - (should (equal '((test . "filter")) - (stack-filter-store 'test "filter"))) - ;; aggregation - (should (equal '((test2 . "filter2") (test . "filter")) - (stack-filter-store 'test2 "filter2"))) - ;; mutation - (should (equal '((test2 . "filter2") (test . "filter-test")) - (stack-filter-store 'test "filter-test")))) + stack-filter-cache-file)))) -- cgit v1.2.3 From 13e7d2b851da90435bc33137925144074a28eb4c Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 2 Nov 2014 12:06:17 -0500 Subject: Consolidate testing variables and print requests --- test/tests.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index 9c9438d..f19d506 100644 --- a/test/tests.el +++ b/test/tests.el @@ -22,8 +22,10 @@ ;;; Tests -(setq stack-core-remaining-api-requests-message-threshold 50000) -(setq debug-on-error t) +(setq + stack-core-remaining-api-requests-message-threshold 50000 + debug-on-error t + stack-core-silent-requests nil) (require 'stack-core) (require 'stack-question) -- cgit v1.2.3 From 800b3af0e5a4cbfb385b2f8d925f5884bc71baad Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 2 Nov 2014 13:02:14 -0500 Subject: Let-bind user-emacs-directory to cwd Useful for testing locally, since now you can simply blow away the `.stackmode' directory instead of searching for it in `.emacs.d'. At any rate, it keeps everything in the project tidy. --- .gitignore | 2 ++ test/tests.el | 17 +++++++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/.gitignore b/.gitignore index 663dcbb..2585bf5 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ *.elc /.cask/ .dir-locals.el +/.stackmode/ +/url/ diff --git a/test/tests.el b/test/tests.el index f19d506..bd0cb67 100644 --- a/test/tests.el +++ b/test/tests.el @@ -5,6 +5,8 @@ (if (string-prefix-p "stack-" (symbol-name symbol)) (unintern symbol))))) +;;; Tests + (defun stack-test-sample-data (method &optional directory) (with-current-buffer (find-file-noselect @@ -15,17 +17,16 @@ "'no-value" (buffer-string)))))) -(setq stack-test-data-questions - (stack-test-sample-data "questions") - stack-test-data-sites - (stack-test-sample-data "sites")) - -;;; Tests - (setq stack-core-remaining-api-requests-message-threshold 50000 debug-on-error t - stack-core-silent-requests nil) + stack-core-silent-requests nil + user-emacs-directory "." + + stack-test-data-questions + (stack-test-sample-data "questions") + stack-test-data-sites + (stack-test-sample-data "sites")) (require 'stack-core) (require 'stack-question) -- cgit v1.2.3 From 73a1b008211cc2ca548c30ff99b2950c99e53325 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 2 Nov 2014 13:04:54 -0500 Subject: Let-bind stack-cache-directory instead There are several variables and functions that depend on it; simply binding the filter-cache file isn't enough. --- test/tests.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index bd0cb67..9e1cff1 100644 --- a/test/tests.el +++ b/test/tests.el @@ -80,7 +80,7 @@ '(1 2 3))))) (ert-deftest test-filters () - (let ((stack-filter-cache-file (make-temp-file "stack-test-"))) + (let ((stack-cache-directory (make-temp-file "stack-test" t))) (should-error (stack-filter-store "names must be symbols" "this is a filter")) ;; basic use -- cgit v1.2.3 From 7a58be5e2a0aeae2e170cc576befbb3a2e34878e Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sun, 2 Nov 2014 13:23:28 -0500 Subject: Fix get-sample-data and avoid `find-file-noselect' --- test/tests.el | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/tests.el b/test/tests.el index 9e1cff1..e097244 100644 --- a/test/tests.el +++ b/test/tests.el @@ -8,14 +8,13 @@ ;;; Tests (defun stack-test-sample-data (method &optional directory) - (with-current-buffer - (find-file-noselect - (concat "data-samples/" - (when directory (concat directory "/")) - method ".el")) - (eval (read (if (string-equal "" (buffer-string)) - "'no-value" - (buffer-string)))))) + (let ((file (concat "data-samples/" + (when directory (concat directory "/")) + method ".el"))) + (when (file-exists-p file) + (with-temp-buffer + (insert-file-contents file) + (read (buffer-string)))))) (setq stack-core-remaining-api-requests-message-threshold 50000 -- cgit v1.2.3