@@ -12,7 +12,7 @@ import Data.Text (Text)
12
12
import Data.Typeable
13
13
import Test.Hspec
14
14
import Test.Hspec.QuickCheck
15
- import Test.QuickCheck (Arbitrary )
15
+ import Test.QuickCheck (Arbitrary , Property , property , counterexample )
16
16
17
17
import Servant.API
18
18
import Servant.Swagger.Internal.TypeLevel
@@ -76,7 +76,7 @@ validateEveryToJSON :: forall proxy api. TMap (Every [Typeable, Show, Arbitrary,
76
76
-> Spec
77
77
validateEveryToJSON _ = props
78
78
(Proxy :: Proxy [ToJSON , ToSchema ])
79
- (null . validateToJSON)
79
+ (reportErrors . validateToJSON)
80
80
(Proxy :: Proxy (BodyTypes JSON api ))
81
81
82
82
-- | Verify that every type used with @'JSON'@ content type in a servant API
@@ -89,7 +89,7 @@ validateEveryToJSONWithPatternChecker :: forall proxy api. TMap (Every [Typeable
89
89
-> Spec
90
90
validateEveryToJSONWithPatternChecker checker _ = props
91
91
(Proxy :: Proxy [ToJSON , ToSchema ])
92
- (null . validateToJSONWithPatternChecker checker)
92
+ (reportErrors . validateToJSONWithPatternChecker checker)
93
93
(Proxy :: Proxy (BodyTypes JSON api ))
94
94
95
95
-- * QuickCheck-related stuff
@@ -102,7 +102,7 @@ validateEveryToJSONWithPatternChecker checker _ = props
102
102
-- context "read . show == id" $
103
103
-- props
104
104
-- (Proxy :: Proxy [Eq, Show, Read])
105
- -- (\x -> read (show x) == x)
105
+ -- (\x -> read (show x) === x)
106
106
-- (Proxy :: Proxy [Bool, Int, String])
107
107
-- :}
108
108
-- <BLANKLINE>
@@ -116,15 +116,23 @@ validateEveryToJSONWithPatternChecker checker _ = props
116
116
-- Finished in ... seconds
117
117
-- 3 examples, 0 failures
118
118
props :: forall p p'' cs xs . TMap (Every (Typeable ': Show ': Arbitrary ': cs )) xs =>
119
- p cs -- ^ A list of constraints.
120
- -> (forall x . EveryTF cs x => x -> Bool ) -- ^ Property predicate.
121
- -> p'' xs -- ^ A list of types.
119
+ p cs -- ^ A list of constraints.
120
+ -> (forall x . EveryTF cs x => x -> Property ) -- ^ Property predicate.
121
+ -> p'' xs -- ^ A list of types.
122
122
-> Spec
123
123
props _ f px = sequence_ specs
124
124
where
125
125
specs :: [Spec ]
126
126
specs = tmapEvery (Proxy :: Proxy (Typeable ': Show ': Arbitrary ': cs )) aprop px
127
127
128
128
aprop :: forall p' a . (EveryTF cs a , Typeable a , Show a , Arbitrary a ) => p' a -> Spec
129
- aprop _ = prop (show (typeOf (undefined :: a ))) (f :: a -> Bool )
129
+ aprop _ = prop (show (typeOf (undefined :: a ))) (f :: a -> Property )
130
130
131
+ -- | A property that prints a nicely formatted list of errors if there are
132
+ -- any.
133
+ reportErrors :: [ValidationError ] -> Property
134
+ reportErrors [] = property True
135
+ reportErrors ex = counterexample errString (property False )
136
+ where
137
+ errString = unlines $ " Validation against the schema fails:"
138
+ : map (" * " ++ ) ex
0 commit comments