Skip to content

Commit 036102a

Browse files
NorfairKingTom Sydney Kerckhove
andauthored
Evaluate NoContent before (not) rendering it. (#1587)
* Evaluate NoContent before rendering it, so it shows up as covered in coverage reports * failing test as well * test that NoContent gets rendered if it is not an exception Co-authored-by: Tom Sydney Kerckhove <[email protected]>
1 parent 5e1569e commit 036102a

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

servant/src/Servant/API/ContentTypes.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ instance {-# OVERLAPPABLE #-}
295295
-- then this would be taken care of. However there is no more specific instance
296296
-- between that and 'MimeRender JSON a', so we do this instead
297297
instance {-# OVERLAPPING #-} ( Accept ctyp ) => AllMimeRender '[ctyp] NoContent where
298-
allMimeRender _ _ = map (, "") $ NE.toList $ contentTypes pctyp
298+
allMimeRender _ NoContent = map (, "") $ NE.toList $ contentTypes pctyp
299299
where
300300
pctyp = Proxy :: Proxy ctyp
301301

servant/test/Servant/API/ContentTypesSpec.hs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ import Data.String.Conversions
3333
import qualified Data.Text as TextS
3434
import qualified Data.Text.Encoding as TextSE
3535
import qualified Data.Text.Lazy as TextL
36+
import Control.Exception
37+
(evaluate)
3638
import GHC.Generics
3739
import Test.Hspec
3840
import Test.QuickCheck
@@ -78,6 +80,15 @@ spec = describe "Servant.API.ContentTypes" $ do
7880
it "has mimeUnrender reverse mimeRender for valid top-level json " $ do
7981
property $ \x -> mimeUnrender p (mimeRender p x) == Right (x::SomeData)
8082

83+
describe "The NoContent Content-Type type" $ do
84+
let p = Proxy :: Proxy '[JSON]
85+
86+
it "does not render any content" $
87+
allMimeRender p NoContent `shouldSatisfy` (all (BSL8.null . snd))
88+
89+
it "evaluates the NoContent value" $
90+
evaluate (allMimeRender p (undefined :: NoContent)) `shouldThrow` anyErrorCall
91+
8192
describe "The PlainText Content-Type type" $ do
8293
let p = Proxy :: Proxy PlainText
8394

0 commit comments

Comments
 (0)