diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-13 07:02:37 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-13 07:17:42 +0100 |
commit | 3ea4e6459333409c60f66a5745bb472d136da741 (patch) | |
tree | 543ae3e13dd805bf88906f5967681ff3251e243d /test | |
parent | 7c12524d9935d564dc359eb4db01038406e45f38 (diff) |
chore: add `ConduitT` instancesmain
Diffstat (limited to 'test')
-rw-r--r-- | test/Main.hs | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/test/Main.hs b/test/Main.hs index 2f20997..f6bfaf6 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -5,6 +5,7 @@ module Main (main) where +import Conduit import Data.ByteString.Char8 qualified as B import Data.ByteString.Lazy.Char8 qualified as LB import Data.Text qualified as T @@ -14,25 +15,67 @@ import Test.Hspec main :: IO () main = hspec do + describe "input" do + it "capture stdin" do + (`shouldBe` "stdin") =<< runConduitRes (yield "stdin\n" .| [sh|cat|]) + (`shouldBe` "stdin") =<< runConduitRes (yield "stdin\n" .| [sh|cat|] .| foldC) describe "output" do it "capture stdout" do - (`shouldBe` "stdout") . fst @String @String =<< [sh|echo stdout|] + (`shouldBe` "stdout") . fst @String @() =<< [sh|echo stdout|] + (`shouldBe` "stdout") . fst @String @String =<< runConduitRes [sh|echo stdout|] + (`shouldBe` "stdout") . snd @String @String =<< runConduitRes ([sh|echo stdout|] .| partitionEithersC) + -- TODO conduit it "capture stderr" do - (`shouldBe` "stderr") . snd @String =<< [sh|>&2 echo stderr|] + (`shouldBe` "stderr") . snd @() @String =<< [sh|>&2 echo stderr|] + (`shouldBe` "stderr") . snd @() @String =<< runConduitRes [sh|>&2 echo stderr|] + (`shouldBe` "stderr") . fst @String @String + =<< runConduitRes ([sh|>&2 echo stderr|] .| partitionEithersC) it "capture stdout and stderr" do (`shouldBe` ("stdout", "stderr")) =<< [sh| echo stdout >&2 echo stderr |] + (`shouldBe` ("stdout", "stderr")) + =<< runConduitRes + ( [sh| + echo stdout + >&2 echo stderr + |] + ) + (`shouldBe` ("stderr", "stdout")) + =<< runConduitRes + ( [sh| + echo stdout + >&2 echo stderr + |] + .| partitionEithersC + ) it "capture stdout and stderr interleaved" do (`shouldBe` "stdout\nstderr") =<< [sh| echo stdout >&2 echo stderr |] + (`shouldBe` "stdout\nstderr") + =<< runConduitRes + ( [sh| + echo stdout + >&2 echo stderr + |] + ) + (`shouldBe` "stdout\nstderr") + =<< runConduitRes + ( [sh| + echo stdout + >&2 echo stderr + |] + .| foldC + ) it "preserve trailing newline" do - (`shouldBe` "stdout\n") . fst @String @String =<< [sh|echo stdout \|] + (`shouldBe` "stdout\n") =<< [sh|echo stdout \|] + (`shouldBe` "stdout\n") =<< runConduitRes [sh|echo stdout \|] + (`shouldBe` "stdout\n") =<< runConduitRes ([sh|echo stdout \|] .| foldC) describe "arguments" do it "passes `Int`" do (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo '#{x}'|] @@ -64,3 +107,7 @@ main = hspec do (`shouldBe` "foobar") =<< [sh|echo 'foobar'|] it "parses double cross" do (`shouldBe` "0") =<< [sh|echo $#|] + +partitionEithersC :: (Monad m, Monoid a, Monoid b) => ConduitT (Either a b) o m (a, b) +partitionEithersC = + foldlC (\(es, rs) x -> either (\e -> (e `mappend` es, rs)) (\r -> (es, r `mappend` rs)) x) (mempty, mempty) |