[#173] rename *in* to <input> (BREAKING!)
This commit is contained in:
parent
5e10c913e0
commit
a9231b7ecf
5 changed files with 64 additions and 64 deletions
44
README.md
44
README.md
|
|
@ -12,7 +12,7 @@ A Clojure [babushka](https://en.wikipedia.org/wiki/Headscarf) for the grey areas
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ bash <(curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install)
|
$ bash <(curl -s https://raw.githubusercontent.com/borkdude/babashka/master/install)
|
||||||
$ ls | bb --time -i '(filter #(-> % io/file .isDirectory) *in*)'
|
$ ls | bb --time -i '(filter #(-> % io/file .isDirectory) <input>)'
|
||||||
("doc" "resources" "sci" "script" "src" "target" "test")
|
("doc" "resources" "sci" "script" "src" "target" "test")
|
||||||
bb took 4ms.
|
bb took 4ms.
|
||||||
```
|
```
|
||||||
|
|
@ -57,29 +57,29 @@ Experimental. Breaking changes are expected to happen at this phase.
|
||||||
## Examples
|
## Examples
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ ls | bb -i '*in*'
|
$ ls | bb -i '<input>'
|
||||||
["LICENSE" "README.md" "bb" "doc" "pom.xml" "project.clj" "reflection.json" "resources" "script" "src" "target" "test"]
|
["LICENSE" "README.md" "bb" "doc" "pom.xml" "project.clj" "reflection.json" "resources" "script" "src" "target" "test"]
|
||||||
|
|
||||||
$ ls | bb -i '(count *in*)'
|
$ ls | bb -i '(count <input>)'
|
||||||
12
|
12
|
||||||
|
|
||||||
$ bb '(vec (dedupe *in*))' <<< '[1 1 1 1 2]'
|
$ bb '(vec (dedupe <input>))' <<< '[1 1 1 1 2]'
|
||||||
[1 2]
|
[1 2]
|
||||||
|
|
||||||
$ bb '(filterv :foo *in*)' <<< '[{:foo 1} {:bar 2}]'
|
$ bb '(filterv :foo <input>)' <<< '[{:foo 1} {:bar 2}]'
|
||||||
[{:foo 1}]
|
[{:foo 1}]
|
||||||
|
|
||||||
$ bb '(#(+ %1 %2 %3) 1 2 *in*)' <<< 3
|
$ bb '(#(+ %1 %2 %3) 1 2 <input>)' <<< 3
|
||||||
6
|
6
|
||||||
|
|
||||||
$ ls | bb -i '(filterv #(re-find #"reflection" %) *in*)'
|
$ ls | bb -i '(filterv #(re-find #"reflection" %) <input>)'
|
||||||
["reflection.json"]
|
["reflection.json"]
|
||||||
|
|
||||||
$ bb '(run! #(shell/sh "touch" (str "/tmp/test/" %)) (range 100))'
|
$ bb '(run! #(shell/sh "touch" (str "/tmp/test/" %)) (range 100))'
|
||||||
$ ls /tmp/test | bb -i '*in*'
|
$ ls /tmp/test | bb -i '<input>'
|
||||||
["0" "1" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "2" "20" "21" ...]
|
["0" "1" "10" "11" "12" "13" "14" "15" "16" "17" "18" "19" "2" "20" "21" ...]
|
||||||
|
|
||||||
$ bb -O '(repeat "dude")' | bb --stream '(str *in* "rino")' | bb -I '(take 3 *in*)'
|
$ bb -O '(repeat "dude")' | bb --stream '(str <input> "rino")' | bb -I '(take 3 <input>)'
|
||||||
("duderino" "duderino" "duderino")
|
("duderino" "duderino" "duderino")
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -136,12 +136,12 @@ Options:
|
||||||
|
|
||||||
--help, -h or -? Print this help text.
|
--help, -h or -? Print this help text.
|
||||||
--version Print the current version of babashka.
|
--version Print the current version of babashka.
|
||||||
-i Bind *in* to a lazy seq of lines from stdin.
|
-i Bind <input> to a lazy seq of lines from stdin.
|
||||||
-I Bind *in* to a lazy seq of EDN values from stdin.
|
-I Bind <input> to a lazy seq of EDN values from stdin.
|
||||||
-o Write lines to stdout.
|
-o Write lines to stdout.
|
||||||
-O Write EDN values to stdout.
|
-O Write EDN values to stdout.
|
||||||
--verbose Print entire stacktrace in case of exception.
|
--verbose Print entire stacktrace in case of exception.
|
||||||
--stream Stream over lines or EDN values from stdin. Combined with -i or -I *in* becomes a single value per iteration.
|
--stream Stream over lines or EDN values from stdin. Combined with -i or -I <input> becomes a single value per iteration.
|
||||||
-e, --eval <expr> Evaluate an expression.
|
-e, --eval <expr> Evaluate an expression.
|
||||||
-f, --file <path> Evaluate a file.
|
-f, --file <path> Evaluate a file.
|
||||||
-cp, --classpath Classpath to use.
|
-cp, --classpath Classpath to use.
|
||||||
|
|
@ -214,7 +214,7 @@ conditionals](#reader-conditionals) to maintain compatibility with JVM Clojure.
|
||||||
|
|
||||||
Special vars:
|
Special vars:
|
||||||
|
|
||||||
- `*in*`: contains the input read from stdin. EDN by default, multiple lines of
|
- `<input>`: contains the input read from stdin. EDN by default, multiple lines of
|
||||||
text with the `-i` option, or multiple EDN values with the `-I` option.
|
text with the `-i` option, or multiple EDN values with the `-I` option.
|
||||||
- `*command-line-args*`: contain the command line args
|
- `*command-line-args*`: contain the command line args
|
||||||
|
|
||||||
|
|
@ -330,7 +330,7 @@ export BABASHKA_PRELOADS
|
||||||
Note that you can concatenate multiple expressions. Now you can use these functions in babashka:
|
Note that you can concatenate multiple expressions. Now you can use these functions in babashka:
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ bb '(-> (foo *in*) bar)' <<< 1
|
$ bb '(-> (foo <input>) bar)' <<< 1
|
||||||
6
|
6
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -340,7 +340,7 @@ You can also preload an entire file using `load-file`:
|
||||||
export BABASHKA_PRELOADS='(load-file "my_awesome_prelude.clj")'
|
export BABASHKA_PRELOADS='(load-file "my_awesome_prelude.clj")'
|
||||||
```
|
```
|
||||||
|
|
||||||
Note that `*in*` is not available in preloads.
|
Note that `<input>` is not available in preloads.
|
||||||
|
|
||||||
## Classpath
|
## Classpath
|
||||||
|
|
||||||
|
|
@ -563,7 +563,7 @@ welcome!
|
||||||
### Delete a list of files returned by a Unix command
|
### Delete a list of files returned by a Unix command
|
||||||
|
|
||||||
```
|
```
|
||||||
find . | grep conflict | bb -i '(doseq [f *in*] (.delete (io/file f)))'
|
find . | grep conflict | bb -i '(doseq [f <input>] (.delete (io/file f)))'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Calculate aggregate size of directory
|
### Calculate aggregate size of directory
|
||||||
|
|
@ -597,7 +597,7 @@ $ cat /tmp/test.txt
|
||||||
3 Babashka
|
3 Babashka
|
||||||
4 Goodbye
|
4 Goodbye
|
||||||
|
|
||||||
$ < /tmp/test.txt bb -io '(shuffle *in*)'
|
$ < /tmp/test.txt bb -io '(shuffle <input>)'
|
||||||
3 Babashka
|
3 Babashka
|
||||||
2 Clojure
|
2 Clojure
|
||||||
4 Goodbye
|
4 Goodbye
|
||||||
|
|
@ -611,7 +611,7 @@ For converting JSON to EDN, see [jet](https://github.com/borkdude/jet).
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ curl -s https://api.github.com/repos/borkdude/babashka/tags |
|
$ curl -s https://api.github.com/repos/borkdude/babashka/tags |
|
||||||
jet --from json --keywordize --to edn |
|
jet --from json --keywordize --to edn |
|
||||||
bb '(-> *in* first :name (subs 1))'
|
bb '(-> <input> first :name (subs 1))'
|
||||||
"0.0.4"
|
"0.0.4"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -620,8 +620,8 @@ bb '(-> *in* first :name (subs 1))'
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ curl -s https://api.github.com/repos/borkdude/babashka/releases |
|
$ curl -s https://api.github.com/repos/borkdude/babashka/releases |
|
||||||
jet --from json --keywordize |
|
jet --from json --keywordize |
|
||||||
bb '(-> *in* first :assets)' |
|
bb '(-> <input> first :assets)' |
|
||||||
bb '(some #(re-find #".*linux.*" (:browser_download_url %)) *in*)'
|
bb '(some #(re-find #".*linux.*" (:browser_download_url %)) <input>)'
|
||||||
"https://github.com/borkdude/babashka/releases/download/v0.0.4/babashka-0.0.4-linux-amd64.zip"
|
"https://github.com/borkdude/babashka/releases/download/v0.0.4/babashka-0.0.4-linux-amd64.zip"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
@ -631,7 +631,7 @@ Contributed by [@plexus](https://github.com/plexus).
|
||||||
|
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ curl https://clojars.org/stats/all.edn |
|
$ curl https://clojars.org/stats/all.edn |
|
||||||
bb -o '(for [[[group art] counts] *in*] (str (reduce + (vals counts)) " " group "/" art))' |
|
bb -o '(for [[[group art] counts] <input>] (str (reduce + (vals counts)) " " group "/" art))' |
|
||||||
sort -rn |
|
sort -rn |
|
||||||
less
|
less
|
||||||
14113842 clojure-complete/clojure-complete
|
14113842 clojure-complete/clojure-complete
|
||||||
|
|
@ -684,7 +684,7 @@ Contributed by [@plexus](https://github.com/plexus).
|
||||||
``` shellsession
|
``` shellsession
|
||||||
$ cat project.clj |
|
$ cat project.clj |
|
||||||
sed -e 's/#=//g' -e 's/~@//g' -e 's/~//g' |
|
sed -e 's/#=//g' -e 's/~@//g' -e 's/~//g' |
|
||||||
bb '(let [{:keys [dependencies source-paths resource-paths]} (apply hash-map (drop 3 *in*))]
|
bb '(let [{:keys [dependencies source-paths resource-paths]} (apply hash-map (drop 3 <input>))]
|
||||||
{:paths (into source-paths resource-paths)
|
{:paths (into source-paths resource-paths)
|
||||||
:deps (into {} (for [[d v] dependencies] [d {:mvn/version v}]))}) ' |
|
:deps (into {} (for [[d v] dependencies] [d {:mvn/version v}]))}) ' |
|
||||||
jet --pretty > deps.edn
|
jet --pretty > deps.edn
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,12 @@
|
||||||
(println "
|
(println "
|
||||||
--help, -h or -? Print this help text.
|
--help, -h or -? Print this help text.
|
||||||
--version Print the current version of babashka.
|
--version Print the current version of babashka.
|
||||||
-i Bind *in* to a lazy seq of lines from stdin.
|
-i Bind <input> to a lazy seq of lines from stdin.
|
||||||
-I Bind *in* to a lazy seq of EDN values from stdin.
|
-I Bind <input> to a lazy seq of EDN values from stdin.
|
||||||
-o Write lines to stdout.
|
-o Write lines to stdout.
|
||||||
-O Write EDN values to stdout.
|
-O Write EDN values to stdout.
|
||||||
--verbose Print entire stacktrace in case of exception.
|
--verbose Print entire stacktrace in case of exception.
|
||||||
--stream Stream over lines or EDN values from stdin. Combined with -i or -I *in* becomes a single value per iteration.
|
--stream Stream over lines or EDN values from stdin. Combined with -i or -I <input> becomes a single value per iteration.
|
||||||
-e, --eval <expr> Evaluate an expression.
|
-e, --eval <expr> Evaluate an expression.
|
||||||
-f, --file <path> Evaluate a file.
|
-f, --file <path> Evaluate a file.
|
||||||
-cp, --classpath Classpath to use.
|
-cp, --classpath Classpath to use.
|
||||||
|
|
@ -175,14 +175,14 @@ Everything after that is bound to *command-line-args*."))
|
||||||
|
|
||||||
(defn start-repl! [ctx read-next]
|
(defn start-repl! [ctx read-next]
|
||||||
(let [ctx (update ctx :bindings assoc
|
(let [ctx (update ctx :bindings assoc
|
||||||
(with-meta '*in*
|
(with-meta '<input>
|
||||||
{:sci/deref! true})
|
{:sci/deref! true})
|
||||||
(read-next))]
|
(read-next))]
|
||||||
(repl/start-repl! ctx)))
|
(repl/start-repl! ctx)))
|
||||||
|
|
||||||
(defn start-socket-repl! [address ctx read-next]
|
(defn start-socket-repl! [address ctx read-next]
|
||||||
(let [ctx (update ctx :bindings assoc
|
(let [ctx (update ctx :bindings assoc
|
||||||
(with-meta '*in*
|
(with-meta '<input>
|
||||||
{:sci/deref! true})
|
{:sci/deref! true})
|
||||||
(read-next))]
|
(read-next))]
|
||||||
(socket-repl/start-repl! address ctx)
|
(socket-repl/start-repl! address ctx)
|
||||||
|
|
@ -294,7 +294,7 @@ Everything after that is bound to *command-line-args*."))
|
||||||
(let [expr (if file (read-file file) expression)]
|
(let [expr (if file (read-file file) expression)]
|
||||||
(if expr
|
(if expr
|
||||||
(loop [in (read-next *in*)]
|
(loop [in (read-next *in*)]
|
||||||
(let [ctx (update-in ctx [:namespaces 'user] assoc (with-meta '*in*
|
(let [ctx (update-in ctx [:namespaces 'user] assoc (with-meta '<input>
|
||||||
(when-not stream?
|
(when-not stream?
|
||||||
{:sci/deref! true})) in)]
|
{:sci/deref! true})) in)]
|
||||||
(if (identical? ::EOF in)
|
(if (identical? ::EOF in)
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
(defn repl! []
|
(defn repl! []
|
||||||
(start-repl! {:bindings {(with-meta '*in*
|
(start-repl! {:bindings {(with-meta '<input>
|
||||||
{:sci/deref! true})
|
{:sci/deref! true})
|
||||||
(delay [1 2 3])
|
(delay [1 2 3])
|
||||||
'*command-line-args*
|
'*command-line-args*
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
(assert-repl "1\n(dec *1)(+ *2 *2)" "2")
|
(assert-repl "1\n(dec *1)(+ *2 *2)" "2")
|
||||||
(assert-repl "1\n(dec *1)(+ *2 *2)" "2")
|
(assert-repl "1\n(dec *1)(+ *2 *2)" "2")
|
||||||
(assert-repl "*command-line-args*" "[\"a\" \"b\" \"c\"]")
|
(assert-repl "*command-line-args*" "[\"a\" \"b\" \"c\"]")
|
||||||
(assert-repl "*in*" "[1 2 3]"))
|
(assert-repl "<input>" "[1 2 3]"))
|
||||||
|
|
||||||
;;;; Scratch
|
;;;; Scratch
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
(deftest socket-repl-test
|
(deftest socket-repl-test
|
||||||
(try
|
(try
|
||||||
(if tu/jvm?
|
(if tu/jvm?
|
||||||
(start-repl! "0.0.0.0:1666" {:bindings {(with-meta '*in*
|
(start-repl! "0.0.0.0:1666" {:bindings {(with-meta '<input>
|
||||||
{:sci/deref! true})
|
{:sci/deref! true})
|
||||||
(delay [1 2 3])
|
(delay [1 2 3])
|
||||||
'*command-line-args*
|
'*command-line-args*
|
||||||
|
|
@ -47,8 +47,8 @@
|
||||||
(sh "bash" "-c"
|
(sh "bash" "-c"
|
||||||
"lsof -t -i:1666"))))))
|
"lsof -t -i:1666"))))))
|
||||||
(is (socket-command "(+ 1 2 3)" "user=> 6"))
|
(is (socket-command "(+ 1 2 3)" "user=> 6"))
|
||||||
(testing "*in*"
|
(testing "<input>"
|
||||||
(is (socket-command "*in*" "[1 2 3]")))
|
(is (socket-command "<input>" "[1 2 3]")))
|
||||||
(testing "*command-line-args*"
|
(testing "*command-line-args*"
|
||||||
(is (socket-command '*command-line-args* "\"a\" \"b\" \"c\"")))
|
(is (socket-command '*command-line-args* "\"a\" \"b\" \"c\"")))
|
||||||
(testing "&env"
|
(testing "&env"
|
||||||
|
|
@ -72,7 +72,7 @@
|
||||||
(dotimes [_ 1000]
|
(dotimes [_ 1000]
|
||||||
(t/run-tests))
|
(t/run-tests))
|
||||||
(stop-repl!)
|
(stop-repl!)
|
||||||
(start-repl! "0.0.0.0:1666" {:bindings {(with-meta '*in*
|
(start-repl! "0.0.0.0:1666" {:bindings {(with-meta '<input>
|
||||||
{:sci/deref! true})
|
{:sci/deref! true})
|
||||||
(delay [1 2 3])
|
(delay [1 2 3])
|
||||||
'*command-line-args*
|
'*command-line-args*
|
||||||
|
|
|
||||||
|
|
@ -34,45 +34,45 @@
|
||||||
|
|
||||||
(deftest main-test
|
(deftest main-test
|
||||||
(testing "-io behaves as identity"
|
(testing "-io behaves as identity"
|
||||||
(= "foo\nbar\n" (test-utils/bb "foo\nbar\n" "-io" "*in*")))
|
(= "foo\nbar\n" (test-utils/bb "foo\nbar\n" "-io" "<input>")))
|
||||||
(testing "if and when"
|
(testing "if and when"
|
||||||
(is (= 1 (bb 0 '(if (zero? *in*) 1 2))))
|
(is (= 1 (bb 0 '(if (zero? <input>) 1 2))))
|
||||||
(is (= 2 (bb 1 '(if (zero? *in*) 1 2))))
|
(is (= 2 (bb 1 '(if (zero? <input>) 1 2))))
|
||||||
(is (= 1 (bb 0 '(when (zero? *in*) 1))))
|
(is (= 1 (bb 0 '(when (zero? <input>) 1))))
|
||||||
(is (nil? (bb 1 '(when (zero? *in*) 1)))))
|
(is (nil? (bb 1 '(when (zero? <input>) 1)))))
|
||||||
(testing "and and or"
|
(testing "and and or"
|
||||||
(is (= false (bb 0 '(and false true *in*))))
|
(is (= false (bb 0 '(and false true <input>))))
|
||||||
(is (= 0 (bb 0 '(and true true *in*))))
|
(is (= 0 (bb 0 '(and true true <input>))))
|
||||||
(is (= 1 (bb 1 '(or false false *in*))))
|
(is (= 1 (bb 1 '(or false false <input>))))
|
||||||
(is (= false (bb false '(or false false *in*))))
|
(is (= false (bb false '(or false false <input>))))
|
||||||
(is (= 3 (bb false '(or false false *in* 3)))))
|
(is (= 3 (bb false '(or false false <input> 3)))))
|
||||||
(testing "fn"
|
(testing "fn"
|
||||||
(is (= 2 (bb 1 "(#(+ 1 %) *in*)")))
|
(is (= 2 (bb 1 "(#(+ 1 %) <input>)")))
|
||||||
(is (= [1 2 3] (bb 1 "(map #(+ 1 %) [0 1 2])")))
|
(is (= [1 2 3] (bb 1 "(map #(+ 1 %) [0 1 2])")))
|
||||||
(is (= 1 (bb 1 "(#(when (odd? *in*) *in*))"))))
|
(is (= 1 (bb 1 "(#(when (odd? <input>) <input>))"))))
|
||||||
(testing "map"
|
(testing "map"
|
||||||
(is (= [1 2 3] (bb 1 '(map inc [0 1 2])))))
|
(is (= [1 2 3] (bb 1 '(map inc [0 1 2])))))
|
||||||
(testing "keep"
|
(testing "keep"
|
||||||
(is (= [false true false] (bb 1 '(keep odd? [0 1 2])))))
|
(is (= [false true false] (bb 1 '(keep odd? [0 1 2])))))
|
||||||
(testing "->"
|
(testing "->"
|
||||||
(is (= 4 (bb 1 '(-> *in* inc inc (inc))))))
|
(is (= 4 (bb 1 '(-> <input> inc inc (inc))))))
|
||||||
(testing "->>"
|
(testing "->>"
|
||||||
(is (= 10 (edn/read-string (test-utils/bb "foo\n\baar\baaaaz" "-i" "(->> *in* (map count) (apply max))")))))
|
(is (= 10 (edn/read-string (test-utils/bb "foo\n\baar\baaaaz" "-i" "(->> <input> (map count) (apply max))")))))
|
||||||
(testing "literals"
|
(testing "literals"
|
||||||
(is (= {:a 4
|
(is (= {:a 4
|
||||||
:b {:a 2}
|
:b {:a 2}
|
||||||
:c [1 1]
|
:c [1 1]
|
||||||
:d #{1 2}}
|
:d #{1 2}}
|
||||||
(bb 1 '{:a (+ 1 2 *in*)
|
(bb 1 '{:a (+ 1 2 <input>)
|
||||||
:b {:a (inc *in*)}
|
:b {:a (inc <input>)}
|
||||||
:c [*in* *in*]
|
:c [<input> <input>]
|
||||||
:d #{*in* (inc *in*)}}))))
|
:d #{<input> (inc <input>)}}))))
|
||||||
(testing "shuffle the contents of a file"
|
(testing "shuffle the contents of a file"
|
||||||
(let [in "foo\n Clojure is nice. \nbar\n If you're nice to clojure. "
|
(let [in "foo\n Clojure is nice. \nbar\n If you're nice to clojure. "
|
||||||
in-lines (set (str/split in #"\n"))
|
in-lines (set (str/split in #"\n"))
|
||||||
out (test-utils/bb in
|
out (test-utils/bb in
|
||||||
"-io"
|
"-io"
|
||||||
(str '(shuffle *in*)))
|
(str '(shuffle <input>)))
|
||||||
out-lines (set (str/split out #"\n"))]
|
out-lines (set (str/split out #"\n"))]
|
||||||
(is (= in-lines out-lines))))
|
(is (= in-lines out-lines))))
|
||||||
(testing "find occurrences in file by line number"
|
(testing "find occurrences in file by line number"
|
||||||
|
|
@ -80,14 +80,14 @@
|
||||||
(->
|
(->
|
||||||
(bb "foo\n Clojure is nice. \nbar\n If you're nice to clojure. "
|
(bb "foo\n Clojure is nice. \nbar\n If you're nice to clojure. "
|
||||||
"-i"
|
"-i"
|
||||||
"(map-indexed #(-> [%1 %2]) *in*)")
|
"(map-indexed #(-> [%1 %2]) <input>)")
|
||||||
(bb "(keep #(when (re-find #\"(?i)clojure\" (second %)) (first %)) *in*)"))))))
|
(bb "(keep #(when (re-find #\"(?i)clojure\" (second %)) (first %)) <input>)"))))))
|
||||||
|
|
||||||
(deftest println-test
|
(deftest println-test
|
||||||
(is (= "hello\n" (test-utils/bb nil "(println \"hello\")"))))
|
(is (= "hello\n" (test-utils/bb nil "(println \"hello\")"))))
|
||||||
|
|
||||||
(deftest input-test
|
(deftest input-test
|
||||||
(testing "bb doesn't wait for input if *in* isn't used"
|
(testing "bb doesn't wait for input if <input> isn't used"
|
||||||
(is (= "2\n" (with-out-str (main/main "(inc 1)"))))))
|
(is (= "2\n" (with-out-str (main/main "(inc 1)"))))))
|
||||||
|
|
||||||
(deftest System-test
|
(deftest System-test
|
||||||
|
|
@ -114,12 +114,12 @@
|
||||||
(is (re-find #"doctype html" resp))))
|
(is (re-find #"doctype html" resp))))
|
||||||
|
|
||||||
(deftest stream-test
|
(deftest stream-test
|
||||||
(is (= "2\n3\n4\n" (test-utils/bb "1 2 3" "--stream" "(inc *in*)")))
|
(is (= "2\n3\n4\n" (test-utils/bb "1 2 3" "--stream" "(inc <input>)")))
|
||||||
(is (= "2\n3\n4\n" (test-utils/bb "{:x 2} {:x 3} {:x 4}" "--stream" "(:x *in*)")))
|
(is (= "2\n3\n4\n" (test-utils/bb "{:x 2} {:x 3} {:x 4}" "--stream" "(:x <input>)")))
|
||||||
(let [x "foo\n\bar\n"]
|
(let [x "foo\n\bar\n"]
|
||||||
(is (= x (test-utils/bb x "--stream" "-io" "*in*"))))
|
(is (= x (test-utils/bb x "--stream" "-io" "<input>"))))
|
||||||
(let [x "f\n\b\n"]
|
(let [x "f\n\b\n"]
|
||||||
(is (= x (test-utils/bb x "--stream" "-io" "(subs *in* 0 1)")))))
|
(is (= x (test-utils/bb x "--stream" "-io" "(subs <input> 0 1)")))))
|
||||||
|
|
||||||
(deftest load-file-test
|
(deftest load-file-test
|
||||||
(let [tmp (java.io.File/createTempFile "script" ".clj")]
|
(let [tmp (java.io.File/createTempFile "script" ".clj")]
|
||||||
|
|
@ -145,21 +145,21 @@
|
||||||
(deftest pipe-test
|
(deftest pipe-test
|
||||||
(when test-utils/native?
|
(when test-utils/native?
|
||||||
(let [out (:out (sh "bash" "-c" "./bb -o '(range)' |
|
(let [out (:out (sh "bash" "-c" "./bb -o '(range)' |
|
||||||
./bb --stream '(* *in* *in*)' |
|
./bb --stream '(* <input> <input>)' |
|
||||||
head -n10"))
|
head -n10"))
|
||||||
out (str/split-lines out)
|
out (str/split-lines out)
|
||||||
out (map edn/read-string out)]
|
out (map edn/read-string out)]
|
||||||
(is (= (take 10 (map #(* % %) (range))) out))))
|
(is (= (take 10 (map #(* % %) (range))) out))))
|
||||||
(when test-utils/native?
|
(when test-utils/native?
|
||||||
(let [out (:out (sh "bash" "-c" "./bb -O '(repeat \"dude\")' |
|
(let [out (:out (sh "bash" "-c" "./bb -O '(repeat \"dude\")' |
|
||||||
./bb --stream '(str *in* \"rino\")' |
|
./bb --stream '(str <input> \"rino\")' |
|
||||||
./bb -I '(take 3 *in*)'"))
|
./bb -I '(take 3 <input>)'"))
|
||||||
out (edn/read-string out)]
|
out (edn/read-string out)]
|
||||||
(is (= '("duderino" "duderino" "duderino") out)))))
|
(is (= '("duderino" "duderino" "duderino") out)))))
|
||||||
|
|
||||||
(deftest lazy-text-in-test
|
(deftest lazy-text-in-test
|
||||||
(when test-utils/native?
|
(when test-utils/native?
|
||||||
(let [out (:out (sh "bash" "-c" "yes | ./bb -i '(take 2 *in*)'"))
|
(let [out (:out (sh "bash" "-c" "yes | ./bb -i '(take 2 <input>)'"))
|
||||||
out (edn/read-string out)]
|
out (edn/read-string out)]
|
||||||
(is (= '("y" "y") out)))))
|
(is (= '("y" "y") out)))))
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue