test-simple 0.1 → 0.1.1
raw patch · 3 files changed
+20/−4 lines, 3 files
Files
- src/Test/Simple.hs +6/−1
- test-simple.cabal +1/−1
- tests/Main.hs +13/−2
src/Test/Simple.hs view
@@ -47,7 +47,7 @@ plan, -- * Test functions- ok, isnt, is, like, unlike,+ ok, isnt, is, like, unlike, isRight, -- * Diagnostics loc, diag) where@@ -146,6 +146,11 @@ -- | Is @a@ unlike @b@? unlike :: (Show a, Show b, Likeable a b, Monad m) => a -> b -> TestSimpleT m Bool unlike a b = ok (not $ isLike a b) >>? diagVals "" (quote a) "matches" (quote b)++-- | Is 'Either' right?+isRight :: (Monad m, Show a) => Either a b -> TestSimpleT m Bool+isRight (Right _) = ok True+isRight (Left a) = ok False >>? diagVals "got Left:" (quote a) "expected:" "Right" -- | Outputs diagnostics message. diag :: Monad m => String -> TestSimpleT m ()
test-simple.cabal view
@@ -1,5 +1,5 @@ Name: test-simple-Version: 0.1+Version: 0.1.1 License: BSD3 License-File: COPYING Copyright: Boris Sukholitko, 2012
tests/Main.hs view
@@ -78,16 +78,23 @@ like err "# got: '1'\n" like err "# expected: anything else\n" +testEither :: ExitCode -> String -> String -> TestSimpleT IO Bool+testEither ec out err = do+ isnt ec ExitSuccess+ like out "1..2"+ like out "ok 1"+ like err "got Left: '\"badleft\"'"+ testAll :: IO () testAll = testSimpleMain $ do- plan 40+ plan 44 pn <- liftIO getExecutablePath mapM_ (runMyself pn) [ ("bbbf", testUnknown), ("ok1", testOk1), ("nok1", testNOk1) , ("mism", testMismatch), ("isf", testIsFailure) , ("likef", testLikeFailure), ("qloc", testLocationPrint) , ("unlike", testOk1), ("fail_unlike", testUnlikeFailure) , ("guard", testOk1), ("mplus", testMPlus), ("fail_mplus", testMPlusFail)- , ("guardisnt", testGuard) ]+ , ("guardisnt", testGuard), ("either", testEither) ] where runMyself pn (arg, act) = do (ec, out, err) <- liftIO $ readProcessWithExitCode pn [ arg ] "" act ec out err@@ -109,5 +116,9 @@ [ "mplus" ] -> testSimpleMain $ (plan 1 >> ok True) >> (plan 1 >> ok True) [ "fail_mplus" ] -> testSimpleMain $ (plan 1 >> ok False) >> (plan 1 >> ok True) [ "guardisnt" ] -> testSimpleMain $ plan 1 >> (isnt (1::Int) 1 >>= guard) >> diag "DIAG"+ [ "either" ] -> testSimpleMain $ do+ plan 2+ isRight (Right "hhh" :: Either Int String)+ isRight (Left "badleft" :: Either String Int) _ -> error $ "Unknown: " ++ show as