Skip to content

Commit 0ff6f62

Browse files
committed
added test
1 parent 06bbf71 commit 0ff6f62

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/libpython_clj2/uv_test.clj

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(ns libpython-clj2.uv-test
2+
(:require [clojure.test :refer :all]
3+
[clojure.string :as str]
4+
[libpython-clj2.python.uv :as uv]))
5+
6+
7+
(deftest start-and-print-captures-stdout
8+
(let [out (with-out-str
9+
(@#'libpython-clj2.python.uv/start-and-print!
10+
["sh" "-lc" "printf 'hello\n' "]))]
11+
(is (= "hello\n" out))))
12+
13+
(deftest start-and-print-captures-stderr
14+
(let [out (with-out-str
15+
(@#'libpython-clj2.python.uv/start-and-print!
16+
["sh" "-lc" "printf 'oops\n' 1>&2 "]))]
17+
(is (= "oops\n" out))))
18+
19+
(deftest start-and-print-reads-stdout-then-stderr
20+
;; The child process writes interleaved to stdout and stderr, but
21+
;; start-and-print! reads stdout to completion before stderr, so the
22+
;; captured output should have all stdout first, then all stderr.
23+
(let [script (str/join "; " ["echo out1"
24+
"echo err1 1>&2"
25+
"echo out2"
26+
"echo err2 1>&2"])
27+
out (with-out-str
28+
(@#'libpython-clj2.python.uv/start-and-print!
29+
["sh" "-lc" script]))]
30+
(is (= (str "out1\n"
31+
"out2\n"
32+
"err1\n"
33+
"err2\n")
34+
out))))

0 commit comments

Comments
 (0)