comparison src/clojure/contrib/test_contrib/test_shell.clj @ 10:ef7dbbd6452c

added clojure source goodness
author Robert McIntyre <rlm@mit.edu>
date Sat, 21 Aug 2010 06:25:44 -0400
parents
children
comparison
equal deleted inserted replaced
9:35cf337adfcf 10:ef7dbbd6452c
1 (ns clojure.contrib.test-shell
2 (:use clojure.test
3 clojure.contrib.shell)
4 (:import (java.io File)))
5
6 ; workaroung to access private parse-args. Better way?
7 (def parse-args ((ns-interns 'clojure.contrib.shell) 'parse-args))
8 (def as-file ((ns-interns 'clojure.contrib.shell) 'as-file))
9 (def as-env-string ((ns-interns 'clojure.contrib.shell) 'as-env-string))
10
11 (deftest test-parse-args
12 (are [x y] (= x y)
13 {:cmd [nil] :out "UTF-8" :dir nil :env nil} (parse-args [])
14 {:cmd ["ls"] :out "UTF-8" :dir nil :env nil} (parse-args ["ls"])
15 {:cmd ["ls" "-l"] :out "UTF-8" :dir nil :env nil} (parse-args ["ls" "-l"])
16 {:cmd ["ls"] :out "ISO-8859-1" :dir nil :env nil} (parse-args ["ls" :out "ISO-8859-1"])
17 ))
18
19 (deftest test-with-sh-dir
20 (are [x y] (= x y)
21 nil *sh-dir*
22 "foo" (with-sh-dir "foo" *sh-dir*)))
23
24 (deftest test-with-sh-env
25 (are [x y] (= x y)
26 nil *sh-env*
27 {:KEY "VAL"} (with-sh-env {:KEY "VAL"} *sh-env*)))
28
29 (deftest test-as-env-string
30 (are [x y] (= x y)
31 nil (as-env-string nil)
32 ["FOO=BAR"] (seq (as-env-string {"FOO" "BAR"}))
33 ["FOO_SYMBOL=BAR"] (seq (as-env-string {'FOO_SYMBOL "BAR"}))
34 ["FOO_KEYWORD=BAR"] (seq (as-env-string {:FOO_KEYWORD "BAR"}))))
35
36
37 (deftest test-as-file
38 (are [x y] (= x y)
39 (File. "foo") (as-file "foo")
40 nil (as-file nil)
41 (File. "bar") (as-file (File. "bar"))))