@@ -18,9 +18,9 @@ import Data.Text (Text)
18
18
import Data.Word
19
19
import System.Directory
20
20
import System.Environment
21
+ import System.FilePath
21
22
import System.IO
22
23
import Test.HUnit
23
- import Paths_configurator
24
24
25
25
main :: IO ()
26
26
main = runTestTT tests >> return ()
@@ -35,17 +35,17 @@ tests = TestList
35
35
, " reload" ~: reloadTest
36
36
]
37
37
38
- withLoad :: [ Worth FilePath ] -> (Config -> IO () ) -> IO ()
39
- withLoad files t = do
40
- mb <- try $ load files
38
+ withLoad :: FilePath -> (Config -> IO () ) -> IO ()
39
+ withLoad name t = do
40
+ mb <- try $ load (testFile name)
41
41
case mb of
42
42
Left (err :: SomeException ) -> assertFailure (show err)
43
43
Right cfg -> t cfg
44
44
45
- withReload :: [ Worth FilePath ] -> ([Maybe FilePath ] -> Config -> IO () ) -> IO ()
46
- withReload files t = do
45
+ withReload :: FilePath -> ([Maybe FilePath ] -> Config -> IO () ) -> IO ()
46
+ withReload name t = do
47
47
tmp <- getTemporaryDirectory
48
- temps <- forM files $ \ f -> do
48
+ temps <- forM (testFile name) $ \ f -> do
49
49
exists <- doesFileExist (worth f)
50
50
if exists
51
51
then do
@@ -61,6 +61,9 @@ withReload files t = do
61
61
Left (err :: SomeException ) -> assertFailure (show err)
62
62
Right (cfg, tid) -> t (map snd temps) cfg >> killThread tid
63
63
64
+ testFile :: FilePath -> [Worth FilePath ]
65
+ testFile name = [Required $ " tests" </> " resources" </> name]
66
+
64
67
takeMVarTimeout :: Int -> MVar a -> IO (Maybe a )
65
68
takeMVarTimeout millis v = do
66
69
w <- newEmptyMVar
@@ -74,9 +77,8 @@ takeMVarTimeout millis v = do
74
77
takeMVar w
75
78
76
79
loadTest :: Assertion
77
- loadTest = do
78
- fp <- getDataFileName " tests/resources/pathological.cfg"
79
- withLoad [Required fp] $ \ cfg -> do
80
+ loadTest =
81
+ withLoad " pathological.cfg" $ \ cfg -> do
80
82
aa <- lookup cfg " aa"
81
83
assertEqual " int property" aa $ (Just 1 :: Maybe Int )
82
84
@@ -102,9 +104,8 @@ loadTest = do
102
104
assertEqual " deep bool" deep (Just False :: Maybe Bool )
103
105
104
106
typesTest :: Assertion
105
- typesTest = do
106
- fp <- getDataFileName " tests/resources/pathological.cfg"
107
- withLoad [Required fp] $ \ cfg -> do
107
+ typesTest =
108
+ withLoad " pathological.cfg" $ \ cfg -> do
108
109
asInt <- lookup cfg " aa" :: IO (Maybe Int )
109
110
assertEqual " int" asInt (Just 1 )
110
111
@@ -154,15 +155,14 @@ typesTest = do
154
155
assertEqual " char" asChar (Just ' x' )
155
156
156
157
interpTest :: Assertion
157
- interpTest = do
158
- fp <- getDataFileName " tests/resources/pathological.cfg"
159
- withLoad [Required fp] $ \ cfg -> do
158
+ interpTest =
159
+ withLoad " pathological.cfg" $ \ cfg -> do
160
160
home <- getEnv " HOME"
161
161
cfgHome <- lookup cfg " ba"
162
162
assertEqual " home interp" (Just home) cfgHome
163
163
164
164
scopedInterpTest :: Assertion
165
- scopedInterpTest = withLoad [ Required " resources/ interp.cfg" ] $ \ cfg -> do
165
+ scopedInterpTest = withLoad " interp.cfg" $ \ cfg -> do
166
166
home <- getEnv " HOME"
167
167
168
168
lookup cfg " myprogram.exec"
@@ -175,18 +175,16 @@ scopedInterpTest = withLoad [Required "resources/interp.cfg"] $ \ cfg -> do
175
175
>>= assertEqual " nested scope" (Just $ home++ " /top/layer1/layer2" )
176
176
177
177
importTest :: Assertion
178
- importTest = do
179
- fp <- getDataFileName " tests/resources/import.cfg"
180
- withLoad [Required fp] $ \ cfg -> do
178
+ importTest =
179
+ withLoad " import.cfg" $ \ cfg -> do
181
180
aa <- lookup cfg " x.aa" :: IO (Maybe Int )
182
181
assertEqual " simple" aa (Just 1 )
183
182
acx <- lookup cfg " x.ac.x" :: IO (Maybe Int )
184
183
assertEqual " nested" acx (Just 1 )
185
184
186
185
reloadTest :: Assertion
187
- reloadTest = do
188
- fp <- getDataFileName " tests/resources/pathological.cfg"
189
- withReload [Required fp] $ \ [Just f] cfg -> do
186
+ reloadTest =
187
+ withReload " pathological.cfg" $ \ [Just f] cfg -> do
190
188
aa <- lookup cfg " aa"
191
189
assertEqual " simple property 1" aa $ Just (1 :: Int )
192
190
0 commit comments