summaryrefslogtreecommitdiff
path: root/tests/Main.hs
blob: 63281cf3b8391c25478be0b7d8212828fc527142 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Main where

import Spec
import System.Exit
import System.Environment
import System.Process
import System.Directory
import Control.Exception
import Data.List
import Data.Maybe
import Data.Functor

clients :: [(String, String)]
clients = [
 ("rtorrent","rtorrent -p 51234-51234 -O dht=on -O dht_port=6881 -O session=rtorrent-sessiondir testfile.torrent") ]

main :: IO ()
main = do
  args <- getArgs
  let cmd' = do
        cl <- listToMaybe $ reverse
                   $ map (tail . dropWhile (/='='))
                   $ filter (isPrefixOf "--bittorrent-client=") args
        cmd <- (++) "screen -dm -S bittorrent-testsuite " <$> lookup cl clients
        return cmd
  case cmd' of
    Just cmd -> do _ <- system "screen -S bittorrent-testsuite -X quit"
                   dir <- getCurrentDirectory
                   _ <- createProcess (shell cmd) { cwd = Just (dir ++ "/res") }
                   return ()
    Nothing -> return ()

  let args' = (filter (not . isPrefixOf "--bittorrent-client=") args)
  code <- catch (withArgs args' hspecMain >> return ExitSuccess) return

  _ <- system "screen -S bittorrent-testsuite -X quit"
  exitWith code >> return ()