From 8b9a3b6ef6277a9e99961c62796d963dd88906a7 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Sat, 9 Mar 2024 14:56:40 +0100 Subject: chore: strip trailing newlines by default Can be disabled by ending the quasi quotation template with a single backslash. --- test/Main.hs | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) (limited to 'test/Main.hs') diff --git a/test/Main.hs b/test/Main.hs index e00ccf6..96612dc 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -16,38 +16,40 @@ main :: IO () main = hspec do describe "output" do it "capture stdout" do - (`shouldBe` "stdout") . fst @String @String =<< [sh|echo -n stdout|] + (`shouldBe` "stdout") . fst @String @String =<< [sh|echo stdout|] it "capture stderr" do - (`shouldBe` "stderr") . snd @String =<< [sh|>&2 echo -n stderr|] - it "capture stdout and stderr interleaved" do + (`shouldBe` "stderr") . snd @String =<< [sh|>&2 echo stderr|] + it "capture stdout and stderr" do (`shouldBe` ("stdout", "stderr")) =<< [sh| - echo -n stdout - >&2 echo -n stderr + echo stdout + >&2 echo stderr |] - it "capture interleaved" do - (`shouldBe` "stdout\nstderr\n") + it "capture stdout and stderr interleaved" do + (`shouldBe` "stdout\nstderr") =<< [sh| echo stdout >&2 echo stderr |] + it "preserve trailing newline" do + (`shouldBe` "stdout\n") . fst @String @String =<< [sh|echo stdout \|] describe "arguments" do it "passes `Int`" do - (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo -n '#{x}'|] + (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo '#{x}'|] it "passes `Text`" do - (`shouldBe` "foobar") =<< let x = T.pack "foobar" in [sh|echo -n '#{x}'|] - (`shouldBe` "foobar") =<< let x = LT.pack "foobar" in [sh|echo -n '#{x}'|] + (`shouldBe` "foobar") =<< let x = T.pack "foobar" in [sh|echo '#{x}'|] + (`shouldBe` "foobar") =<< let x = LT.pack "foobar" in [sh|echo '#{x}'|] it "passes `ByteString`" do - (`shouldBe` "foobar") =<< let x = B.pack "foobar" in [sh|echo -n '#{x}'|] - (`shouldBe` "foobar") =<< let x = LB.pack "foobar" in [sh|echo -n '#{x}'|] + (`shouldBe` "foobar") =<< let x = B.pack "foobar" in [sh|echo '#{x}'|] + (`shouldBe` "foobar") =<< let x = LB.pack "foobar" in [sh|echo '#{x}'|] it "interpolates expressions" do - (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo -n '#{show x}'|] + (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo '#{show x}'|] it "interpolates monadic expressions" do - (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo -n '#{{pure @IO x}}'|] + (`shouldBe` "1") =<< let x = 1 :: Int in [sh|echo '#{{pure @IO x}}'|] it "interpolates monadic expressions" do - (`shouldBe` "1") =<< runReaderT [sh|echo -n '#{{asks fst}}'|] (1 :: Int, 2 :: Int) + (`shouldBe` "1") =<< runReaderT [sh|echo '#{{asks fst}}'|] (1 :: Int, 2 :: Int) it "preserves argument order" do - (`shouldBe` "1 2") =<< let x = "1"; y = "2" in [sh|echo -n '#{x}' '#{y}'|] + (`shouldBe` "1 2") =<< let x = "1"; y = "2" in [sh|echo '#{x}' '#{y}'|] describe "quoting" do it "preserves arguments" do (`shouldBe` "foo\\ bar") @@ -63,6 +65,6 @@ main = hspec do (`shouldBe` "''") =<< let x = "" in [sh|printf %q '#{x}'|] describe "parsing" do it "parses shell quotes" do - (`shouldBe` "foobar") =<< [sh|echo -n 'foobar'|] + (`shouldBe` "foobar") =<< [sh|echo 'foobar'|] it "parses double cross" do - (`shouldBe` "0") =<< [sh|echo -n $#|] + (`shouldBe` "0") =<< [sh|echo $#|] -- cgit v1.2.3