~jojo/Carth

ref: 6071f9511dc62f784cc808db4f3c26a2a02ed780 Carth/test/SystemSpec.hs -rw-r--r-- 818 bytes
6071f951JoJo Formatting 1 year, 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
{-# LANGUAGE LambdaCase #-}

module SystemSpec where

import Data.Data
import Data.Functor
import Control.Monad
import System.Directory
import System.FilePath
import Test.Hspec

import Parse
import Check

spec :: Spec
spec = do
    -- describe "Good programs" $ do
    --     it "produce expected output" $ shouldSatisfy True id
    describe "Bad programs don't typecheck" $ do
        let d = "test/tests/bad"
        fs <- runIO $ listDirectory d <&> filter (isExtensionOf "carth")
        forM_ fs $ \f -> do
            expectedErr <- runIO $ fmap (drop 3 . head . lines) (readFile (d </> f))
            result <- runIO $ parse (d </> f)
            it (dropExtension f) $ shouldSatisfy (fmap typecheck result) $ \case
                Right (Left e) -> show (toConstr e) == expectedErr
                _ -> False