diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-28 23:25:56 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-02-28 23:25:56 +0400 |
commit | 669627fd2c8f997511f9c97ecfb5999be78c8806 (patch) | |
tree | 9829fb864badfdfc8bbbb7c1cfbc30ed78118473 | |
parent | 7b0b4f657d1f35d62b125184da146df55a4af130 (diff) |
Spec: clean up after tests
-rw-r--r-- | tests/Main.hs | 21 |
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" | |||
32 | sessionName :: String -- screen session name | 32 | sessionName :: String -- screen session name |
33 | sessionName = "bittorrent-testsuite" | 33 | sessionName = "bittorrent-testsuite" |
34 | 34 | ||
35 | tmpDir :: FilePath | ||
36 | tmpDir = "res" | ||
37 | |||
35 | clients :: [Descr] | 38 | clients :: [Descr] |
36 | clients = | 39 | clients = |
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 | ||
70 | terminateEnv :: IO () | 72 | terminateEnv :: IO () |
71 | terminateEnv = do | 73 | terminateEnv = 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 | ||
85 | withEnv :: EnvOpts -> IO a -> IO a | ||
86 | withEnv opts action = bracket (setupEnv opts) terminate (const action) | ||
87 | where | ||
88 | terminate running = do | ||
89 | when (isJust running) $ do | ||
90 | terminateEnv | ||
91 | |||
81 | main :: IO () | 92 | main :: IO () |
82 | main = do | 93 | main = 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 | ||