summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kiki.cabal15
-rw-r--r--testkiki/testkiki.hs58
2 files changed, 73 insertions, 0 deletions
diff --git a/kiki.cabal b/kiki.cabal
index b64b87e..b074fb9 100644
--- a/kiki.cabal
+++ b/kiki.cabal
@@ -60,6 +60,7 @@ Executable hosts
60 60
61Executable cokiki 61Executable cokiki
62 Main-is: cokiki.hs 62 Main-is: cokiki.hs
63 Buildable: False
63 Build-Depends: base >=4.6.0.0, 64 Build-Depends: base >=4.6.0.0,
64 bytestring, 65 bytestring,
65 unix, 66 unix,
@@ -121,3 +122,17 @@ library
121 else 122 else
122 Build-Depends: cryptonite, x509 >=1.6, memory, hourglass 123 Build-Depends: cryptonite, x509 >=1.6, memory, hourglass
123 c-sources: lib/dotlock.c 124 c-sources: lib/dotlock.c
125
126Test-suite testkiki
127 type: exitcode-stdio-1.0
128 Main-is: testkiki.hs
129 hs-source-dirs: testkiki
130 Build-depends: base
131 , Cabal
132 , hspec
133 , process
134 , directory
135 , unix
136 , filepath
137 , kiki
138
diff --git a/testkiki/testkiki.hs b/testkiki/testkiki.hs
new file mode 100644
index 0000000..d84f92d
--- /dev/null
+++ b/testkiki/testkiki.hs
@@ -0,0 +1,58 @@
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE DoAndIfThenElse #-}
3import System.Environment
4--import System.Posix.Env.ByteString (getEnv)
5import System.Posix.Files
6import Test.Hspec
7import System.Process
8import Control.Exception
9import System.Directory
10import System.FilePath
11import System.Exit
12import System.IO
13--import System.Posix.ByteString.FilePath
14import Control.Applicative
15import Control.Monad
16
17
18data TestKikiSettings = TKS
19 { chroot :: FilePath
20 }
21 deriving (Show,Eq)
22
23kiki = "./dist/build/kiki/kiki"
24
25main = do
26 args <- getArgs
27 cwd <- getCurrentDirectory
28 let chomp x = takeWhile (/='\n') x
29 date <- maybe (return "")
30 (\x -> chomp <$> readProcess x ["+%Y-%m-%d-%H%M"] "") =<< findExecutable "date"
31
32 let tdir = cwd </> "TESTS" </> date
33
34 {- -- Remove old TESTS, clean up directory
35 - -- XXX: get this to work right with HSpec
36 -
37 - when (args == ["clean"]) $ do
38 - removeDirectoryRecursive (cwd </> "TESTS")
39 -}
40
41 existsAlready <- or <$> (sequence $ map ($ tdir) [doesDirectoryExist,doesFileExist])
42
43 if existsAlready then do
44 hPutStrLn stderr ("Path " ++ show tdir ++ " already exists, remove or change working folder to run clean tests.")
45 exitFailure
46 else do
47 let chrootdir = cwd </> tdir </> "chroot"
48 createDirectoryIfMissing True chrootdir
49 let config = TKS { chroot = chrootdir }
50 print config
51 putStrLn "==="
52 doTests config
53
54doTests :: TestKikiSettings -> IO ()
55doTests tkConfig = hspec $ do
56 describe "TODO: error" $
57 it "throws an exception" $
58 evaluate (error "TODO:testsuite") `shouldThrow` anyException