{-# LANGUAGE CPP #-}
import qualified Test.Posix
import qualified Test.Utils
import qualified Test.Tree
import qualified Test.Index
import qualified Test.IO
import qualified Test.Hash
import qualified Test.TreeMonad
import qualified Test.DarcsPristine

import Test.Framework( defaultMain, testGroup )
import System.Directory( createDirectory, removeDirectoryRecursive
                       , setCurrentDirectory )
import Codec.Archive.Zip( extractFilesFromArchive, toArchive )
import qualified Data.ByteString.Lazy as BL

#if mingw32_HOST_OS
testdata = "testdata-win.zip"
#else
testdata = "testdata-posix.zip"
#endif

tests = [ testGroup "Bundled.Posix" Test.Posix.tests
        , testGroup "Utils" Test.Utils.tests
        , testGroup "Hash" Test.Hash.tests
        , testGroup "IO" Test.IO.tests
        , testGroup "Index" Test.Index.tests
        , testGroup "Tree" Test.Tree.tests
        , testGroup "TreeMonad" Test.TreeMonad.tests
        , testGroup "DarcsPristine" Test.DarcsPristine.tests ]

main :: IO ()
main = do zip <- toArchive `fmap` BL.readFile testdata
          removeDirectoryRecursive "_test_playground" `catch` \_ -> return ()
          createDirectory "_test_playground"
          setCurrentDirectory "_test_playground"
          extractFilesFromArchive [] zip
          defaultMain tests

