Skip to content

Commit 662f1d2

Browse files
ardumontgracjan
authored andcommitted
Add tests on haskell-process-wrapper-function
1 parent e63bdc6 commit 662f1d2

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

tests/haskell-process-tests.el

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

0 commit comments

Comments
 (0)