diff options
Diffstat (limited to 'test')
| -rw-r--r-- | test/projectile-test.el | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/test/projectile-test.el b/test/projectile-test.el index 08c9ff6..b5b7424 100644 --- a/test/projectile-test.el +++ b/test/projectile-test.el @@ -1212,7 +1212,22 @@ Just delegates OPERATION and ARGS for all operations except for`shell-command`'. (expect (projectile-test-file-p "src/Foo.cpp") :to-equal nil) (expect (projectile--find-matching-test "src/Foo.cpp") :to-equal '("test/Foo.cpp")) (expect (projectile--find-matching-test "src/Foo.cpp") :to-equal '("test/Foo.cpp")) - (expect (projectile--find-matching-file "test/Foo.cpp") :to-equal '("src/Foo.cpp")))))) + (expect (projectile--find-matching-file "test/Foo.cpp") :to-equal '("src/Foo.cpp"))))) + + (it "defers to test-dir property when it's set to a function" + (projectile-test-with-sandbox + (projectile-test-with-files-using-custom-project + ("src/foo/Foo.cpp" + "src/bar/Foo.cpp" + "src/foo/FooTest.cpp") + (:test-dir + (lambda (file-path) + (projectile-complementary-dir file-path "src" "test")) + :test-suffix "Test") + (expect (projectile--find-matching-test + (projectile-expand-root "src/bar/Foo.cpp")) + :to-equal + (list "test/bar/FooTest.cpp")))))) (describe "projectile--related-files" (it "returns related files for the given file" @@ -1657,6 +1672,68 @@ projectile-process-current-project-buffers-current to have similar behaviour" (projectile-process-current-project-buffers-current (lambda () (push (current-buffer) list-b))) (expect list-a :to-equal list-b)))))) +(describe "projectile-find-implementation-or-test" + (it "error when test file does not exist and projectile-create-missing-test-files is nil" + (cl-letf (((symbol-function 'projectile-test-file-p) #'ignore) + ((symbol-function 'file-exists-p) #'ignore) + ((symbol-function 'projectile-expand-root) #'identity) + ((symbol-function 'projectile-find-matching-test) (lambda (file) "dir/foo")) + (projectile-create-missing-test-files nil)) + (expect (projectile-find-implementation-or-test "foo") :to-throw)))) + +(describe "projectile--test-file-from-test-dir-fn" + :var ((mock-projectile-project-types + '((foo test-dir (lambda (impl-file) "/outer/foo/test/dir")) + (bar test-dir "not a function")))) + (it "returns result of projectile--complementary-file when test-dir property is a function" + (cl-letf (((symbol-function 'projectile--complementary-file) + (lambda (impl-file dir-fn file-fn) (funcall dir-fn impl-file))) + ((symbol-function 'projectile-project-type) (lambda () 'foo)) + ((symbol-function 'projectile-project-root) (lambda () "foo")) + ((symbol-function 'file-relative-name) (lambda (f rel) f)) + (projectile-project-types mock-projectile-project-types)) + (expect (projectile--test-file-from-test-dir-fn "foo") :to-equal "/outer/foo/test/dir"))) + (it "returns file relative to project root" + (cl-letf (((symbol-function 'projectile-project-type) (lambda () 'foo)) + ((symbol-function 'projectile-project-root) (lambda () "/outer/foo")) + ((symbol-function 'projectile--complementary-file) + (lambda (impl-file dir-fn file-fn) (funcall dir-fn impl-file))) + (projectile-project-types mock-projectile-project-types)) + (expect (projectile--test-file-from-test-dir-fn "/outer/foo/bar") + :to-equal + "test/dir"))) + (it "returns nil when test-dir property is a not function" + (cl-letf (((symbol-function 'projectile-project-type) (lambda () 'bar)) + (projectile-project-types mock-projectile-project-types) + ((symbol-function 'projectile-project-root) (lambda () "foo"))) + (expect (projectile--test-file-from-test-dir-fn "bar") :to-equal nil)))) + +(describe "projectile--complementary-file" + (it "dir-fn and filename-fn applied correctly" + (cl-letf (((symbol-function 'file-exists-p) (lambda (file) t)) + ((symbol-function 'dir-fn) (lambda (dir) "foo/test/dir")) + ((symbol-function 'filename-fn) (lambda (filename) "Foo.test"))) + (expect (projectile--complementary-file + "foo/src/dir/Foo.impl" + #'dir-fn + #'filename-fn) + :to-equal "foo/test/dir/Foo.test")))) + +(describe "projectile--impl-to-test-dir" + :var ((mock-projectile-project-types + '((foo test-dir "test" src-dir "src") + (bar test-dir identity src-dir "src")))) + (it "replaces occurrences of src-dir with test-dir" + (cl-letf (((symbol-function 'projectile-project-root) (lambda () "foo")) + ((symbol-function 'projectile-project-type) (lambda () 'foo)) + (projectile-project-types mock-projectile-project-types)) + (expect (projectile--impl-to-test-dir "/foo/src/Foo") :to-equal "/foo/test/"))) + (it "error signalled when test dir property is not a string" + (cl-letf (((symbol-function 'projectile-project-root) (lambda () "bar")) + ((symbol-function 'projectile-project-type) (lambda () 'bar)) + (projectile-project-types mock-projectile-project-types)) + (expect (projectile--impl-to-test-dir "/bar/src/bar") :to-throw)))) + ;; A bunch of tests that make sure Projectile commands handle ;; gracefully the case of being run outside of a project. (assert-friendly-error-when-no-project projectile-project-info) |
