on master help sign in
Make unixFilter output stderr when failing
7ee4e61Nick Boultbee
lib/Hakyll/Core/UnixFilter.hs+2−1
@@ -92,7 +92,8 @@ unixFilterWith writer reader programName args input = do
92 ExitSuccess -> return output
92 ExitSuccess -> return output
93 ExitFailure e -> fail $
93 ExitFailure e -> fail $
94 "Hakyll.Core.UnixFilter.unixFilterWith: " ++
94 "Hakyll.Core.UnixFilter.unixFilterWith: " ++
95− unwords (programName : args) ++ " gave exit code " ++ show e
95+ unwords (programName : args) ++ " gave exit code " ++ show e ++
96+ ". (Error: " ++ err ++ ")"
96
97
97
98
98--------------------------------------------------------------------------------
99--------------------------------------------------------------------------------
tests/Hakyll/Core/UnixFilter/Tests.hs+21−3
@@ -17,6 +17,7 @@ import Hakyll.Core.Compiler
17import Hakyll.Core.Compiler.Internal
17import Hakyll.Core.Compiler.Internal
18import Hakyll.Core.Item
18import Hakyll.Core.Item
19import Hakyll.Core.UnixFilter
19import Hakyll.Core.UnixFilter
20+import Hakyll.Core.Identifier
20import TestSuite.Util
21import TestSuite.Util
21
22
22
23
@@ -25,16 +26,19 @@ tests :: TestTree
25tests = testGroup "Hakyll.Core.UnixFilter.Tests"
26tests = testGroup "Hakyll.Core.UnixFilter.Tests"
26 [ testCase "unixFilter rev" unixFilterRev
27 [ testCase "unixFilter rev" unixFilterRev
27 , testCase "unixFilter false" unixFilterFalse
28 , testCase "unixFilter false" unixFilterFalse
29+ , testCase "unixFilter error" unixFilterError
28 ]
30 ]
29
31
32+testMarkdown :: Identifier
33+testMarkdown = "russian.md"
30
34
31--------------------------------------------------------------------------------
35--------------------------------------------------------------------------------
32unixFilterRev :: H.Assertion
36unixFilterRev :: H.Assertion
33unixFilterRev = do
37unixFilterRev = do
34 store <- newTestStore
38 store <- newTestStore
35 provider <- newTestProvider store
39 provider <- newTestProvider store
36− output <- testCompilerDone store provider "russian.md" compiler
40+ output <- testCompilerDone store provider testMarkdown compiler
37− expected <- testCompilerDone store provider "russian.md" getResourceString
41+ expected <- testCompilerDone store provider testMarkdown getResourceString
38 H.assert $ rev (itemBody expected) == lines (itemBody output)
42 H.assert $ rev (itemBody expected) == lines (itemBody output)
39 cleanTestEnv
43 cleanTestEnv
40 where
44 where
@@ -47,10 +51,24 @@ unixFilterFalse :: H.Assertion
47unixFilterFalse = do
51unixFilterFalse = do
48 store <- newTestStore
52 store <- newTestStore
49 provider <- newTestProvider store
53 provider <- newTestProvider store
50− result <- testCompiler store provider "russian.md" compiler
54+ result <- testCompiler store provider testMarkdown compiler
51 H.assert $ case result of
55 H.assert $ case result of
52 CompilerError es -> any ("exit code" `isInfixOf`) es
56 CompilerError es -> any ("exit code" `isInfixOf`) es
53 _ -> False
57 _ -> False
54 cleanTestEnv
58 cleanTestEnv
55 where
59 where
56 compiler = getResourceString >>= withItemBody (unixFilter "false" [])
60 compiler = getResourceString >>= withItemBody (unixFilter "false" [])
61+
62+
63+--------------------------------------------------------------------------------
64+unixFilterError :: H.Assertion
65+unixFilterError = do
66+ store <- newTestStore
67+ provider <- newTestProvider store
68+ result <- testCompiler store provider testMarkdown compiler
69+ H.assert $ case result of
70+ CompilerError es -> any ("invalid option" `isInfixOf`) es
71+ _ -> False
72+ cleanTestEnv
73+ where
74+ compiler = getResourceString >>= withItemBody (unixFilter "head" ["-#"])