1;;; alchemist-project-tests.el --- 2 3;; Copyright © 2014-2015 Samuel Tonini 4;; 5;; Author: Samuel Tonini <tonini.samuel@gmail.com> 6 7;; This file is not part of GNU Emacs. 8 9;; This program is free software: you can redistribute it and/or modify 10;; it under the terms of the GNU General Public License as published by 11;; the Free Software Foundation, either version 3 of the License, or 12;; (at your option) any later version. 13 14;; This program is distributed in the hope that it will be useful, 15;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17;; GNU General Public License for more details. 18 19;; You should have received a copy of the GNU General Public License 20;; along with this program. If not, see <http://www.gnu.org/licenses/>. 21 22;;; Commentary: 23 24;;; Code: 25 26(require 'test-helper) 27 28(ert-deftest test-project-root/no-argument () 29 "Should use `default-directory' when no argument." 30 (setq alchemist-project-root-path-cache nil) 31 (with-sandbox 32 (f-touch "mix.exs") 33 (f-mkdir "path" "to" "lib") 34 (should (equal (alchemist-project-root) alchemist-sandbox-path)))) 35 36(ert-deftest test-project-root/except-files-exists () 37 "Should use `default-directory' when no argument." 38 (setq alchemist-project-root-path-cache nil) 39 (with-sandbox 40 (f-touch "mix.exs") 41 (f-touch ".hex") 42 (f-mkdir "path" "to" "lib") 43 (should-not (alchemist-project-root)))) 44 45(ert-deftest test-project-root/directory-as-argument () 46 "Should find root directory when directory as argument." 47 (setq alchemist-project-root-path-cache nil) 48 (with-sandbox 49 (f-touch "mix.exs") 50 (f-mkdir "path" "to" "lib") 51 (should (equal (alchemist-project-root "path/to/lib") alchemist-sandbox-path)))) 52 53(ert-deftest test-project-root/no-project-root () 54 "Should return nil when no root." 55 (setq alchemist-project-root-path-cache nil) 56 (with-sandbox 57 (f-mkdir "path" "to" "lib") 58 (should (equal (alchemist-project-root "path/to/lib") nil)))) 59 60(ert-deftest test-project-name/no-project-root () 61 "Should return an empty string" 62 (setq alchemist-project-root-path-cache nil) 63 (with-sandbox 64 (should (equal (alchemist-project-name) "")))) 65 66(ert-deftest test-project-name/project-exists () 67 (setq alchemist-project-root-path-cache nil) 68 "Should return name of the project" 69 (with-sandbox 70 (f-touch "mix.exs") 71 (should (equal (alchemist-project-name) "sandbox")))) 72 73(ert-deftest alchemist-project/file-under-test () 74 (with-sandbox 75 (f-touch "mix.exs") 76 (f-mkdir "lib" "path" "to") 77 (f-mkdir "web" "controllers") 78 (f-mkdir "test" "controllers") 79 (f-mkdir "test" "path" "to") 80 (f-touch "lib/path/to/file.ex") 81 (f-touch "test/path/to/file_test.exs") 82 (f-touch "web/controllers/my_controller.ex") 83 (f-touch "test/controllers/my_controller_test.exs") 84 (should (equal (file-name-nondirectory 85 (alchemist-project-file-under-test "test/path/to/file_test.exs" "lib")) 86 "file.ex")) 87 (should (equal (file-name-nondirectory 88 (alchemist-project-file-under-test "test/controllers/my_controller_test.exs" "web")) 89 "my_controller.ex")))) 90 91(ert-deftest alchemsit-project/switch-from-test-to-file-under-test-1 () 92 (with-sandbox 93 (f-touch "mix.exs") 94 (f-mkdir "lib" "path" "to") 95 (f-mkdir "test" "path" "to") 96 (f-touch "lib/path/to/file.ex") 97 (f-touch "test/path/to/file_test.exs") 98 (find-file "test/path/to/file_test.exs") 99 (alchemist-project-toggle-file-and-tests) 100 (should (equal (file-name-nondirectory (buffer-file-name)) 101 "file.ex")))) 102 103(ert-deftest alchemsit-project/switch-from-test-to-file-under-test-2 () 104 (with-sandbox 105 (f-touch "mix.exs") 106 (f-mkdir "web" "controllers") 107 (f-mkdir "test" "controllers") 108 (f-touch "web/controllers/my_controller.ex") 109 (f-touch "test/controllers/my_controller_test.exs") 110 (find-file "test/controllers/my_controller_test.exs") 111 (alchemist-project-toggle-file-and-tests) 112 (should (equal (file-name-nondirectory (buffer-file-name)) 113 "my_controller.ex")))) 114 115(ert-deftest alchemist-project/switch-from-file-under-test-to-test-file-1 () 116 (with-sandbox 117 (f-touch "mix.exs") 118 (f-mkdir "lib" "path" "to") 119 (f-mkdir "test" "path" "to") 120 (f-touch "lib/path/to/other_file.ex") 121 (f-touch "test/path/to/other_file_test.exs") 122 (find-file "lib/path/to/other_file.ex") 123 (alchemist-project-toggle-file-and-tests) 124 (should (equal (file-name-nondirectory (buffer-file-name)) 125 "other_file_test.exs")))) 126 127(ert-deftest alchemist-project/switch-from-file-under-test-to-test-file-2 () 128 (with-sandbox 129 (f-touch "mix.exs") 130 (f-mkdir "web" "views") 131 (f-mkdir "test" "views") 132 (f-touch "web/views/my_view.ex") 133 (f-touch "test/views/my_view_test.exs") 134 (find-file "web/views/my_view.ex") 135 (alchemist-project-toggle-file-and-tests) 136 (should (equal (file-name-nondirectory (buffer-file-name)) 137 "my_view_test.exs")))) 138 139(ert-deftest alchemist-project/inside-elixir-codebase () 140 (setq alchemist-goto-elixir-source-dir alchemist-sandbox-path) 141 (with-sandbox 142 (should (alchemist-project-elixir-p)) 143 (should (equal (alchemist-project-elixir-root) alchemist-sandbox-path)))) 144 145(ert-deftest alchemist-project/not-inside-elixir-codebase () 146 (setq alchemist-goto-elixir-source-dir nil) 147 (with-sandbox 148 (should-not (alchemist-project-elixir-p)) 149 (should (equal nil (alchemist-project-elixir-root))))) 150 151(provide 'alchemist-project-tests) 152