From cfaabed84e1a621d216561f9917e48a21a76bdee Mon Sep 17 00:00:00 2001 From: Matvey Aksenov Date: Wed, 1 Apr 2015 23:31:59 +0000 Subject: [PATCH] Fire up a separate LDAP server instance for each example --- Guardfile | 2 +- ldap-client.cabal | 2 +- test/Main.hs | 24 ------------------------ test/Spec.hs | 2 +- test/SpecHelper.hs | 16 +++++++++++++++- 5 files changed, 18 insertions(+), 28 deletions(-) delete mode 100644 test/Main.hs diff --git a/Guardfile b/Guardfile index 6478764..decfdcb 100644 --- a/Guardfile +++ b/Guardfile @@ -1,4 +1,4 @@ -guard :haskell, all_on_start: true, all_on_pass: true, cmd: "cabal exec -- ghci -isrc -itest -DTEST test/Main.hs -ignore-dot-ghci -optP-include -optPdist/build/autogen/cabal_macros.h" do +guard :haskell, all_on_start: true, all_on_pass: true, cmd: "cabal exec -- ghci -isrc -itest -DTEST test/Spec.hs -ignore-dot-ghci -optP-include -optPdist/build/autogen/cabal_macros.h" do watch(%r{test/.+Spec\.l?hs$}) watch(%r{src/.+\.l?hs$}) watch(%r{.+\.cabal$}) diff --git a/ldap-client.cabal b/ldap-client.cabal index ebc80a7..12f642f 100644 --- a/ldap-client.cabal +++ b/ldap-client.cabal @@ -50,7 +50,7 @@ test-suite spec hs-source-dirs: test main-is: - Main.hs + Spec.hs other-modules: Ldap.ClientSpec build-depends: diff --git a/test/Main.hs b/test/Main.hs deleted file mode 100644 index da49d6d..0000000 --- a/test/Main.hs +++ /dev/null @@ -1,24 +0,0 @@ -module Main (main) where - -import Control.Concurrent (threadDelay) -import Control.Exception (bracket) -import System.IO (hGetLine) -import System.Process (runInteractiveProcess, terminateProcess, waitForProcess) -import Test.Hspec - -import qualified Spec -import SpecHelper (port) - - -main :: IO () -main = - bracket (do (_, out, _, h) <- runInteractiveProcess "./test/ldap.js" [] Nothing - (Just [ ("PORT", show port) - , ("SSL_CERT", "./ssl/cert.pem") - , ("SSL_KEY", "./ssl/key.pem") - ]) - hGetLine out - return h) - (\h -> do terminateProcess h - waitForProcess h) - (\_ -> hspec Spec.spec) diff --git a/test/Spec.hs b/test/Spec.hs index 5416ef6..a824f8c 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -1 +1 @@ -{-# OPTIONS_GHC -F -pgmF hspec-discover -optF --module-name=Spec #-} +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} diff --git a/test/SpecHelper.hs b/test/SpecHelper.hs index dd81638..4d151e2 100644 --- a/test/SpecHelper.hs +++ b/test/SpecHelper.hs @@ -21,11 +21,25 @@ module SpecHelper , oddish ) where +import Control.Exception (bracket) +import System.IO (hGetLine) +import System.Process (runInteractiveProcess, terminateProcess, waitForProcess) + import Ldap.Client as Ldap locally :: (Ldap -> IO a) -> IO (Either LdapError a) -locally = Ldap.with localhost port +locally f = + bracket (do (_, out, _, h) <- runInteractiveProcess "./test/ldap.js" [] Nothing + (Just [ ("PORT", show port) + , ("SSL_CERT", "./ssl/cert.pem") + , ("SSL_KEY", "./ssl/key.pem") + ]) + hGetLine out + return h) + (\h -> do terminateProcess h + waitForProcess h) + (\_ -> Ldap.with localhost port f) localhost :: Host localhost = Insecure "localhost"