Last active
December 17, 2015 05:04
-
-
Save mookerji/d6c9fe48bc35e16bd569 to your computer and use it in GitHub Desktop.
Environmental fails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Test.QuickCheck | |
import Test.QuickCheck.Instances.Maybe | |
import Test.QuickCheck.Monadic | |
instance Arbitrary LogLevel where | |
arbitrary = do | |
n <- choose (0, 4) :: Gen Int | |
return $ case n of | |
0 -> LevelDebug | |
1 -> LevelInfo | |
2 -> LevelWarn | |
3 -> LevelError | |
4 -> LevelOther "other" | |
instance Arbitrary Conf where | |
arbitrary = Conf <$> maybeGen nonulls | |
<*> maybeGen arbitrary | |
<*> maybeGen arbitrary | |
<*> maybeGen arbitrary | |
where nonempty = getNonEmpty <$> arbitrary | |
nonulls = nonempty `suchThat` (not . ('\NUL' `elem`)) | |
testEnvProperties :: TestTree | |
testEnvProperties = testGroup "(checked by QuickCheck)" | |
[ QC.testProperty "Log Level environmental configuration" $ | |
\(x :: LogLevel) -> Just x == fromVar (toVar x) | |
, QC.testProperty "Configuration environmental configuration" $ | |
\(c :: Conf) -> monadicIO $ do | |
res <- run $ do | |
let Conf{..} = c | |
set k v = maybe (unsetEnv k) (\x -> setEnv k $ (unpack . show) x) v | |
set "SKYLARK_CONFFILE" _cConfFile | |
set "SKYLARK_PORT" _cPort | |
set "SKYLARK_TIMEOUT" _cTimeout | |
set "SKYLARK_LOGLEVEL" _cLogLevel | |
decodeEnv | |
Test.QuickCheck.Monadic.assert $ res == Right c | |
] | |
testProperties :: TestTree | |
testProperties = testGroup "Properties" [ testEnvProperties ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment