Skip to content

Commit

Permalink
Switch from test-framework to tasty
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodigrim committed Dec 18, 2020
1 parent 684047c commit 8c631df
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 54 deletions.
6 changes: 3 additions & 3 deletions tests/Properties.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ import Prelude hiding (abs)

import Rules
import QuickCheckUtils
import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.Tasty
import Test.Tasty.QuickCheck

toInt64 :: Int -> Int64
toInt64 = fromIntegral
Expand Down Expand Up @@ -1854,7 +1854,7 @@ short_tests =
-- The entry point

main :: IO ()
main = defaultMain tests
main = defaultMain $ testGroup "All" tests

--
-- And now a list of all the properties to test.
Expand Down
10 changes: 4 additions & 6 deletions tests/Regressions.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import Control.Exception (SomeException, handle)
import Test.HUnit (assertBool, assertEqual, assertFailure)
import qualified Data.ByteString as B
import qualified Test.Framework as F
import qualified Test.Framework.Providers.HUnit as F
import qualified Test.Tasty as F
import qualified Test.Tasty.HUnit as F

-- Try to generate arguments to concat that are big enough to cause an
-- Int to overflow.
Expand All @@ -17,9 +17,7 @@ concat_overflow =
(lsize, bsize) | maxBound == (2147483647::Int) = (2^14, 2^18)
| otherwise = (2^34, 2^29)

tests :: [F.Test]
tests = [
F.testCase "concat_overflow" concat_overflow
]
tests :: F.TestTree
tests = F.testCase "concat_overflow" concat_overflow

main = F.defaultMain tests
2 changes: 1 addition & 1 deletion tests/Rules.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Word

import QuickCheckUtils

import Test.Framework.Providers.QuickCheck2
import Test.Tasty.QuickCheck

prop_break_C :: Word8 -> C.ByteString -> Bool
prop_break_C w = C.break ((==) x) `eq1` break ((==) x)
Expand Down
18 changes: 9 additions & 9 deletions tests/builder/Data/ByteString/Builder/Prim/TestUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ import System.ByteOrder
import System.IO.Unsafe (unsafePerformIO)

import Test.HUnit (assertBool)
import Test.Framework
import Test.Framework.Providers.HUnit
import Test.Framework.Providers.QuickCheck2
import Test.Tasty
import Test.Tasty.HUnit (testCase)
import Test.Tasty.QuickCheck (testProperty)
import Test.QuickCheck (Arbitrary(..))

-- Helper functions
Expand All @@ -91,7 +91,7 @@ import Test.QuickCheck (Arbitrary(..))
-- | Quickcheck test that includes a check that the property holds on the
-- bounds of a bounded value.
testBoundedProperty :: forall a. (Arbitrary a, Show a, Bounded a)
=> String -> (a -> Bool) -> Test
=> String -> (a -> Bool) -> TestTree
testBoundedProperty name p = testGroup name
[ testProperty name p
, testCase (name ++ " minBound") $ assertBool "minBound" (p (minBound :: a))
Expand Down Expand Up @@ -146,7 +146,7 @@ testF :: (Arbitrary a, Show a)
=> String
-> (a -> [Word8])
-> FixedPrim a
-> Test
-> TestTree
testF name ref fe =
testProperty name prop
where
Expand All @@ -167,7 +167,7 @@ testBoundedF :: (Arbitrary a, Bounded a, Show a)
=> String
-> (a -> [Word8])
-> FixedPrim a
-> Test
-> TestTree
testBoundedF name ref fe =
testBoundedProperty name $ \x -> evalF fe x == ref x

Expand All @@ -177,7 +177,7 @@ testFixedBoundF :: (Arbitrary a, Show a, Integral a)
=> String
-> (a -> a -> [Word8])
-> (a -> FixedPrim a)
-> Test
-> TestTree
testFixedBoundF name ref bfe =
testProperty name prop
where
Expand All @@ -204,7 +204,7 @@ testBoundedB :: (Arbitrary a, Bounded a, Show a)
=> String
-> (a -> [Word8])
-> BoundedPrim a
-> Test
-> TestTree
testBoundedB name ref fe =
testBoundedProperty name check
where
Expand All @@ -221,7 +221,7 @@ testBoundedB name ref fe =

-- | Compare two implementations of a function.
compareImpls :: (Arbitrary a, Show a, Show b, Eq b)
=> TestName -> (a -> b) -> (a -> b) -> Test
=> TestName -> (a -> b) -> (a -> b) -> TestTree
compareImpls name f1 f2 =
testProperty name check
where
Expand Down
20 changes: 10 additions & 10 deletions tests/builder/Data/ByteString/Builder/Prim/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ import Data.ByteString.Builder
import qualified Data.ByteString.Builder.Prim as BP
import Data.ByteString.Builder.Prim.TestUtils

import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.Tasty
import Test.Tasty.QuickCheck

tests :: [Test]
tests :: [TestTree]
tests = concat [ testsBinary, testsASCII, testsChar8, testsUtf8
, testsCombinatorsB, [testCString, testCStringUtf8] ]

testCString :: Test
testCString :: TestTree
testCString = testProperty "cstring" $
toLazyByteString (BP.cstring "hello world!"#) ==
LC.pack "hello" `L.append` L.singleton 0x20 `L.append` LC.pack "world!"

testCStringUtf8 :: Test
testCStringUtf8 :: TestTree
testCStringUtf8 = testProperty "cstringUtf8" $
toLazyByteString (BP.cstringUtf8 "hello\xc0\x80world!"#) ==
LC.pack "hello" `L.append` L.singleton 0x00 `L.append` LC.pack "world!"
Expand All @@ -40,7 +40,7 @@ testCStringUtf8 = testProperty "cstringUtf8" $
-- Binary
------------------------------------------------------------------------------

testsBinary :: [Test]
testsBinary :: [TestTree]
testsBinary =
[ testBoundedF "word8" bigEndian_list BP.word8
, testBoundedF "int8" bigEndian_list BP.int8
Expand Down Expand Up @@ -89,7 +89,7 @@ testsBinary =
-- Latin-1 aka Char8
------------------------------------------------------------------------------

testsChar8 :: [Test]
testsChar8 :: [TestTree]
testsChar8 =
[ testBoundedF "char8" char8_list BP.char8 ]

Expand All @@ -98,7 +98,7 @@ testsChar8 =
-- ASCII
------------------------------------------------------------------------------

testsASCII :: [Test]
testsASCII :: [TestTree]
testsASCII =
[ testBoundedF "char7" char7_list BP.char7

Expand Down Expand Up @@ -139,7 +139,7 @@ testsASCII =
-- UTF-8
------------------------------------------------------------------------------

testsUtf8 :: [Test]
testsUtf8 :: [TestTree]
testsUtf8 =
[ testBoundedB "charUtf8" charUtf8_list BP.charUtf8 ]

Expand All @@ -151,7 +151,7 @@ testsUtf8 =
maybeB :: BP.BoundedPrim () -> BP.BoundedPrim a -> BP.BoundedPrim (Maybe a)
maybeB nothing just = maybe (Left ()) Right BP.>$< BP.eitherB nothing just

testsCombinatorsB :: [Test]
testsCombinatorsB :: [TestTree]
testsCombinatorsB =
[ compareImpls "mapMaybe (via BoundedPrim)"
(L.pack . concatMap encChar)
Expand Down
32 changes: 16 additions & 16 deletions tests/builder/Data/ByteString/Builder/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ import Foreign (ForeignPtr, withForeignPtr, castPtr)
import Foreign.C.String (withCString)
import System.Posix.Internals (c_unlink)

import Test.Framework
import Test.Framework.Providers.QuickCheck2
import Test.Tasty
import Test.Tasty.QuickCheck (testProperty)

import Test.QuickCheck
( Arbitrary(..), oneof, choose, listOf, elements
, counterexample, ioProperty, UnicodeString(..), Property )


tests :: [Test]
tests :: [TestTree]
tests =
[ testBuilderRecipe
, testHandlePutBuilder
Expand All @@ -72,7 +72,7 @@ tests =
-- Testing 'Builder' execution
------------------------------------------------------------------------------

testBuilderRecipe :: Test
testBuilderRecipe :: TestTree
testBuilderRecipe =
testProperty "toLazyByteStringWith" $ testRecipe <$> arbitrary
where
Expand All @@ -89,7 +89,7 @@ testBuilderRecipe =
, "diff : " ++ show (dropWhile (uncurry (==)) $ zip x1 x2)
]

testHandlePutBuilder :: Test
testHandlePutBuilder :: TestTree
testHandlePutBuilder =
testProperty "hPutBuilder" testRecipe
where
Expand Down Expand Up @@ -140,7 +140,7 @@ testHandlePutBuilder =
unless success (error msg)
return success

testHandlePutBuilderChar8 :: Test
testHandlePutBuilderChar8 :: TestTree
testHandlePutBuilderChar8 =
testProperty "char8 hPutBuilder" testRecipe
where
Expand Down Expand Up @@ -365,7 +365,7 @@ instance Arbitrary Recipe where
-- Creating Builders from basic encodings
------------------------------------------------------------------------------

testsEncodingToBuilder :: [Test]
testsEncodingToBuilder :: [TestTree]
testsEncodingToBuilder =
[ test_encodeUnfoldrF
, test_encodeUnfoldrB
Expand All @@ -375,7 +375,7 @@ testsEncodingToBuilder =
-- Unfoldr fused with encoding
------------------------------

test_encodeUnfoldrF :: Test
test_encodeUnfoldrF :: TestTree
test_encodeUnfoldrF =
compareImpls "encodeUnfoldrF word8" id encode
where
Expand All @@ -387,7 +387,7 @@ test_encodeUnfoldrF =
go (w:ws) = Just (w, ws)


test_encodeUnfoldrB :: Test
test_encodeUnfoldrB :: TestTree
test_encodeUnfoldrB =
compareImpls "encodeUnfoldrB charUtf8" (foldMap charUtf8_list) encode
where
Expand All @@ -403,7 +403,7 @@ test_encodeUnfoldrB =
-- Testing the Put monad
------------------------------------------------------------------------------

testPut :: Test
testPut :: TestTree
testPut = testGroup "Put monad"
[ testLaw "identity" (\v -> (pure id <*> putInt v) `eqPut` (putInt v))

Expand Down Expand Up @@ -463,7 +463,7 @@ ensureFree minFree =
-- Testing the Builder runner
------------------------------------------------------------------------------

testRunBuilder :: Test
testRunBuilder :: TestTree
testRunBuilder =
testProperty "runBuilder" prop
where
Expand Down Expand Up @@ -505,7 +505,7 @@ bufferWriterOutput bwrite0 = do
------------------------------------------------------------------------------

testBuilderConstr :: (Arbitrary a, Show a)
=> TestName -> (a -> [Word8]) -> (a -> Builder) -> Test
=> TestName -> (a -> [Word8]) -> (a -> Builder) -> TestTree
testBuilderConstr name ref mkBuilder =
testProperty name check
where
Expand All @@ -516,7 +516,7 @@ testBuilderConstr name ref mkBuilder =
ws = ref x


testsBinary :: [Test]
testsBinary :: [TestTree]
testsBinary =
[ testBuilderConstr "word8" bigEndian_list word8
, testBuilderConstr "int8" bigEndian_list int8
Expand Down Expand Up @@ -560,7 +560,7 @@ testsBinary =
, testBuilderConstr "doubleHost" (double_list hostEndian_list) doubleHost
]

testsASCII :: [Test]
testsASCII :: [TestTree]
testsASCII =
[ testBuilderConstr "char7" char7_list char7
, testBuilderConstr "string7" (foldMap char7_list) string7
Expand Down Expand Up @@ -603,13 +603,13 @@ testsASCII =
where
enlarge (n, e) = n ^ (abs (e `mod` (50 :: Integer)))

testsChar8 :: [Test]
testsChar8 :: [TestTree]
testsChar8 =
[ testBuilderConstr "charChar8" char8_list char8
, testBuilderConstr "stringChar8" (foldMap char8_list) string8
]

testsUtf8 :: [Test]
testsUtf8 :: [TestTree]
testsUtf8 =
[ testBuilderConstr "charUtf8" charUtf8_list charUtf8
, testBuilderConstr "stringUtf8" (foldMap charUtf8_list) stringUtf8
Expand Down
6 changes: 3 additions & 3 deletions tests/builder/TestSuite.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module Main where

import qualified Data.ByteString.Builder.Tests
import qualified Data.ByteString.Builder.Prim.Tests
import Test.Framework (defaultMain, Test, testGroup)
import Test.Tasty (defaultMain, TestTree, testGroup)

main :: IO ()
main = defaultMain tests
main = defaultMain $ testGroup "All" tests

tests :: [Test]
tests :: [TestTree]
tests =
[ testGroup "Data.ByteString.Builder"
Data.ByteString.Builder.Tests.tests
Expand Down
10 changes: 4 additions & 6 deletions tests/bytestring-tests.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test-suite prop-compiled
Data.ByteString.Unsafe
hs-source-dirs: . ..
build-depends: base, ghc-prim, deepseq, random,
test-framework, test-framework-quickcheck2,
tasty, tasty-quickcheck,
QuickCheck >= 2.10 && < 2.15
c-sources: ../cbits/fpstring.c
include-dirs: ../include
Expand All @@ -56,7 +56,7 @@ test-suite lazy-hclose
Data.ByteString.Unsafe
hs-source-dirs: . ..
build-depends: base, ghc-prim, deepseq, random,
test-framework, test-framework-quickcheck2,
tasty,
QuickCheck >= 2.10 && < 2.15
c-sources: ../cbits/fpstring.c
include-dirs: ../include
Expand All @@ -72,7 +72,7 @@ executable regressions
Data.ByteString.Unsafe
hs-source-dirs: . ..
build-depends: base, ghc-prim, deepseq, random,
test-framework, test-framework-hunit, HUnit
tasty, HUnit
c-sources: ../cbits/fpstring.c
include-dirs: ../include
ghc-options: -fwarn-unused-binds
Expand Down Expand Up @@ -111,9 +111,7 @@ test-suite test-builder
dlist >= 0.5 && < 0.9,
transformers >= 0.3,
HUnit,
test-framework,
test-framework-hunit,
test-framework-quickcheck2 >= 0.3
tasty, tasty-hunit, tasty-quickcheck
ghc-options: -Wall -fwarn-tabs -threaded -rtsopts
c-sources: ../cbits/fpstring.c
../cbits/itoa.c
Expand Down

0 comments on commit 8c631df

Please sign in to comment.