Skip to content

Commit 07bf9cd

Browse files
committed
Add tests on haskell-process-wrapper-function
1 parent ec7ff37 commit 07bf9cd

File tree

2 files changed

+114
-1
lines changed

2 files changed

+114
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
haskell-mode-autoloads.el
44
haskell-mode.info
55
haskell-mode.tmp.texi
6-
dir
6+
dir

tests/haskell-process-tests.el

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
10+
(progn ;; HACK install package.el including for emacs-23.3, then install external el-mock dependency
11+
(when (version< emacs-version "24")
12+
(with-current-buffer (url-retrieve-synchronously "http://git.savannah.gnu.org/gitweb/?p=emacs.git;a=blob_plain;hb=ba08b24186711eaeb3748f3d1f23e2c2d9ed0d09;f=lisp/emacs-lisp/package.el")
13+
(save-excursion
14+
(goto-char (point-min))
15+
(kill-line 8)
16+
(eval-buffer))))
17+
(require 'package)
18+
(package-initialize)
19+
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
20+
(package-refresh-contents)
21+
(package-install 'el-mock))
22+
23+
(require 'el-mock)
24+
25+
(ert-deftest haskell-process-wrapper-command-function-identity ()
26+
"No wrapper, return directly the command."
27+
(should (equal '("ghci")
28+
(progn
29+
(custom-set-variables '(haskell-process-wrapper-function #'identity))
30+
(apply haskell-process-wrapper-function (list '("ghci")))))))
31+
32+
(ert-deftest haskell-process-wrapper-function-non-identity ()
33+
"Wrapper as a string, return the wrapping command as a string."
34+
(should (equal '("nix-shell" "default.nix" "--command" "cabal\\ run")
35+
(progn
36+
(custom-set-variables '(haskell-process-wrapper-function (lambda (argv)
37+
(append '("nix-shell" "default.nix" "--command")
38+
(list (shell-quote-argument argv))))))
39+
(apply haskell-process-wrapper-function (list "cabal run"))))))
40+
41+
(ert-deftest test-haskell-process--compute-process-log-and-command-ghci ()
42+
(should (equal '("Starting inferior GHCi process ghci ..." "dumses1" nil "ghci" "-ferror-spans")
43+
(let ((haskell-process-path-ghci "ghci")
44+
(haskell-process-args-ghci '("-ferror-spans")))
45+
(custom-set-variables '(haskell-process-wrapper-function #'identity))
46+
(mocklet (((haskell-session-name "dummy-session") => "dumses1"))
47+
(haskell-process-compute-process-log-and-command "dummy-session" 'ghci))))))
48+
49+
(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-ghci ()
50+
(should (equal '("Starting inferior GHCi process ghci ..." "dumses1" nil "nix-shell" "default.nix" "--command" "ghci\\ -ferror-spans")
51+
(let ((haskell-process-path-ghci "ghci")
52+
(haskell-process-args-ghci '("-ferror-spans")))
53+
(custom-set-variables '(haskell-process-wrapper-function
54+
(lambda (argv) (append (list "nix-shell" "default.nix" "--command" )
55+
(list (shell-quote-argument (mapconcat 'identity argv " ")))))))
56+
(mocklet (((haskell-session-name "dummy-session") => "dumses1"))
57+
(haskell-process-compute-process-log-and-command "dummy-session" 'ghci))))))
58+
59+
(ert-deftest test-haskell-process--compute-process-log-and-command-cabal-repl ()
60+
(should (equal '("Starting inferior `cabal repl' process using cabal ..." "dumses2" nil "cabal" "repl" "--ghc-option=-ferror-spans" "dumdum-session")
61+
(let ((haskell-process-path-cabal "cabal")
62+
(haskell-process-args-cabal-repl '("--ghc-option=-ferror-spans")))
63+
(custom-set-variables '(haskell-process-wrapper-function #'identity))
64+
(mocklet (((haskell-session-name "dummy-session2") => "dumses2")
65+
((haskell-session-target "dummy-session2") => "dumdum-session"))
66+
(haskell-process-compute-process-log-and-command "dummy-session2" 'cabal-repl))))))
67+
68+
(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-repl ()
69+
(should (equal '("Starting inferior `cabal repl' process using cabal ..." "dumses2" nil "nix-shell" "default.nix" "--command" "cabal\\ repl\\ --ghc-option\\=-ferror-spans" "dumdum-session")
70+
(let ((haskell-process-path-cabal "cabal")
71+
(haskell-process-args-cabal-repl '("--ghc-option=-ferror-spans")))
72+
(custom-set-variables '(haskell-process-wrapper-function
73+
(lambda (argv) (append (list "nix-shell" "default.nix" "--command" )
74+
(list (shell-quote-argument (mapconcat 'identity argv " ")))))))
75+
(mocklet (((haskell-session-name "dummy-session2") => "dumses2")
76+
((haskell-session-target "dummy-session2") => "dumdum-session"))
77+
(haskell-process-compute-process-log-and-command "dummy-session2" 'cabal-repl))))))
78+
79+
(ert-deftest test-haskell-process--compute-process-log-and-command-cabal-ghci ()
80+
(should (equal '("Starting inferior cabal-ghci process using cabal-ghci ..." "dumses3" nil "cabal-ghci")
81+
(let ((haskell-process-path-ghci "ghci"))
82+
(custom-set-variables '(haskell-process-wrapper-function #'identity))
83+
(mocklet (((haskell-session-name "dummy-session3") => "dumses3"))
84+
(haskell-process-compute-process-log-and-command "dummy-session3" 'cabal-ghci))))))
85+
86+
(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-ghci ()
87+
(should (equal '("Starting inferior cabal-ghci process using cabal-ghci ..." "dumses3" nil "nix-shell" "default.nix" "--command" "cabal-ghci")
88+
(let ((haskell-process-path-ghci "ghci"))
89+
(custom-set-variables '(haskell-process-wrapper-function
90+
(lambda (argv) (append (list "nix-shell" "default.nix" "--command" )
91+
(list (shell-quote-argument (mapconcat 'identity argv " ")))))))
92+
(mocklet (((haskell-session-name "dummy-session3") => "dumses3"))
93+
(haskell-process-compute-process-log-and-command "dummy-session3" 'cabal-ghci))))))
94+
95+
(ert-deftest test-haskell-process--compute-process-log-and-command-cabal-dev ()
96+
(should (equal '("Starting inferior cabal-dev process cabal-dev -s directory/cabal-dev ..." "dumses4" nil "cabal-dev" "ghci" "-s" "directory/cabal-dev")
97+
(let ((haskell-process-path-cabal-dev "cabal-dev"))
98+
(custom-set-variables '(haskell-process-wrapper-function #'identity))
99+
(mocklet (((haskell-session-name "dummy-session4") => "dumses4")
100+
((haskell-session-cabal-dir "dummy-session4") => "directory"))
101+
(haskell-process-compute-process-log-and-command "dummy-session4" 'cabal-dev))))))
102+
103+
(ert-deftest test-haskell-process--with-wrapper-compute-process-log-and-command-cabal-dev ()
104+
(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")
105+
(let ((haskell-process-path-cabal-dev "cabal-dev"))
106+
(custom-set-variables '(haskell-process-wrapper-function
107+
(lambda (argv) (append (list "run-with-docker")
108+
(list (shell-quote-argument (mapconcat 'identity argv " ")))))))
109+
(mocklet (((haskell-session-name "dummy-session4") => "dumses4")
110+
((haskell-session-cabal-dir "dummy-session4") => "directory"))
111+
(haskell-process-compute-process-log-and-command "dummy-session4" 'cabal-dev))))))
112+
113+
;;; haskell-process-tests.el ends here

0 commit comments

Comments
 (0)