diff --git a/haskell-load.el b/haskell-load.el index 3dd70c506..8bdfb0687 100644 --- a/haskell-load.el +++ b/haskell-load.el @@ -227,10 +227,12 @@ list of modules where missed IDENT was found." (defun haskell-process-do-cabal (command) "Run a Cabal command." - (let ((process (haskell-interactive-process))) + (let ((process (ignore-errors + (haskell-interactive-process)))) (cond - ((let ((child (haskell-process-process process))) - (not (equal 'run (process-status child)))) + ((or (eq process nil) + (let ((child (haskell-process-process process))) + (not (equal 'run (process-status child))))) (message "Process is not running, so running directly.") (shell-command (concat "cabal " command) (get-buffer-create "*haskell-process-log*") diff --git a/tests/haskell-load-tests.el b/tests/haskell-load-tests.el index 227f2e180..7331ecd58 100644 --- a/tests/haskell-load-tests.el +++ b/tests/haskell-load-tests.el @@ -2,6 +2,7 @@ ;;; Code: +(require 'cl) (require 'ert) (require 'haskell-test-utils) @@ -83,3 +84,14 @@ (search-forward "import Data.String") (haskell-goto-prev-error) (should (looking-at-p "Data.Mayb")))) + +(ert-deftest do-cabal-no-process () + "Ensure that haskell-process-do-cabal can call cabal directly. + +Redefine `shell-command' to just capture the command it's asked +to execute, and make sure it matches what we expected." + (let (shell-call) + (flet ((shell-command (command &optional input-buffer output-buffer) + (setq shell-call command))) + (haskell-process-do-cabal "help") + (should (equal shell-call "cabal help")))))