git.iko.soy/typeable/generic-arbitrary
on master help sign in
test that infinite types have no Arbitrary
9bbd598Aleksey Uymanov
generic-arbitrary.cabal+20−1
@@ -59,8 +59,27 @@ test-suite test
59 , generic-arbitrary
59 , generic-arbitrary
60 , tasty
60 , tasty
61 , tasty-discover
61 , tasty-discover
62+ , tasty-hunit
62 , tasty-quickcheck
63 , tasty-quickcheck
64+ other-modules: NoTypecheckTest
63− other-modules: RecursiveTest
65+ , RecursiveTest
66+ default-extensions: AllowAmbiguousTypes
67+ , CPP
68+ , DataKinds
69+ , DeriveGeneric
70+ , FlexibleContexts
71+ , FlexibleInstances
72+ , GeneralizedNewtypeDeriving
73+ , LambdaCase
74+ , MultiParamTypeClasses
75+ , PolyKinds
76+ , RankNTypes
77+ , ScopedTypeVariables
78+ , TypeFamilies
79+ , TypeOperators
80+ , TypeSynonymInstances
81+ , UndecidableInstances
82+ , ViewPatterns
64 build-tools: tasty-discover
83 build-tools: tasty-discover
65 ghc-options: -Wall
84 ghc-options: -Wall
66 -threaded
85 -threaded
test/NoTypecheckTest.hsnew file+25
@@ -0,0 +1,25 @@
1+{-# OPTIONS_GHC -fdefer-type-errors #-}
2+
3+-- | Test that infinite types has no Arbitrary instance
4+
5+module NoTypecheckTest where
6+
7+import Control.Exception
8+import GHC.Generics (Generic)
9+import Test.QuickCheck
10+import Test.QuickCheck.Arbitrary.Generic
11+
12+
13+data R = R R
14+ deriving (Eq, Show, Generic)
15+
16+-- | Instance which must not be valid
17+instance Arbitrary R where
18+ arbitrary = genericArbitrary
19+ shrink = genericShrink
20+
21+unit_mustFail :: IO ()
22+unit_mustFail = do
23+ try (generate (arbitrary :: Gen R) >>= print) >>= \case
24+ Left (_ :: SomeException) -> pure ()
25+ Right _ -> error "Error expected"