git.iko.soy/typeable/generic-arbitrary
on master help sign in
test that infinite types have no Arbitrary
commit9bbd598f9e9668b6652e8fc8a751b2b77de223c5 authorAleksey Uymanov <s9gf4ult@gmail.com> dateMon 2 Aug 2021, 19:33 (5 years ago) parentb33b921
2 files changed+45−1
generic-arbitrary.cabal+20−1 test/NoTypecheckTest.hs+25
generic-arbitrary.cabal+20−1
@@ -59,8 +59,27 @@ test-suite test
5959 , generic-arbitrary
6060 , tasty
6161 , tasty-discover
62+ , tasty-hunit
6263 , tasty-quickcheck
63− other-modules: RecursiveTest
64+ other-modules: NoTypecheckTest
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
6483 build-tools: tasty-discover
6584 ghc-options: -Wall
6685 -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"