summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-24 16:54:35 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-24 16:54:35 +0400
commite5a007173eda61ed8a2865aba2638eaf4cc783ef (patch)
treef47ec4db65f6c59060622758678f31a07bf5b0fe
parentc5114183d5e9776b8bcce9809384dabb702d1b23 (diff)
Allow to read torrent from spec items
-rw-r--r--tests/Config.hs30
1 files changed, 23 insertions, 7 deletions
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
13 , getThisOpts 13 , getThisOpts
14 , getRemoteOpts 14 , getRemoteOpts
15 , withRemote 15 , withRemote
16 , getTestTorrent
16 ) where 17 ) where
17 18
18import Control.Monad 19import Control.Monad
@@ -27,6 +28,9 @@ import System.Environment
27import System.IO.Unsafe 28import System.IO.Unsafe
28import Test.Hspec 29import Test.Hspec
29 30
31import Data.Torrent
32
33
30type ClientName = String 34type ClientName = String
31 35
32 36
@@ -69,16 +73,18 @@ clientOptsParser = ClientOpts
69 ) 73 )
70 74
71data EnvOpts = EnvOpts 75data EnvOpts = EnvOpts
72 { testClient :: Maybe ClientName 76 { testClient :: Maybe ClientName
73 , remoteOpts :: ClientOpts 77 , testTorrents :: [FilePath]
74 , thisOpts :: ClientOpts 78 , remoteOpts :: ClientOpts
79 , thisOpts :: ClientOpts
75 } 80 }
76 81
77instance Default EnvOpts where 82instance Default EnvOpts where
78 def = EnvOpts 83 def = EnvOpts
79 { testClient = Nothing 84 { testClient = Just "rtorrent"
80 , remoteOpts = defRemoteOpts 85 , testTorrents = ["testfile.torrent"]
81 , thisOpts = defThisOpts 86 , remoteOpts = defRemoteOpts
87 , thisOpts = defThisOpts
82 } 88 }
83 89
84findConflicts :: EnvOpts -> [String] 90findConflicts :: EnvOpts -> [String]
@@ -96,6 +102,7 @@ envOptsParser = EnvOpts
96 <> metavar "CLIENT" 102 <> metavar "CLIENT"
97 <> help "torrent client to run" 103 <> help "torrent client to run"
98 )) 104 ))
105 <*> pure []
99 <*> clientOptsParser 106 <*> clientOptsParser
100 <*> clientOptsParser 107 <*> clientOptsParser
101 108
@@ -120,7 +127,9 @@ getThisOpts = thisOpts <$> getEnvOpts
120 127
121-- | Return 'Nothing' if remote client is not running. 128-- | Return 'Nothing' if remote client is not running.
122getRemoteOpts :: IO (Maybe ClientOpts) 129getRemoteOpts :: IO (Maybe ClientOpts)
123getRemoteOpts = return Nothing 130getRemoteOpts = do
131 EnvOpts {..} <- getEnvOpts
132 return $ const remoteOpts <$> testClient
124 133
125withRemote :: (ClientOpts -> Expectation) -> Expectation 134withRemote :: (ClientOpts -> Expectation) -> Expectation
126withRemote action = do 135withRemote action = do
@@ -129,6 +138,13 @@ withRemote action = do
129 Nothing -> pendingWith "Remote client isn't running" 138 Nothing -> pendingWith "Remote client isn't running"
130 Just opts -> action opts 139 Just opts -> action opts
131 140
141getTestTorrent :: IO Torrent
142getTestTorrent = do
143 EnvOpts {..} <- getEnvOpts
144 if L.null testTorrents
145 then error "getTestTorrent"
146 else fromFile ("res/" ++ L.head testTorrents)
147
132-- TODO fix EnvOpts parsing 148-- TODO fix EnvOpts parsing
133 149
134-- | Should be used by test suite driver. 150-- | Should be used by test suite driver.