@@ -3,12 +3,13 @@ module Main where
3
3
import Control.Applicative
4
4
import Control.Monad
5
5
import Data.IORef
6
+ import Data.List
6
7
7
8
import Test.Framework (defaultMain )
8
9
import Test.Framework.Providers.HUnit (hUnitTestToTests )
9
10
import Test.HUnit
10
11
import System.FilePath.Glob (glob )
11
- import System.FilePath (takeDirectory , replaceDirectory )
12
+ import System.FilePath (takeDirectory , replaceDirectory , splitPath )
12
13
13
14
import Language.Egison.Types
14
15
import Language.Egison.Core
@@ -18,23 +19,23 @@ import Language.Egison
18
19
import UnitTest
19
20
20
21
main = do
21
- unitTestCases <- glob " test/**/*.egi"
22
- defaultMain $ hUnitTestToTests $ test $ map runUnitTestCase unitTestCases
23
- sampleTestCases <- glob " sample/*.egi"
24
- defaultMain $ hUnitTestToTests $ test $ map runSampleTestCase sampleTestCases
22
+ unitTestCases <- glob " test/[^answer]**/*.egi"
23
+ sampleTestCases <- glob " test/answer/**/*.egi"
24
+ defaultMain $ hUnitTestToTests $ test $ map runUnitTestCase unitTestCases ++ map runSampleTestCase sampleTestCases
25
25
26
26
runSampleTestCase :: FilePath -> Test
27
27
runSampleTestCase file = TestLabel file . TestCase $ do
28
28
env <- initialEnv
29
29
let directory_path = takeDirectory file
30
- answers <- readFile (replaceDirectory file ( " test/answer/ " ++ directory_path))
30
+ answers <- readFile file
31
31
assertEgisonM (lines answers) $ do
32
- exprs <- loadFile file
32
+ exprs <- loadFile (replaceDirectory file $ concat $ drop 2 $ splitPath directory_path)
33
33
let (bindings, tests) = foldr collectDefsAndTests ([] , [] ) exprs
34
34
env' <- recursiveBind env bindings
35
- forM tests $ evalExprDeep env'
35
+ vals <- forM tests (evalExprDeep env')
36
+ return $ zip tests vals
36
37
where
37
- assertEgisonM :: [String ] -> EgisonM [EgisonValue ] -> Assertion
38
+ assertEgisonM :: [String ] -> EgisonM [( EgisonExpr , EgisonValue ) ] -> Assertion
38
39
assertEgisonM answers m = fromEgisonM m >>= assertString . either show (f answers)
39
40
40
41
collectDefsAndTests (Define name expr) (bindings, tests) =
@@ -43,9 +44,10 @@ runSampleTestCase file = TestLabel file . TestCase $ do
43
44
(bindings, expr : tests)
44
45
collectDefsAndTests _ r = r
45
46
46
- f :: [String ] -> [EgisonValue ] -> String
47
+ f :: [String ] -> [( EgisonExpr , EgisonValue ) ] -> String
47
48
f answers ls = g answers ls 0
48
- g x y i = if (x !! i) == show (y !! i)
49
+ g x y i = let (e, v) = unzip y in
50
+ if (x !! i) == show (v !! i)
49
51
then (if i < (length y - 1 ) then g x y (i + 1 )
50
52
else " " )
51
- else " failed " ++ show i ++ " \n expected: " ++ (x !! i) ++ " \n but found: " ++ show (y !! i)
53
+ else " failed " ++ show (e !! i) ++ " \n expected: " ++ (x !! i) ++ " \n but found: " ++ show (v !! i)
0 commit comments