-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run tests from source, intro bbin integration tests (#6)
Also extend test suite to MS-Win. Co-authored-by: ikappaki <ikappaki@users.noreply.github.com>
- Loading branch information
Showing
4 changed files
with
156 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
(require 'clj2el) | ||
|
||
(require 'cl-lib) | ||
(require 'ert) | ||
|
||
(defmacro with-temp-bbin-install (&rest body) | ||
"Create a temp dir to install clj2el to with bbin and run BODY. | ||
The following functions are updated in BODY to use this installation | ||
- `clj2el-clj!' | ||
- `clj2el-transpile-buffer' (also called interactively with prefix arg) | ||
- `clj2el-transpile-range' (also called interactively with prefix arg)." | ||
(declare (indent 0)) | ||
`(let ((bbin-install-dir (make-temp-file "clj2el" t)) | ||
(bbin-exec (executable-find "bbin")) | ||
(env-bbd (getenv "BABASHKA_BBIN_DIR")) | ||
(env-path (getenv "PATH"))) | ||
;; (message ":temp-bbin-install-dir-created-at %s" bbin-install-dir) | ||
(unwind-protect | ||
(progn | ||
(should bbin-exec) | ||
(setenv "BABASHKA_BBIN_DIR" bbin-install-dir) | ||
(setenv "PATH" (concat (expand-file-name "bin" bbin-install-dir) path-separator | ||
(getenv "PATH"))) | ||
(with-temp-buffer | ||
(let ((ret (call-process-shell-command "bbin" nil (current-buffer) nil | ||
"install" "."))) | ||
(when (not (= ret 0)) | ||
(message ":bbin-install-error %s" (buffer-substring-no-properties (point-min) (point-max)))) | ||
(should (= ret 0)))) | ||
(cl-macrolet ((clj2el-clj! (expr) `(eval '(clj2el-clj! ,expr))) | ||
(clj2el-transpile-buffer () '(let ((current-prefix-arg '(4))) | ||
(call-interactively 'clj2el-transpile-buffer))) | ||
(clj2el-transpile-range () '(let ((current-prefix-arg '(4))) | ||
(call-interactively 'clj2el-transpile-range)))) | ||
,@body)) | ||
(progn | ||
(setenv "BABASHKA_BBIN_DIR" env-bbd) | ||
(setenv "PATH" env-path) | ||
;; (message ":temp-bbin-install-deleting... %s" bbin-install-dir) | ||
(delete-directory bbin-install-dir t))))) | ||
|
||
|
||
(ert-deftest integration () | ||
(with-temp-bbin-install | ||
|
||
;; clj2el-transpile-buffer | ||
(should (string= "(1+ 3)\n" | ||
(with-temp-buffer | ||
(insert "(inc 3)") | ||
(clj2el-transpile-buffer) | ||
(buffer-substring-no-properties (point-min) (point-max))))) | ||
|
||
;; clj2el-transpile-region | ||
(should (string= "[[ (1+ 4)\n ]]" | ||
(with-temp-buffer | ||
(insert "[[ (inc 4) ]]") | ||
(set-mark 4) | ||
(goto-char 11) | ||
(clj2el-transpile-region) | ||
(buffer-substring-no-properties (point-min) (point-max))))) | ||
|
||
|
||
;; clj2el-clj! | ||
(should (= 6 (clj2el-clj! (inc 5)))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,69 @@ | ||
(require 'clj2el) | ||
|
||
(require 'cl-lib) | ||
(require 'ert) | ||
|
||
(cl-defmacro with-clj2el-test (&rest body &aux (test-clj2el-command "bb -x clj2el.exec/exec")) | ||
"Execute BODY with `clj2el-command' bound to TEST-CLJ2EL-COMMAND. | ||
The command is supposed to execute clj2el from source. | ||
the following fucntions are also updated to be called interactively with a prefix arg: | ||
- `clj2el-transpile-buffer' | ||
- `clj2el-transpile-range'." | ||
(declare (indent 0)) | ||
`(let ((clj2el-command ,test-clj2el-command)) | ||
(cl-macrolet (;; use eval to pick up the updated | ||
;; `clj2el-command'. | ||
(clj2el-clj! (expr) `(eval '(clj2el-clj! ,expr))) | ||
|
||
;; call with prefix arg. | ||
(clj2el-transpile-buffer () '(let ((current-prefix-arg '(4))) | ||
(call-interactively 'clj2el-transpile-buffer))) | ||
(clj2el-transpile-range () '(let ((current-prefix-arg '(4))) | ||
(call-interactively 'clj2el-transpile-range)))) | ||
,@body))) | ||
|
||
(ert-deftest basic () | ||
(with-clj2el-test | ||
|
||
;; clj2el-transpile-buffer | ||
(should (string= "(1+ 2)\n" | ||
(with-temp-buffer | ||
(insert "(inc 2)") | ||
(clj2el-transpile-buffer) | ||
(buffer-substring-no-properties (point-min) (point-max))))) | ||
|
||
;; clj2el-transpile-region | ||
(should (string= "[[ (1+ 2)\n ]]" | ||
(with-temp-buffer | ||
(insert "[[ (inc 2) ]]") | ||
(set-mark 4) | ||
(goto-char 11) | ||
(clj2el-transpile-region) | ||
;; (test--call-interactively-with-prefix 'clj2el-transpile-region) | ||
(buffer-substring-no-properties (point-min) (point-max))))) | ||
|
||
|
||
;; clj2el-clj! | ||
(should (= 3 (clj2el-clj! (inc 2)))))) | ||
|
||
(ert-deftest juxt () | ||
(should (equal | ||
(clj2el-clj! ((juxt inc dec) 1)) | ||
'(2 0))) | ||
(should (equal | ||
(clj2el-clj! ((juxt + -) | ||
0 1 2 3 4 5)) | ||
'(15 -15))) | ||
;; Currently, `funcall' is required here. Might change in the future. | ||
(should (equal | ||
(clj2el-clj! (let [fns (juxt + -)] | ||
(funcall fns 0 1 2 3 4 5))) | ||
'(15 -15))) | ||
;; Missing `funcall' | ||
(should-error (clj2el-clj! (let [fns (juxt + -)] | ||
(fns 0 1 2 3 4 5))))) | ||
(with-clj2el-test | ||
(should (equal | ||
(clj2el-clj! ((juxt inc dec) 1)) | ||
'(2 0))) | ||
(should (equal | ||
(clj2el-clj! ((juxt + -) | ||
0 1 2 3 4 5)) | ||
'(15 -15))) | ||
;; Currently, `funcall' is required here. Might change in the future. | ||
|
||
(should (equal | ||
(clj2el-clj! (let [fns (juxt + -)] | ||
(funcall fns 0 1 2 3 4 5))) | ||
'(15 -15))) | ||
;; Missing `funcall' | ||
|
||
(should-error (clj2el-clj! (let [fns (juxt + -)] | ||
(fns 0 1 2 3 4 5)))))) |