From 1f008bcc12f883936b2e2caa57dee997e7e70bc3 Mon Sep 17 00:00:00 2001 From: James Crayne Date: Wed, 27 Apr 2016 18:20:20 -0400 Subject: refactoring --- testkiki/testkiki.hs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'testkiki') diff --git a/testkiki/testkiki.hs b/testkiki/testkiki.hs index 2a19889..64c1a6a 100644 --- a/testkiki/testkiki.hs +++ b/testkiki/testkiki.hs @@ -27,10 +27,14 @@ import Data.IORef import Crypto.Hash.SHA1 (hash) import System.IO.Unsafe (unsafePerformIO) import ProcessUtils +import Data.Bool #if !MIN_VERSION_base(4,7,0) setEnv k v = System.Posix.Env.setEnv k v True unsetEnv = System.Posix.Env.unsetEnv +bool :: a -> a -> Bool -> a +bool f _ False = f +bool _ t True = t #endif data TestKikiSettings = TKS @@ -257,9 +261,8 @@ doTests tkConfig = hspec $ do -- **** cokiki tests ***** describe "cokiki ssh-client" $ do - it "modifies system ssh configuration to respect /var/cache/kiki/ssh_known_hosts." $ do - bDidInit3 <-readIORef didInit3 - if not bDidInit3 then skipThisTest else do + it "modifies system ssh configuration to respect /var/cache/kiki/ssh_known_hosts." $ + onlyIf didInit3 $ do let cfg' = appendpaths tkConfig "3" home = chroot cfg' "root" gnuhome = home ".gnupg" @@ -290,9 +293,8 @@ doTests tkConfig = hspec $ do (lost,gained,bChanged,(subStr0,subStr),compare mtime mtime0) `shouldBe` (1,1,True,(False,True),GT) describe "cokiki ssh-server" $ do - it "modifies system ssh config to use /var/cache/kiki/ssh_host_rsa_key." $ do - bDidInit3 <-readIORef didInit3 - if not bDidInit3 then skipThisTest else do + it "modifies system ssh config to use /var/cache/kiki/ssh_host_rsa_key." $ + onlyIf didInit3 $ do let cfg' = appendpaths tkConfig "3" home = chroot cfg' "root" gnuhome = home ".gnupg" @@ -304,8 +306,7 @@ doTests tkConfig = hspec $ do describe "cokiki strongswan" $ do it "modifies /etc/ipsec.conf to include settings from /var/cache/kiki/ipsec.conf." $ do - bDidInit3 <-readIORef didInit3 - if not bDidInit3 then skipThisTest else do + onlyIf didInit3 $ do let cfg' = appendpaths tkConfig "3" home = chroot cfg' "root" gnuhome = home ".gnupg" @@ -316,6 +317,10 @@ doTests tkConfig = hspec $ do pending where + onlyIf ref action = do + b <- readIORef ref + when b action + skipThisTest = pendingWith "SKIPPING due to prior failure." freshStdErrHandle tmpdir = openTempFile tmpdir "err.tmp" @@ -325,7 +330,7 @@ doTests tkConfig = hspec $ do len <- (+1) . length <$> getCurrentDirectory -- dump stderr here bracket (freshStdErrHandle dir) - (\(_,h) -> hClose h) $ \(errfile,myStdErr) -> do + (\(_,h) -> hClose h) $ \(errfile,myStdErr) -> flip catch (\(e::SomeException) -> (do b <- hIsOpen myStdErr x <- if b then do -- cgit v1.2.3