Revision 1263a102 test/hs/Test/Ganeti/TestCommon.hs

b/test/hs/Test/Ganeti/TestCommon.hs
60 60
  , genLuxiTagName
61 61
  , netmask2NumHosts
62 62
  , testSerialisation
63
  , testDeserialisationFail
63 64
  , resultProp
64 65
  , readTestData
65 66
  , genSample
......
373 374
    J.Error msg -> failTest $ "Failed to deserialise: " ++ msg
374 375
    J.Ok a' -> a ==? a'
375 376

  
377
-- | Checks if the deserializer doesn't accept forbidden values.
378
-- The first argument is ignored, it just enforces the correct type.
379
testDeserialisationFail :: (Eq a, Show a, J.JSON a)
380
                        => a -> J.JSValue -> Property
381
testDeserialisationFail a val =
382
  case liftM (`asTypeOf` a) $ J.readJSON val of
383
    J.Error _ -> passTest
384
    J.Ok x    -> failTest $ "Parsed invalid value " ++ show val ++
385
                            " to: " ++ show x
386

  
376 387
-- | Result to PropertyM IO.
377 388
resultProp :: (Show a) => BasicTypes.GenericResult a b -> PropertyM IO b
378 389
resultProp (BasicTypes.Bad err) = stop . failTest $ show err

Also available in: Unified diff