From e5a007173eda61ed8a2865aba2638eaf4cc783ef Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Mon, 24 Feb 2014 16:54:35 +0400 Subject: Allow to read torrent from spec items --- tests/Config.hs | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'tests/Config.hs') diff --git a/tests/Config.hs b/tests/Config.hs index 3dc254a8..3dea6603 100644 --- a/tests/Config.hs +++ b/tests/Config.hs @@ -13,6 +13,7 @@ module Config , getThisOpts , getRemoteOpts , withRemote + , getTestTorrent ) where import Control.Monad @@ -27,6 +28,9 @@ import System.Environment import System.IO.Unsafe import Test.Hspec +import Data.Torrent + + type ClientName = String @@ -69,16 +73,18 @@ clientOptsParser = ClientOpts ) data EnvOpts = EnvOpts - { testClient :: Maybe ClientName - , remoteOpts :: ClientOpts - , thisOpts :: ClientOpts + { testClient :: Maybe ClientName + , testTorrents :: [FilePath] + , remoteOpts :: ClientOpts + , thisOpts :: ClientOpts } instance Default EnvOpts where def = EnvOpts - { testClient = Nothing - , remoteOpts = defRemoteOpts - , thisOpts = defThisOpts + { testClient = Just "rtorrent" + , testTorrents = ["testfile.torrent"] + , remoteOpts = defRemoteOpts + , thisOpts = defThisOpts } findConflicts :: EnvOpts -> [String] @@ -96,6 +102,7 @@ envOptsParser = EnvOpts <> metavar "CLIENT" <> help "torrent client to run" )) + <*> pure [] <*> clientOptsParser <*> clientOptsParser @@ -120,7 +127,9 @@ getThisOpts = thisOpts <$> getEnvOpts -- | Return 'Nothing' if remote client is not running. getRemoteOpts :: IO (Maybe ClientOpts) -getRemoteOpts = return Nothing +getRemoteOpts = do + EnvOpts {..} <- getEnvOpts + return $ const remoteOpts <$> testClient withRemote :: (ClientOpts -> Expectation) -> Expectation withRemote action = do @@ -129,6 +138,13 @@ withRemote action = do Nothing -> pendingWith "Remote client isn't running" Just opts -> action opts +getTestTorrent :: IO Torrent +getTestTorrent = do + EnvOpts {..} <- getEnvOpts + if L.null testTorrents + then error "getTestTorrent" + else fromFile ("res/" ++ L.head testTorrents) + -- TODO fix EnvOpts parsing -- | Should be used by test suite driver. -- cgit v1.2.3