diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Main.hs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/tests/Main.hs b/tests/Main.hs index 204d1656..96c599b4 100644 --- a/tests/Main.hs +++ b/tests/Main.hs | |||
@@ -4,10 +4,11 @@ import Control.Exception | |||
4 | import Control.Monad | 4 | import Control.Monad |
5 | import Data.Functor | 5 | import Data.Functor |
6 | import Data.Maybe | 6 | import Data.Maybe |
7 | import System.Directory | ||
7 | import System.Exit | 8 | import System.Exit |
8 | import System.Environment | 9 | import System.Environment |
10 | import System.FilePath | ||
9 | import System.Process | 11 | import System.Process |
10 | import System.Directory | ||
11 | import Text.Printf | 12 | import Text.Printf |
12 | import Test.Hspec | 13 | import Test.Hspec |
13 | 14 | ||
@@ -25,26 +26,37 @@ torrents = | |||
25 | , "testfile.torrent" | 26 | , "testfile.torrent" |
26 | ] | 27 | ] |
27 | 28 | ||
29 | rtorrentSessionDir :: String | ||
30 | rtorrentSessionDir = "rtorrent-sessiondir" | ||
31 | |||
32 | sessionName :: String -- screen session name | ||
33 | sessionName = "bittorrent-testsuite" | ||
34 | |||
28 | clients :: [Descr] | 35 | clients :: [Descr] |
29 | clients = | 36 | clients = |
30 | [ ("rtorrent" | 37 | [ ("rtorrent" |
31 | , \ ClientOpts {..} tfile -> printf | 38 | , \ ClientOpts {..} tfile -> printf |
32 | "rtorrent -p %i-%i -O dht=on -O dht_port=%i -O session=rtorrent-sessiondir %s" | 39 | "rtorrent -p %i-%i -O dht=on -O dht_port=%i -O session=%s %s" |
33 | (fromEnum peerPort) (fromEnum peerPort) (fromEnum nodePort) tfile | 40 | (fromEnum peerPort) (fromEnum peerPort) (fromEnum nodePort) |
41 | rtorrentSessionDir tfile | ||
34 | ) | 42 | ) |
35 | ] | 43 | ] |
36 | 44 | ||
37 | sessionName :: String -- screen session name | ||
38 | sessionName = "bittorrent-testsuite" | ||
39 | |||
40 | setupEnv :: EnvOpts -> IO (Maybe ()) | 45 | setupEnv :: EnvOpts -> IO (Maybe ()) |
41 | setupEnv EnvOpts {..} | 46 | setupEnv EnvOpts {..} |
42 | | Just client <- testClient | 47 | | Just client <- testClient |
43 | , Just mkCmd <- lookup client clients = do | 48 | , Just mkCmd <- lookup client clients = do |
49 | _ <- printf "Setting up %s\n" client | ||
50 | |||
51 | let torrentPath = "testfile.torrent" | ||
52 | let tmpDir = "res" | ||
44 | let runner = printf "screen -dm -S %s %s" sessionName | 53 | let runner = printf "screen -dm -S %s %s" sessionName |
45 | (mkCmd remoteOpts "testfile.torrent") | 54 | (mkCmd remoteOpts torrentPath) |
46 | dir <- getCurrentDirectory | 55 | |
47 | _ <- createProcess (shell runner) { cwd = Just (dir ++ "/res") } | 56 | wd <- getCurrentDirectory |
57 | createDirectoryIfMissing True (wd </> tmpDir </> rtorrentSessionDir) | ||
58 | _ <- createProcess (shell runner) { cwd = Just (wd </> tmpDir) } | ||
59 | |||
48 | return (Just ()) | 60 | return (Just ()) |
49 | 61 | ||
50 | | Just client <- testClient = do | 62 | | Just client <- testClient = do |