From: Ramakrishnan Muthukrishnan Date: Fri, 21 Jul 2017 16:36:04 +0000 (+0530) Subject: run bencode tests as well X-Git-Url: https://git.rkrishnan.org/listings/specifications//%22file:/%22?a=commitdiff_plain;h=54e38026518ff34a59879b9a2b6582a728dc0525;p=functorrent.git run bencode tests as well --- diff --git a/functorrent.cabal b/functorrent.cabal index b85e836..ba04b12 100644 --- a/functorrent.cabal +++ b/functorrent.cabal @@ -82,5 +82,7 @@ test-suite functorrent-test main-is: Main.hs other-modules: MagneturiTests build-depends: base + , bytestring , functorrent , hspec + , QuickCheck diff --git a/test/BencodeTests.hs b/test/BencodeTests.hs index c83e9cc..d889643 100644 --- a/test/BencodeTests.hs +++ b/test/BencodeTests.hs @@ -2,16 +2,31 @@ module BencodeTests (tests) where import FuncTorrent.Bencode (encode, decode, BVal(..)) -import Test.Tasty (TestTree, testGroup) -import Test.Tasty.QuickCheck (testProperty) +import Test.Hspec +import Test.QuickCheck +import Data.ByteString.Char8 (unpack, pack) propEncodeDecode :: BVal -> Bool propEncodeDecode bval = let encoded = encode bval decoded = decode encoded in Right bval == decoded -qcTests :: TestTree -qcTests = testGroup "QuickCheck tests" [ testProperty "encode/decode" propEncodeDecode ] - -tests :: TestTree -tests = testGroup "Tests" [qcTests] +tests :: IO () +tests = hspec $ do + describe "BVal tests" $ do + it "encode/decode bstr tests" $ do + property $ \s -> + let encoded = encode (Bstr s) + decoded = decode encoded + in Right (Bstr s) == decoded + it "encode/decode bint tests" $ do + property $ \i -> + let encoded = encode (Bint i) + decoded = decode encoded + in Right (Bint i) == decoded + -- describe "Bencode property tests" $ do + -- it "encode/decode" $ do + -- property $ \bval -> + -- let encoded = encode bval + -- decoded = decode encoded + -- in Right bval == decoded diff --git a/test/Main.hs b/test/Main.hs index 09d3e98..974ec54 100644 --- a/test/Main.hs +++ b/test/Main.hs @@ -2,8 +2,11 @@ module Main where -import MagneturiTests +import qualified MagneturiTests as Muri +import qualified BencodeTests as Benc main :: IO () -main = tests +main = do + Muri.tests + Benc.tests