From edba4fda3293fd7ce513662df51dbcfef0e38efc Mon Sep 17 00:00:00 2001 From: krangelov Date: Thu, 12 Aug 2021 14:23:20 +0200 Subject: [PATCH] test that we can handle loading failures --- src/runtime/haskell/tests/basic.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/runtime/haskell/tests/basic.hs b/src/runtime/haskell/tests/basic.hs index 0279099f3..72ca046f2 100644 --- a/src/runtime/haskell/tests/basic.hs +++ b/src/runtime/haskell/tests/basic.hs @@ -1,10 +1,14 @@ +import Control.Exception import Test.HUnit import PGF2 main = do + x <- testLoadFailure "non-existing.pgf" + x <- testLoadFailure "tests/basic.gf" gr <- readPGF "tests/basic.pgf" runTestTTAndExit $ - TestList [TestCase (assertEqual "abstract names" "basic" (abstractName gr)) + TestList [TestCase (assertBool "loading failure handled" x) + ,TestCase (assertEqual "abstract names" "basic" (abstractName gr)) ,TestCase (assertEqual "abstract categories" ["Float","Int","N","P","S","String"] (categories gr)) ,TestCase (assertEqual "abstract functions" ["c","ind","s","z"] (functions gr)) ,TestCase (assertEqual "abstract functions by cat 1" ["s","z"] (functionsByCat gr "N")) @@ -23,5 +27,11 @@ main = do ,TestCase (assertEqual "function is constructor 4" False (functionIsConstructor gr "ind")) ] +testLoadFailure fpath = do + res <- try (readPGF fpath) + case res :: Either SomeException PGF of + Left _ -> return True + Right _ -> return False + eqJust (Just x) (Just y) = x == y eqJust _ _ = False