summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-02-28 23:25:56 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-02-28 23:25:56 +0400
commit669627fd2c8f997511f9c97ecfb5999be78c8806 (patch)
tree9829fb864badfdfc8bbbb7c1cfbc30ed78118473
parent7b0b4f657d1f35d62b125184da146df55a4af130 (diff)
Spec: clean up after tests
-rw-r--r--tests/Main.hs21
1 files changed, 15 insertions, 6 deletions
diff --git a/tests/Main.hs b/tests/Main.hs
index 96c599b4..2f249945 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -32,6 +32,9 @@ rtorrentSessionDir = "rtorrent-sessiondir"
32sessionName :: String -- screen session name 32sessionName :: String -- screen session name
33sessionName = "bittorrent-testsuite" 33sessionName = "bittorrent-testsuite"
34 34
35tmpDir :: FilePath
36tmpDir = "res"
37
35clients :: [Descr] 38clients :: [Descr]
36clients = 39clients =
37 [ ("rtorrent" 40 [ ("rtorrent"
@@ -49,7 +52,6 @@ setupEnv EnvOpts {..}
49 _ <- printf "Setting up %s\n" client 52 _ <- printf "Setting up %s\n" client
50 53
51 let torrentPath = "testfile.torrent" 54 let torrentPath = "testfile.torrent"
52 let tmpDir = "res"
53 let runner = printf "screen -dm -S %s %s" sessionName 55 let runner = printf "screen -dm -S %s %s" sessionName
54 (mkCmd remoteOpts torrentPath) 56 (mkCmd remoteOpts torrentPath)
55 57
@@ -69,6 +71,8 @@ setupEnv EnvOpts {..}
69 71
70terminateEnv :: IO () 72terminateEnv :: IO ()
71terminateEnv = do 73terminateEnv = do
74 wd <- getCurrentDirectory
75 removeDirectoryRecursive (wd </> tmpDir </> rtorrentSessionDir)
72 _ <- printf "closing screen session: %s\n" sessionName 76 _ <- printf "closing screen session: %s\n" sessionName
73 _ <- system (printf "screen -S %s -X quit" sessionName) 77 _ <- system (printf "screen -S %s -X quit" sessionName)
74 return () 78 return ()
@@ -78,11 +82,16 @@ runTestSuite args = do
78 _ <- printf "running hspec test suite with args: %s\n" (show args) 82 _ <- printf "running hspec test suite with args: %s\n" (show args)
79 catch (withArgs args (hspec spec) >> return ExitSuccess) return 83 catch (withArgs args (hspec spec) >> return ExitSuccess) return
80 84
85withEnv :: EnvOpts -> IO a -> IO a
86withEnv opts action = bracket (setupEnv opts) terminate (const action)
87 where
88 terminate running = do
89 when (isJust running) $ do
90 terminateEnv
91
81main :: IO () 92main :: IO ()
82main = do 93main = do
83 (envOpts, suiteArgs) <- getOpts 94 (envOpts, suiteArgs) <- getOpts
84 running <- setupEnv envOpts 95 withEnv envOpts $ do
85 code <- runTestSuite suiteArgs 96 code <- runTestSuite suiteArgs
86 when (isJust running) $ do 97 exitWith code
87 terminateEnv
88 exitWith code