Skip to content

Commit

Permalink
Signal an error if the root directory does not exist
Browse files Browse the repository at this point in the history
* indium-workspace.el (indium-workspace-root): Signal an error is the root
  directory is invalid (non-existent or not a directory).
* test/unit/indium-workspace-test.el: Add a regression test.
  • Loading branch information
NicolasPetton committed Jul 23, 2018
1 parent 3c66236 commit ef83c51
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
13 changes: 9 additions & 4 deletions indium-workspace.el
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,15 @@ If no connection is open yet, lookup the root directory as follows:
\"root\") configuration option.
- If no \"root\" option is set, it defaults to the directory
containing the \".indium.json\" project file."
(or (indium-current-connection-project-root)
(indium-workspace--root-from-configuration)
(indium-workspace--project-directory)))
containing the \".indium.json\" project file.
If the root directory does not exist, signal an error."
(let ((root (or (indium-current-connection-project-root)
(indium-workspace--root-from-configuration)
(indium-workspace--project-directory))))
(unless (file-directory-p root)
(user-error "Project root directory does not exist"))
root))

(defun indium-workspace--root-from-configuration ()
"Return the root directory read from the project configuration.
Expand Down
18 changes: 14 additions & 4 deletions test/unit/indium-workspace-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,36 @@

(describe "Workspace root"
(it "Returns the current connection's project root when there is a connection"
(let ((indium-current-connection (make-indium-connection :project-root 'foo)))
(expect (indium-workspace-root) :to-be 'foo)))
(assess-with-filesystem indium-workspace--test-fs
(let* ((root (expand-file-name "js"))
(indium-current-connection (make-indium-connection :project-root root)))
(expect (indium-workspace-root) :to-be root))))

(it "should default to the project directory when no \"root\" is defined"
(assess-with-filesystem indium-workspace--test-fs
(expect (directory-file-name (indium-workspace-root)) :to-equal
(directory-file-name default-directory))))

(it "should take the directory set in the \"root\" option"
(assess-with-filesystem '((".indium.json" "{\"configurations\": [{\"root\": \"foo\"}]}"))
(assess-with-filesystem '((".indium.json" "{\"configurations\": [{\"root\": \"foo\"}]}")
("foo" ("index.js")))
(with-indium-workspace-configuration
(expect (directory-file-name (indium-workspace-root)) :to-equal
(directory-file-name (expand-file-name "foo" default-directory))))))

(it "webRoot should be an alias for root"
(assess-with-filesystem '((".indium.json" "{\"configurations\": [{\"webRoot\": \"foo\"}]}"))
(assess-with-filesystem '((".indium.json" "{\"configurations\": [{\"webRoot\": \"foo\"}]}")
("foo" ("index.js")))
(with-indium-workspace-configuration
(expect (directory-file-name (indium-workspace-root)) :to-equal
(directory-file-name (expand-file-name "foo" default-directory)))))))

(describe "Invalid root directory"
(it "should signal an error when the root directory does not exist"
(assess-with-filesystem '((".indium.json" "{\"configurations\": [{\"webRoot\": \"foo\"}]}"))
(with-indium-workspace-configuration
(expect (indium-workspace-root) :to-throw)))))

(describe "Choosing a configuration"
(it "should not prompt for a configuration when there is only one"
(assess-with-filesystem '((".indium.json" "{\"configurations\": [{}]}"))
Expand Down

0 comments on commit ef83c51

Please sign in to comment.