Skip to content

Commit 5d58314

Browse files
committed
Merge pull request #1306 from mdorman/cabal-direct
Fix logic for running cabal directly.
2 parents 33a147f + 41532cf commit 5d58314

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

haskell-load.el

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,12 @@ list of modules where missed IDENT was found."
227227

228228
(defun haskell-process-do-cabal (command)
229229
"Run a Cabal command."
230-
(let ((process (haskell-interactive-process)))
230+
(let ((process (ignore-errors
231+
(haskell-interactive-process))))
231232
(cond
232-
((let ((child (haskell-process-process process)))
233-
(not (equal 'run (process-status child))))
233+
((or (eq process nil)
234+
(let ((child (haskell-process-process process)))
235+
(not (equal 'run (process-status child)))))
234236
(message "Process is not running, so running directly.")
235237
(shell-command (concat "cabal " command)
236238
(get-buffer-create "*haskell-process-log*")

tests/haskell-load-tests.el

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
;;; Code:
44

5+
(require 'cl)
56
(require 'ert)
67
(require 'haskell-test-utils)
78

@@ -83,3 +84,14 @@
8384
(search-forward "import Data.String")
8485
(haskell-goto-prev-error)
8586
(should (looking-at-p "Data.Mayb"))))
87+
88+
(ert-deftest do-cabal-no-process ()
89+
"Ensure that haskell-process-do-cabal can call cabal directly.
90+
91+
Redefine `shell-command' to just capture the command it's asked
92+
to execute, and make sure it matches what we expected."
93+
(let (shell-call)
94+
(flet ((shell-command (command &optional input-buffer output-buffer)
95+
(setq shell-call command)))
96+
(haskell-process-do-cabal "help")
97+
(should (equal shell-call "cabal help")))))

0 commit comments

Comments
 (0)