diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-05 04:54:24 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-05 07:43:25 +0100 |
commit | b57f3a35f23aae1b327b46a002201aa32edc525c (patch) | |
tree | f8a180bee2313be99d67b18e04aa541e6de6737a /test/Main.hs |
chore: init
Diffstat (limited to 'test/Main.hs')
-rw-r--r-- | test/Main.hs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/Main.hs b/test/Main.hs new file mode 100644 index 0000000..ad69469 --- /dev/null +++ b/test/Main.hs @@ -0,0 +1,57 @@ +{-# LANGUAGE BlockArguments #-} +{-# LANGUAGE QuasiQuotes #-} + +module Main (main) where + +import Data.ByteString.Char8 qualified as B +import Data.ByteString.Lazy.Char8 qualified as LB +import Data.Text qualified as T +import Data.Text.Lazy qualified as LT +import Process.Shell +import Test.Hspec + +main :: IO () +main = hspec do + describe "output" do + it "capture stdout" do + (`shouldBe` "stdout") . fst @String @String =<< [sh|echo -n stdout|] + it "capture stderr" do + (`shouldBe` "stderr") . snd @String =<< [sh|>&2 echo -n stderr|] + it "capture stdout and stderr interleaved" do + (`shouldBe` ("stdout", "stderr")) + =<< [sh| + echo -n stdout + >&2 echo -n stderr + |] + it "capture interleaved" do + (`shouldBe` "stdout\nstderr\n") + =<< [sh| + echo stdout + >&2 echo stderr + |] + describe "arguments" do + it "passes `Int`" do + (`shouldBe` "1") =<< [sh|echo -n %|] (1 :: Int) + it "passes `Text`" do + (`shouldBe` "foobar") =<< [sh|echo -n %|] (T.pack "foobar") + (`shouldBe` "foobar") =<< [sh|echo -n %|] (LT.pack "foobar") + it "passes `ByteString`" do + (`shouldBe` "foobar") =<< [sh|echo -n %|] (B.pack "foobar") + (`shouldBe` "foobar") =<< [sh|echo -n %|] (LB.pack "foobar") + describe "quoting" do + it "preserves arguments" do + (`shouldBe` "foo\\ bar") + =<< [sh|printf %%q %|] "foo bar" + it "preserves special characters" do + (`shouldBe` "foo\\ bar") + =<< [sh|foo=foo; bar=bar; ( printf %%q % )|] "$foo $bar" + it "escapes special characters" do + (`shouldBe` "\\$foo\\ \\$bar") + =<< [sh|printf %%q '%'|] "$foo $bar" + it "preserves empty arguments" do + (`shouldBe` "''") =<< [sh|printf %%q %|] "" + (`shouldBe` "''") =<< [sh|printf %%q '%'|] "" + describe "parsing" do + it "parses garbled arguments" do + (`shouldBe` "% foo") =<< [sh|echo -n '% ' %|] "foo" + (`shouldBe` " foo") =<< [sh|echo -n ' ' %|] "foo" |