1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-24 16:12:14 +03:00

[test] show diff when ast's are different

This commit is contained in:
Jan Mas Rovira 2022-03-24 17:04:22 +01:00
parent 6ce6489617
commit eedf468261
2 changed files with 19 additions and 4 deletions

View File

@ -50,6 +50,8 @@ dependencies:
# when running the tests. Is there a better solution? # when running the tests. Is there a better solution?
- tasty - tasty
- tasty-hunit - tasty-hunit
- Diff == 0.4.*
- pretty-show == 1.10.*
# TODO organize this # TODO organize this
ghc-options: ghc-options:
@ -89,7 +91,6 @@ executables:
dependencies: dependencies:
- minijuvix - minijuvix
- optparse-applicative == 0.17.* - optparse-applicative == 0.17.*
- pretty-show == 1.10.*
verbatim: verbatim:
default-language: GHC2021 default-language: GHC2021

View File

@ -5,6 +5,9 @@ import qualified MiniJuvix.Syntax.Concrete.Scoped.Pretty.Text as M
import qualified MiniJuvix.Syntax.Concrete.Scoped.Scoper as M import qualified MiniJuvix.Syntax.Concrete.Scoped.Scoper as M
import MiniJuvix.Syntax.Concrete.Scoped.Utils import MiniJuvix.Syntax.Concrete.Scoped.Utils
import qualified Data.HashMap.Strict as HashMap import qualified Data.HashMap.Strict as HashMap
import Text.Show.Pretty hiding (Html)
import Data.Algorithm.Diff
import Data.Algorithm.DiffOutput
data PosTest = PosTest { data PosTest = PosTest {
@ -44,11 +47,22 @@ testDescr PosTest {..} = TestDescr {
s' <- fromRightIO' printErrorAnsi $ return (M.scopeCheck1Pure fs "." p') s' <- fromRightIO' printErrorAnsi $ return (M.scopeCheck1Pure fs "." p')
step "Checks" step "Checks"
assertBool "check: scope . parse . pretty . scope . parse = scope . parse" (s == s') assertEqDiff "check: scope . parse . pretty . scope . parse = scope . parse" s s'
assertBool "check: parse . pretty . scope . parse = parse" (p == p') assertEqDiff "check: parse . pretty . scope . parse = parse" p p'
assertBool "check: parse . pretty . parse = parse" (p == parsedPretty') assertEqDiff "check: parse . pretty . parse = parse" p parsedPretty'
} }
assertEqDiff :: (Eq a, Show a) => String -> a -> a -> Assertion
assertEqDiff msg a b
| a == b = return ()
| otherwise = do
putStrLn (pack $ ppDiff (getGroupedDiff pa pb))
putStrLn "End diff"
fail msg
where
pa = lines $ ppShow a
pb = lines $ ppShow b
allTests :: TestTree allTests :: TestTree
allTests = testGroup "Scope positive tests" allTests = testGroup "Scope positive tests"
(map (mkTest . testDescr) tests) (map (mkTest . testDescr) tests)