Skip to content

Commit 50585eb

Browse files
committed
Add tests on haskell-process-wrapper-function
1 parent ec7ff37 commit 50585eb

File tree

2 files changed

+113
-1
lines changed

2 files changed

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

0 commit comments

Comments
 (0)