packages feed

tahoe-chk-0.1.0.2: test/Spec.hs

module Main where

import Test.Tasty (TestTree, defaultMain, testGroup)

import System.IO (hSetEncoding, stderr, stdout, utf8)

import qualified SpecCHK
import qualified SpecCrypto
import qualified SpecMerkle
import qualified SpecServer
import qualified SpecUEB
import qualified SpecUpload
import qualified SpecUtil
import qualified SpecZFEC
import Test.Tasty.HUnit (assertBool, testCase)
import Vectors (loadTestVectorData)

tests :: [TestTree]
tests =
    [ SpecUpload.tests
    , SpecCrypto.tests
    , SpecMerkle.tests
    , SpecZFEC.tests
    , SpecUtil.tests
    , SpecUEB.tests
    , SpecServer.tests
    , SpecCHK.tests
    ]

failurePlaceholder :: String -> String -> TestTree
failurePlaceholder name msg = testCase name $ assertBool msg False

main :: IO ()
main = do
    -- Hedgehog writes some non-ASCII and the whole test process will die if
    -- it can't be encoded.  Increase the chances that all of the output can
    -- be encoded by forcing the use of UTF-8 (overriding the LANG-based
    -- choice normally made).
    hSetEncoding stdout utf8
    hSetEncoding stderr utf8

    testVectors <- loadTestVectorData
    let testVectorsTree =
            either
                (failurePlaceholder "CHK" . ("Test vectors: " ++) . show)
                SpecCHK.testsFromVectors
                testVectors
    defaultMain (testGroup "CHK" $ testVectorsTree : tests)