on master help sign in
Make unixFilter output stderr when failing

Fixes #581.

commit7ee4e6134cc447c8b053129e7557d9883c7e8e01 authorNick Boultbee <declension@users.noreply.github.com> dateFri 17 Nov 2017, 14:55 (9 years ago) parent7a1f5cd
2 files changed+23−4
lib/Hakyll/Core/UnixFilter.hs+2−1 tests/Hakyll/Core/UnixFilter/Tests.hs+21−3
lib/Hakyll/Core/UnixFilter.hs+2−1
@@ -92,7 +92,8 @@ unixFilterWith writer reader programName args input = do
9292 ExitSuccess -> return output
9393 ExitFailure e -> fail $
9494 "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 ++ ")"
9697
9798
9899--------------------------------------------------------------------------------
tests/Hakyll/Core/UnixFilter/Tests.hs+21−3
@@ -17,6 +17,7 @@ import Hakyll.Core.Compiler
1717import Hakyll.Core.Compiler.Internal
1818import Hakyll.Core.Item
1919import Hakyll.Core.UnixFilter
20+import Hakyll.Core.Identifier
2021import TestSuite.Util
2122
2223
@@ -25,16 +26,19 @@ tests :: TestTree
2526tests = testGroup "Hakyll.Core.UnixFilter.Tests"
2627 [ testCase "unixFilter rev" unixFilterRev
2728 , testCase "unixFilter false" unixFilterFalse
29+ , testCase "unixFilter error" unixFilterError
2830 ]
2931
32+testMarkdown :: Identifier
33+testMarkdown = "russian.md"
3034
3135--------------------------------------------------------------------------------
3236unixFilterRev :: H.Assertion
3337unixFilterRev = do
3438 store <- newTestStore
3539 provider <- newTestProvider store
36− output <- testCompilerDone store provider "russian.md" compiler
37− expected <- testCompilerDone store provider "russian.md" getResourceString
40+ output <- testCompilerDone store provider testMarkdown compiler
41+ expected <- testCompilerDone store provider testMarkdown getResourceString
3842 H.assert $ rev (itemBody expected) == lines (itemBody output)
3943 cleanTestEnv
4044 where
@@ -47,10 +51,24 @@ unixFilterFalse :: H.Assertion
4751unixFilterFalse = do
4852 store <- newTestStore
4953 provider <- newTestProvider store
50− result <- testCompiler store provider "russian.md" compiler
54+ result <- testCompiler store provider testMarkdown compiler
5155 H.assert $ case result of
5256 CompilerError es -> any ("exit code" `isInfixOf`) es
5357 _ -> False
5458 cleanTestEnv
5559 where
5660 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" ["-#"])