Skip to content

Commit 3d507b9

Browse files
committed
Extract tempfile routine to with-tempfile macro
1 parent 0646bce commit 3d507b9

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

clj/src/vim_clojure_static/test.clj

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,27 @@
99
(:import (java.io File)
1010
(java.util List)))
1111

12+
(defmacro with-tempfile
13+
{:requires [File]}
14+
[tmp-sym & body]
15+
`(let [~tmp-sym (File/createTempFile "vim-clojure-static" ".tmp")]
16+
(try
17+
~@body
18+
(finally
19+
(.delete ~tmp-sym)))))
20+
1221
(defn vim-exec
1322
"Spit buf into file, then execute vim-expr after Vim loads the file. The
1423
value of vim-expr is evaluated as EDN and returned."
1524
[file buf vim-expr]
16-
(let [tmp (File/createTempFile "vim-clojure-static.test." ".out")]
17-
(try
18-
(io/make-parents file)
19-
(spit file buf)
20-
(spit tmp (str "let @x = " vim-expr))
21-
(shell/sh "vim" "-N" "-u" "vim/test-runtime.vim"
22-
"-c" (str "source " tmp " | call writefile([@x], " (pr-str (str tmp)) ") | quitall!")
23-
file)
24-
(edn/read-string (slurp tmp))
25-
(finally
26-
(.delete tmp)))))
25+
(with-tempfile tmp
26+
(io/make-parents file)
27+
(spit file buf)
28+
(spit tmp (str "let @x = " vim-expr))
29+
(shell/sh "vim" "-N" "-u" "vim/test-runtime.vim"
30+
"-c" (str "source " tmp " | call writefile([@x], " (pr-str (str tmp)) ") | quitall!")
31+
file)
32+
(edn/read-string (slurp tmp))))
2733

2834
(defn syn-id-names
2935
"Map lines of clojure text to vim synID names at each column as keywords:
@@ -62,7 +68,7 @@
6268
At runtime the syn-id-names of the strings (which are placed in the format
6369
spec) are passed to their associated predicates. The format spec should
6470
contain a single `%s`."
65-
{:require [#'test/deftest]}
71+
{:requires [#'test/deftest syn-id-names subfmt]}
6672
[name & body]
6773
(assert (every? (fn [[fmt tests]] (and (string? fmt)
6874
(coll? tests)
@@ -76,7 +82,6 @@
7682
[[] []] body)
7783
syntable (gensym "syntable")]
7884
`(test/deftest ~name
79-
;; Shellout to vim should happen at runtime
8085
(let [~syntable (syn-id-names (str "tmp/" ~(str name) ".clj") ~@strings)]
8186
~@(map (fn [{:keys [fmt ss λs]}]
8287
`(test/testing ~fmt

0 commit comments

Comments
 (0)