|
| 1 | +;;; haskell-process-tests.el |
| 2 | + |
| 3 | +;;; Code: |
| 4 | + |
| 5 | +(require 'ert) |
| 6 | +(require 'haskell-process) |
| 7 | + |
| 8 | +(eval-when-compile (require 'cl)) ;; for tests with mock to pass... |
| 9 | +(require 'el-mock) |
| 10 | + |
| 11 | +(ert-deftest haskell-process-wrapper-command-function-identity () |
| 12 | + "No wrapper, return directly the command." |
| 13 | + (should (equal '("ghci") |
| 14 | + (progn |
| 15 | + (custom-set-variables '(haskell-process-wrapper-function #'identity)) |
| 16 | + (apply haskell-process-wrapper-function (list '("ghci"))))))) |
| 17 | + |
| 18 | +(ert-deftest haskell-process-wrapper-function-non-identity () |
| 19 | + "Wrapper as a string, return the wrapping command as a string." |
| 20 | + (should (equal '("nix-shell" "default.nix" "--command" "cabal\\ run") |
| 21 | + (progn |
| 22 | + (custom-set-variables '(haskell-process-wrapper-function (lambda (argv) |
| 23 | + (append '("nix-shell" "default.nix" "--command") |
| 24 | + (list (shell-quote-argument argv)))))) |
| 25 | + (apply haskell-process-wrapper-function (list "cabal run")))))) |
| 26 | + |
| 27 | +(ert-deftest test-haskell-process--compute-process-log-and-command-ghci () |
| 28 | + (should (equal '("Starting inferior GHCi process ghci ..." "dumses1" nil "ghci" "-ferror-spans") |
| 29 | + (let ((haskell-process-path-ghci "ghci") |
| 30 | + (haskell-process-args-ghci '("-ferror-spans"))) |
| 31 | + (custom-set-variables '(haskell-process-wrapper-function #'identity)) |
| 32 | + (mocklet (((haskell-session-name "dummy-session") => "dumses1")) |
| 33 | + (haskell-process-compute-process-log-and-command "dummy-session" 'ghci)))))) |
| 34 | + |
| 35 | +(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-ghci () |
| 36 | + (should (equal '("Starting inferior GHCi process ghci ..." "dumses1" nil "nix-shell" "default.nix" "--command" "ghci\\ -ferror-spans") |
| 37 | + (let ((haskell-process-path-ghci "ghci") |
| 38 | + (haskell-process-args-ghci '("-ferror-spans"))) |
| 39 | + (custom-set-variables '(haskell-process-wrapper-function |
| 40 | + (lambda (argv) (append (list "nix-shell" "default.nix" "--command" ) |
| 41 | + (list (shell-quote-argument (mapconcat 'identity argv " "))))))) |
| 42 | + (mocklet (((haskell-session-name "dummy-session") => "dumses1")) |
| 43 | + (haskell-process-compute-process-log-and-command "dummy-session" 'ghci)))))) |
| 44 | + |
| 45 | +(ert-deftest test-haskell-process--compute-process-log-and-command-cabal-repl () |
| 46 | + (should (equal '("Starting inferior `cabal repl' process using cabal ..." "dumses2" nil "cabal" "repl" "--ghc-option=-ferror-spans" "dumdum-session") |
| 47 | + (let ((haskell-process-path-cabal "cabal") |
| 48 | + (haskell-process-args-cabal-repl '("--ghc-option=-ferror-spans"))) |
| 49 | + (custom-set-variables '(haskell-process-wrapper-function #'identity)) |
| 50 | + (mocklet (((haskell-session-name "dummy-session2") => "dumses2") |
| 51 | + ((haskell-session-target "dummy-session2") => "dumdum-session")) |
| 52 | + (haskell-process-compute-process-log-and-command "dummy-session2" 'cabal-repl)))))) |
| 53 | + |
| 54 | +(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-repl () |
| 55 | + (should (equal '("Starting inferior `cabal repl' process using cabal ..." "dumses2" nil "nix-shell" "default.nix" "--command" "cabal\\ repl\\ --ghc-option\\=-ferror-spans" "dumdum-session") |
| 56 | + (let ((haskell-process-path-cabal "cabal") |
| 57 | + (haskell-process-args-cabal-repl '("--ghc-option=-ferror-spans"))) |
| 58 | + (custom-set-variables '(haskell-process-wrapper-function |
| 59 | + (lambda (argv) (append (list "nix-shell" "default.nix" "--command" ) |
| 60 | + (list (shell-quote-argument (mapconcat 'identity argv " "))))))) |
| 61 | + (mocklet (((haskell-session-name "dummy-session2") => "dumses2") |
| 62 | + ((haskell-session-target "dummy-session2") => "dumdum-session")) |
| 63 | + (haskell-process-compute-process-log-and-command "dummy-session2" 'cabal-repl)))))) |
| 64 | + |
| 65 | +(ert-deftest test-haskell-process--compute-process-log-and-command-cabal-ghci () |
| 66 | + (should (equal '("Starting inferior cabal-ghci process using cabal-ghci ..." "dumses3" nil "cabal-ghci") |
| 67 | + (let ((haskell-process-path-ghci "ghci")) |
| 68 | + (custom-set-variables '(haskell-process-wrapper-function #'identity)) |
| 69 | + (mocklet (((haskell-session-name "dummy-session3") => "dumses3")) |
| 70 | + (haskell-process-compute-process-log-and-command "dummy-session3" 'cabal-ghci)))))) |
| 71 | + |
| 72 | +(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-ghci () |
| 73 | + (should (equal '("Starting inferior cabal-ghci process using cabal-ghci ..." "dumses3" nil "nix-shell" "default.nix" "--command" "cabal-ghci") |
| 74 | + (let ((haskell-process-path-ghci "ghci")) |
| 75 | + (custom-set-variables '(haskell-process-wrapper-function |
| 76 | + (lambda (argv) (append (list "nix-shell" "default.nix" "--command" ) |
| 77 | + (list (shell-quote-argument (mapconcat 'identity argv " "))))))) |
| 78 | + (mocklet (((haskell-session-name "dummy-session3") => "dumses3")) |
| 79 | + (haskell-process-compute-process-log-and-command "dummy-session3" 'cabal-ghci)))))) |
| 80 | + |
| 81 | +(ert-deftest test-haskell-process--compute-process-log-and-command-cabal-dev () |
| 82 | + (should (equal '("Starting inferior cabal-dev process cabal-dev -s directory/cabal-dev ..." "dumses4" nil "cabal-dev" "ghci" "-s" "directory/cabal-dev") |
| 83 | + (let ((haskell-process-path-cabal-dev "cabal-dev")) |
| 84 | + (custom-set-variables '(haskell-process-wrapper-function #'identity)) |
| 85 | + (mocklet (((haskell-session-name "dummy-session4") => "dumses4") |
| 86 | + ((haskell-session-cabal-dir "dummy-session4") => "directory")) |
| 87 | + (haskell-process-compute-process-log-and-command "dummy-session4" 'cabal-dev)))))) |
| 88 | + |
| 89 | +(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-dev () |
| 90 | + (should (equal '("Starting inferior cabal-dev process cabal-dev -s directory/cabal-dev ..." "dumses4" nil "run-with-docker" "cabal-dev\\ ghci\\ -s\\ directory/cabal-dev") |
| 91 | + (let ((haskell-process-path-cabal-dev "cabal-dev")) |
| 92 | + (custom-set-variables '(haskell-process-wrapper-function |
| 93 | + (lambda (argv) (append (list "run-with-docker") |
| 94 | + (list (shell-quote-argument (mapconcat 'identity argv " "))))))) |
| 95 | + (mocklet (((haskell-session-name "dummy-session4") => "dumses4") |
| 96 | + ((haskell-session-cabal-dir "dummy-session4") => "directory")) |
| 97 | + (haskell-process-compute-process-log-and-command "dummy-session4" 'cabal-dev)))))) |
| 98 | + |
| 99 | +;;; haskell-process-tests.el ends here |
0 commit comments