aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorEugene Tan <jmingtan@gmail.com>2018-10-24 00:54:48 +0800
committerBozhidar Batsov <bozhidar.batsov@gmail.com>2018-10-23 19:20:16 +0200
commitb91c7dfb9e47af001beaf4d1bb034dbbcd328fff (patch)
tree4592111518e3c1c1471c0a9ef2fc40b1367990c8 /test
parent90997d636c0329420bc50f43e25a5dc4d8a6ce47 (diff)
Migrate some ert tests
Diffstat (limited to 'test')
-rw-r--r--test/projectile-legacy-test.el208
-rw-r--r--test/projectile-test.el223
2 files changed, 223 insertions, 208 deletions
diff --git a/test/projectile-legacy-test.el b/test/projectile-legacy-test.el
index 635ab85..b715b93 100644
--- a/test/projectile-legacy-test.el
+++ b/test/projectile-legacy-test.el
@@ -240,214 +240,6 @@
(should (equal (projectile-tags-exclude-patterns)
"--exclude=\".git\" --exclude=\".hg\""))))
-(ert-deftest projectile-test-maybe-invalidate ()
- (noflet ((projectile-invalidate-cache (arg) t))
- (should-not (projectile-maybe-invalidate-cache nil))
- (should (projectile-maybe-invalidate-cache t))
- (noflet ((file-newer-than-file-p (a b) t))
- (should (projectile-maybe-invalidate-cache nil)))))
-
-(ert-deftest projectile-test-root-top-down ()
- (projectile-test-with-sandbox
- (projectile-test-with-files
- ("projectA/.svn/"
- "projectA/src/.svn/"
- "projectA/src/html/.svn/"
- "projectA/.git/"
- "projectA/src/html/"
- "projectA/src/framework/lib/"
- "projectA/src/framework.conf"
- "projectA/src/html/index.html")
- (should (equal (expand-file-name "projectA/src/")
- (projectile-root-top-down "projectA/src/framework/lib"
- '("framework.conf" ".git"))))
- (should (equal (expand-file-name "projectA/src/")
- (projectile-root-top-down "projectA/src/framework/lib"
- '(".git" "framework.conf"))))
- (should (equal (expand-file-name "projectA/src/html/")
- (projectile-root-top-down "projectA/src/html/"
- '(".svn")))))))
-
-(ert-deftest projectile-test-root-top-down-recurring ()
- (projectile-test-with-sandbox
- (projectile-test-with-files
- ("projectA/.svn/"
- "projectA/src/.svn/"
- "projectA/src/html/.svn/"
- "projectA/.git/"
- "projectA/src/html/"
- "projectA/src/framework/lib/"
- "projectA/src/framework/framework.conf"
- "projectA/src/html/index.html"
- ".projectile")
- (should (equal (expand-file-name "projectA/")
- (projectile-root-top-down-recurring
- "projectA/src/html/"
- '("something" ".svn" ".git"))))
- (should (equal (expand-file-name "projectA/")
- (projectile-root-top-down-recurring
- "projectA/src/html/"
- '(".git"))))
- (should-not (projectile-root-top-down-recurring
- "projectA/src/html/"
- '("elusivefile"))))))
-
-(ert-deftest projectile-test-root-bottom-up ()
- (projectile-test-with-sandbox
- (projectile-test-with-files
- ("projectA/.svn/"
- "projectA/src/.svn/"
- "projectA/src/html/.svn/"
- "projectA/.git/"
- "projectA/src/html/"
- "projectA/src/framework/lib/"
- "projectA/src/framework/framework.conf"
- "projectA/src/html/index.html"
- "projectA/.projectile")
- (should (equal (expand-file-name "projectA/")
- (projectile-root-bottom-up "projectA/src/framework/lib"
- '(".git" ".svn"))))
- (should (equal (expand-file-name "projectA/")
- (projectile-root-bottom-up "projectA/src/html"
- '(".git" ".svn"))))
- (should (equal (expand-file-name "projectA/src/html/")
- (projectile-root-bottom-up "projectA/src/html"
- '(".svn" ".git"))))
- (should (equal (expand-file-name "projectA/")
- (projectile-root-bottom-up "projectA/src/html"
- '(".projectile" "index.html")))))))
-
-(ert-deftest projectile-test-project-root ()
- (projectile-test-with-sandbox
- (projectile-test-with-files
- ("projectA/src/.svn/"
- "projectA/src/html/.svn/"
- "projectA/src/html/"
- "projectA/src/framework/lib/"
- "projectA/build/framework/lib/"
- "projectA/requirements/a/b/c/d/e/f/g/"
- "projectA/src/framework/framework.conf"
- "projectA/requirements/a/b/c/requirements.txt"
- "projectA/src/html/index.html"
- "projectA/.projectile"
- "override")
- (let ((projectile-project-root-files-bottom-up '("somefile" ".projectile"))
- (projectile-project-root-files '("otherfile" "framework.conf" "requirements.txt"))
- (projectile-project-root-files-top-down-recurring '(".svn" ".foo"))
- (projectile-project-root-files-functions '(projectile-root-bottom-up
- projectile-root-top-down
- projectile-root-top-down-recurring)))
- (projectile-test-should-root-in "projectA" "projectA/requirements/a/b/c/d/e/f/g")
- (projectile-test-should-root-in "projectA" "projectA/src/framework/lib")
- (projectile-test-should-root-in "projectA" "projectA/src/html")
-
- (setq projectile-project-root-files-functions '(projectile-root-top-down
- projectile-root-top-down-recurring
- projectile-root-bottom-up))
- (projectile-test-should-root-in "projectA/requirements/a/b/c"
- "projectA/requirements/a/b/c/d/e/f/g")
- (projectile-test-should-root-in "projectA/src/framework"
- "projectA/src/framework/lib")
- (projectile-test-should-root-in "projectA/src"
- "projectA/src/html"))
-
- (let ((projectile-project-root-files-bottom-up '("somefile" ".projectile"))
- (projectile-project-root-files '("otherfile" "noframework.conf"))
- (projectile-project-root-files-top-down-recurring '(".svn" ".foo"))
- (projectile-project-root-files-functions '(projectile-root-top-down-recurring
- projectile-root-bottom-up
- projectile-root-top-down)))
- (projectile-test-should-root-in "projectA/src" "projectA/src/framework/lib")
- (projectile-test-should-root-in "projectA/src" "projectA/src/html")
- (projectile-test-should-root-in "projectA/" "projectA/build/framework/lib"))
-
- (let ((projectile-project-root-files-bottom-up '("somefile" "override"))
- (projectile-project-root-files '("otherfile" "anotherfile"))
- (projectile-project-root-files-top-down-recurring '("someotherfile" "yetanotherfile"))
- (projectile-project-root-files-functions '(projectile-root-bottom-up
- projectile-root-top-down
- projectile-root-top-down-recurring)))
- (projectile-test-should-root-in default-directory "projectA/src/framework/lib")
- (projectile-test-should-root-in default-directory "projectA/src/html"))
-
- (let ((projectile-project-root-files-bottom-up '("somecoolfile"))
- (projectile-project-root-files nil)
- (projectile-project-root-files-top-down-recurring '(".svn"))
- (projectile-project-root-files-functions '(projectile-root-bottom-up
- projectile-root-top-down
- projectile-root-top-down-recurring)))
- (projectile-test-should-root-in "projectA/src/" "projectA/src/")
- (projectile-test-should-root-in "projectA/src/" "projectA/src/html")))))
-
-(ert-deftest projectile-test-file-exists-cache-disabled ()
- (projectile-test-with-sandbox
- (projectile-test-with-files
- ("project/dirA/dirB/"
- "project/fileA")
- (let ((projectile-file-exists-local-cache-expire nil)
- (projectile-file-exists-remote-cache-expire nil))
- (should (projectile-file-exists-p "project/fileA"))
- (should (projectile-file-exists-p "project/dirA/dirB"))
- (should-not (projectile-file-exists-p "project/dirA/fileB"))
- (with-temp-file "project/dirA/fileB")
- (should(projectile-file-exists-p "project/dirA/fileB"))
- (should-not (projectile-file-exists-p "project/nofile"))
- (delete-file "project/fileA")
- (should-not (projectile-file-exists-p "project/fileA"))))))
-
-(ert-deftest projectile-test-file-exists-cache ()
- (projectile-test-with-sandbox
- (projectile-test-with-files
- ("dirA/dirB/"
- "fileA")
- (let* ((initial-time (current-time))
- (projectile-file-exists-local-cache-expire 100)
- (projectile-file-exists-remote-cache-expire nil))
-
- (noflet ((run-with-timer (&rest args) 'nooptimer))
- (noflet ((current-time () initial-time))
- (should (projectile-file-exists-p "fileA"))
- (should (projectile-file-exists-p "dirA/dirB"))
- (should-not (projectile-file-exists-p "dirA/fileB"))
- (with-temp-file "dirA/fileB")
- (should-not (projectile-file-exists-p "dirA/fileB"))
- (delete-file "fileA")
- (should (projectile-file-exists-p "fileA"))
- (should (equal projectile-file-exists-cache-timer 'nooptimer))
- (projectile-file-exists-cache-cleanup)
- (should (equal projectile-file-exists-cache-timer 'nooptimer)))
-
- (noflet ((current-time () (time-add initial-time (seconds-to-time 50))))
- (projectile-file-exists-cache-cleanup)
- (should (projectile-file-exists-p "fileA"))
- (should-not (projectile-file-exists-p "dirA/fileB"))
- (should-not (projectile-file-exists-p "fileC"))
- (with-temp-file "fileC")
- (should (projectile-file-exists-p "fileA"))
- (projectile-file-exists-cache-cleanup)
- (should (equal projectile-file-exists-cache-timer 'nooptimer)))
-
- (noflet ((current-time () (time-add initial-time (seconds-to-time 120))))
- (projectile-file-exists-cache-cleanup)
- (should (projectile-file-exists-p "dirA/fileB"))
- (should-not (projectile-file-exists-p "fileA"))
- (should-not (projectile-file-exists-p "fileC"))
- (should (equal projectile-file-exists-cache-timer 'nooptimer))
- (projectile-file-exists-cache-cleanup)
- (should (equal projectile-file-exists-cache-timer 'nooptimer)))
-
- (noflet ((current-time () (time-add initial-time (seconds-to-time 220))))
- (projectile-file-exists-cache-cleanup)
- (should (projectile-file-exists-p "fileC"))
- (should (equal projectile-file-exists-cache-timer 'nooptimer))
- (projectile-file-exists-cache-cleanup)
- (should (equal projectile-file-exists-cache-timer 'nooptimer)))
-
- (noflet ((current-time () (time-add initial-time (seconds-to-time 1000))))
- (should (equal projectile-file-exists-cache-timer 'nooptimer))
- (projectile-file-exists-cache-cleanup)
- (should-not projectile-file-exists-cache-timer)))))))
-
(defun projectile-test-tmp-file-path ()
"Return a filename suitable to save data to in the
test temp directory"
diff --git a/test/projectile-test.el b/test/projectile-test.el
index 4050894..701674a 100644
--- a/test/projectile-test.el
+++ b/test/projectile-test.el
@@ -100,6 +100,229 @@ test temp directory"
(it "caches the project type"
(expect (gethash (projectile-project-root) projectile-project-type-cache) :to-equal 'emacs-cask)))
+(describe "projectile-maybe-invalidate-cache"
+ (it "should not invalidate cache if dirconfig is older than cache"
+ (spy-on 'projectile-invalidate-cache :and-return-value t)
+ (expect (projectile-maybe-invalidate-cache nil) :not :to-be-truthy))
+ (it "should invalidate cache if force is t"
+ (spy-on 'projectile-invalidate-cache :and-return-value t)
+ (expect (projectile-maybe-invalidate-cache t) :to-be-truthy))
+ (it "should invalidate cache if dirconfig is newer than cache"
+ (spy-on 'projectile-invalidate-cache :and-return-value t)
+ (spy-on 'file-newer-than-file-p :and-return-value t)
+ (expect (projectile-maybe-invalidate-cache nil) :to-be-truthy)))
+
+(describe "projectile-root-top-down"
+ (it "identifies the root directory of a project by top-down search"
+ (projectile-test-with-sandbox
+ (projectile-test-with-files
+ ("projectA/.svn/"
+ "projectA/src/.svn/"
+ "projectA/src/html/.svn/"
+ "projectA/.git/"
+ "projectA/src/html/"
+ "projectA/src/framework/lib/"
+ "projectA/src/framework.conf"
+ "projectA/src/html/index.html")
+ (expect (projectile-root-top-down "projectA/src/framework/lib" '("framework.conf" ".git"))
+ :to-equal
+ (expand-file-name "projectA/src/"))
+ (expect (projectile-root-top-down "projectA/src/framework/lib" '(".git" "framework.conf"))
+ :to-equal
+ (expand-file-name "projectA/src/"))
+ (expect (projectile-root-top-down "projectA/src/html/" '(".svn"))
+ :to-equal
+ (expand-file-name "projectA/src/html/"))))))
+
+(describe "projectile-root-top-down-recurring"
+ (it "identifies the root directory of a project by recurring top-down search"
+ (projectile-test-with-sandbox
+ (projectile-test-with-files
+ ("projectA/.svn/"
+ "projectA/src/.svn/"
+ "projectA/src/html/.svn/"
+ "projectA/.git/"
+ "projectA/src/html/"
+ "projectA/src/framework/lib/"
+ "projectA/src/framework/framework.conf"
+ "projectA/src/html/index.html"
+ ".projectile")
+ (expect (projectile-root-top-down-recurring "projectA/src/html/" '("something" ".svn" ".git"))
+ :to-equal
+ (expand-file-name "projectA/"))
+ (expect (projectile-root-top-down-recurring "projectA/src/html/" '(".git"))
+ :to-equal
+ (expand-file-name "projectA/"))
+ (expect (projectile-root-top-down-recurring "projectA/src/html/" '("elusivefile"))
+ :not :to-be-truthy)))))
+
+(describe "projectile-root-bottom-up"
+ (it "identifies the root directory of a project by bottom-up search"
+ (projectile-test-with-sandbox
+ (projectile-test-with-files
+ ("projectA/.svn/"
+ "projectA/src/.svn/"
+ "projectA/src/html/.svn/"
+ "projectA/.git/"
+ "projectA/src/html/"
+ "projectA/src/framework/lib/"
+ "projectA/src/framework/framework.conf"
+ "projectA/src/html/index.html"
+ "projectA/.projectile")
+ (expect (projectile-root-bottom-up "projectA/src/framework/lib" '(".git" ".svn"))
+ :to-equal
+ (expand-file-name "projectA/"))
+ (expect (projectile-root-bottom-up "projectA/src/html" '(".git" ".svn"))
+ :to-equal
+ (expand-file-name "projectA/"))
+ (expect (projectile-root-bottom-up "projectA/src/html" '(".svn" ".git"))
+ :to-equal
+ (expand-file-name "projectA/src/html/"))
+ (expect (projectile-root-bottom-up "projectA/src/html" '(".projectile" "index.html"))
+ :to-equal
+ (expand-file-name "projectA/"))))))
+
+(describe "projectile-project-root"
+ (defun projectile-test-should-root-in (root directory)
+ (let ((projectile-project-root-cache (make-hash-table :test 'equal)))
+ (expect (let ((default-directory
+ (expand-file-name
+ (file-name-as-directory directory))))
+ (file-truename (projectile-project-root)))
+ :to-equal
+ (file-truename (file-name-as-directory root)))))
+
+ (it "returns the root directory of a project"
+ (projectile-test-with-sandbox
+ (projectile-test-with-files
+ ("projectA/src/.svn/"
+ "projectA/src/html/.svn/"
+ "projectA/src/html/"
+ "projectA/src/framework/lib/"
+ "projectA/build/framework/lib/"
+ "projectA/requirements/a/b/c/d/e/f/g/"
+ "projectA/src/framework/framework.conf"
+ "projectA/requirements/a/b/c/requirements.txt"
+ "projectA/src/html/index.html"
+ "projectA/.projectile"
+ "override")
+ (let ((projectile-project-root-files-bottom-up '("somefile" ".projectile"))
+ (projectile-project-root-files '("otherfile" "framework.conf" "requirements.txt"))
+ (projectile-project-root-files-top-down-recurring '(".svn" ".foo"))
+ (projectile-project-root-files-functions '(projectile-root-bottom-up
+ projectile-root-top-down
+ projectile-root-top-down-recurring)))
+ (projectile-test-should-root-in "projectA" "projectA/requirements/a/b/c/d/e/f/g")
+ (projectile-test-should-root-in "projectA" "projectA/src/framework/lib")
+ (projectile-test-should-root-in "projectA" "projectA/src/html")
+
+ (setq projectile-project-root-files-functions '(projectile-root-top-down
+ projectile-root-top-down-recurring
+ projectile-root-bottom-up))
+ (projectile-test-should-root-in "projectA/requirements/a/b/c"
+ "projectA/requirements/a/b/c/d/e/f/g")
+ (projectile-test-should-root-in "projectA/src/framework"
+ "projectA/src/framework/lib")
+ (projectile-test-should-root-in "projectA/src"
+ "projectA/src/html"))
+
+ (let ((projectile-project-root-files-bottom-up '("somefile" ".projectile"))
+ (projectile-project-root-files '("otherfile" "noframework.conf"))
+ (projectile-project-root-files-top-down-recurring '(".svn" ".foo"))
+ (projectile-project-root-files-functions '(projectile-root-top-down-recurring
+ projectile-root-bottom-up
+ projectile-root-top-down)))
+ (projectile-test-should-root-in "projectA/src" "projectA/src/framework/lib")
+ (projectile-test-should-root-in "projectA/src" "projectA/src/html")
+ (projectile-test-should-root-in "projectA/" "projectA/build/framework/lib"))
+
+ (let ((projectile-project-root-files-bottom-up '("somefile" "override"))
+ (projectile-project-root-files '("otherfile" "anotherfile"))
+ (projectile-project-root-files-top-down-recurring '("someotherfile" "yetanotherfile"))
+ (projectile-project-root-files-functions '(projectile-root-bottom-up
+ projectile-root-top-down
+ projectile-root-top-down-recurring)))
+ (projectile-test-should-root-in default-directory "projectA/src/framework/lib")
+ (projectile-test-should-root-in default-directory "projectA/src/html"))
+
+ (let ((projectile-project-root-files-bottom-up '("somecoolfile"))
+ (projectile-project-root-files nil)
+ (projectile-project-root-files-top-down-recurring '(".svn"))
+ (projectile-project-root-files-functions '(projectile-root-bottom-up
+ projectile-root-top-down
+ projectile-root-top-down-recurring)))
+ (projectile-test-should-root-in "projectA/src/" "projectA/src/")
+ (projectile-test-should-root-in "projectA/src/" "projectA/src/html"))))))
+
+(describe "projectile-file-exists-p"
+ (it "returns t if file exists"
+ (projectile-test-with-sandbox
+ (projectile-test-with-files
+ ("project/dirA/dirB/"
+ "project/fileA")
+ (let ((projectile-file-exists-local-cache-expire nil)
+ (projectile-file-exists-remote-cache-expire nil))
+ (expect (projectile-file-exists-p "project/fileA") :to-be-truthy)
+ (expect (projectile-file-exists-p "project/dirA/dirB") :to-be-truthy)
+ (expect (projectile-file-exists-p "project/dirA/fileB") :not :to-be-truthy)
+ (with-temp-file "project/dirA/fileB")
+ (expect (projectile-file-exists-p "project/dirA/fileB") :to-be-truthy)
+ (expect (projectile-file-exists-p "project/nofile") :not :to-be-truthy)
+ (delete-file "project/fileA")
+ (expect (projectile-file-exists-p "project/fileA") :not :to-be-truthy)))))
+ (it "caches the results"
+ (projectile-test-with-sandbox
+ (projectile-test-with-files
+ ("dirA/dirB/"
+ "fileA")
+ (let ((initial-time (current-time))
+ (projectile-file-exists-local-cache-expire 100)
+ (projectile-file-exists-remote-cache-expire nil))
+
+ (spy-on 'run-with-timer :and-return-value 'nooptimer)
+ (spy-on 'current-time :and-return-value initial-time)
+ (expect (projectile-file-exists-p "fileA") :to-be-truthy)
+ (expect (projectile-file-exists-p "dirA/dirB") :to-be-truthy)
+ (expect (projectile-file-exists-p "dirA/fileB") :not :to-be-truthy)
+ (with-temp-file "dirA/fileB")
+ (expect (projectile-file-exists-p "dirA/fileB") :not :to-be-truthy)
+ (delete-file "fileA")
+ (expect (projectile-file-exists-p "fileA") :to-be-truthy)
+ (expect projectile-file-exists-cache-timer :to-equal 'nooptimer)
+ (projectile-file-exists-cache-cleanup)
+ (expect projectile-file-exists-cache-timer :to-equal 'nooptimer)
+
+ (spy-on 'current-time :and-return-value (time-add initial-time (seconds-to-time 50)))
+ (projectile-file-exists-cache-cleanup)
+ (expect (projectile-file-exists-p "fileA") :to-be-truthy)
+ (expect (projectile-file-exists-p "dirA/fileB") :not :to-be-truthy)
+ (expect (projectile-file-exists-p "fileC") :not :to-be-truthy)
+ (with-temp-file "fileC")
+ (expect (projectile-file-exists-p "fileA") :to-be-truthy)
+ (projectile-file-exists-cache-cleanup)
+ (expect projectile-file-exists-cache-timer :to-equal 'nooptimer)
+
+ (spy-on 'current-time :and-return-value (time-add initial-time (seconds-to-time 120)))
+ (projectile-file-exists-cache-cleanup)
+ (expect (projectile-file-exists-p "dirA/fileB") :to-be-truthy)
+ (expect (projectile-file-exists-p "fileA") :not :to-be-truthy)
+ (expect (projectile-file-exists-p "fileC") :not :to-be-truthy)
+ (expect projectile-file-exists-cache-timer :to-equal 'nooptimer)
+ (projectile-file-exists-cache-cleanup)
+ (expect projectile-file-exists-cache-timer :to-equal 'nooptimer)
+
+ (spy-on 'current-time :and-return-value (time-add initial-time (seconds-to-time 220)))
+ (projectile-file-exists-cache-cleanup)
+ (expect (projectile-file-exists-p "fileC") :to-be-truthy)
+ (expect projectile-file-exists-cache-timer :to-equal 'nooptimer)
+ (projectile-file-exists-cache-cleanup)
+ (expect projectile-file-exists-cache-timer :to-equal 'nooptimer)
+
+ (spy-on 'current-time :and-return-value (time-add initial-time (seconds-to-time 1000)))
+ (expect projectile-file-exists-cache-timer :to-equal 'nooptimer)
+ (projectile-file-exists-cache-cleanup)
+ (expect projectile-file-exists-cache-timer :not :to-be-truthy))))))
+
(describe "projectile-project-root"
(it "caches the current file"
(projectile-test-with-sandbox