Tests.hs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. module LibSucceed.Tests where
  2. import qualified Data.Text as T
  3. import Data.List (isInfixOf)
  4. import Data.Monoid ((<>))
  5. import System.Exit
  6. import System.FilePath
  7. import Test.Tasty ( testGroup, TestTree )
  8. import Test.Tasty.Silver ( printProcResult )
  9. import Test.Tasty.Silver.Advanced ( GDiff(..), GShow(..), goldenTestIO1 )
  10. import Test.Tasty.Silver.Filter ( RegexFilter(RFInclude) )
  11. import Utils
  12. testDir :: FilePath
  13. testDir = "test" </> "LibSucceed"
  14. disabledTests :: [RegexFilter]
  15. disabledTests =
  16. []
  17. notTests :: [String]
  18. notTests =
  19. [ -- These modules are imported by Issue784.agda
  20. "Issue784/"
  21. -- These modules are imported by Issue846.agda
  22. , "Issue846/"
  23. -- These modules are imported by Issue854.agda
  24. , "Issue854/"
  25. -- This module is imported by DeBruijnExSubstSized.agda
  26. , "Termination-Sized-DeBruijnBase"
  27. ]
  28. tests :: IO TestTree
  29. tests = do
  30. let isTest file = not $ any (`isInfixOf` file) notTests
  31. inpFiles <- filter isTest <$> getAgdaFilesInDir Rec testDir
  32. let tests' :: [TestTree]
  33. tests' = map mkLibSucceedTest inpFiles
  34. return $ testGroup "LibSucceed" tests'
  35. rtsOptions :: [String]
  36. rtsOptions = [ "+RTS", "-H1G", "-M1.5G", "-RTS" ]
  37. data TestResult
  38. = TestSuccess
  39. | TestUnexpectedFail ProgramResult
  40. mkLibSucceedTest :: FilePath -- ^ Agda file to test.
  41. -> TestTree
  42. mkLibSucceedTest agdaFile =
  43. goldenTestIO1
  44. testName
  45. readGolden
  46. (printAgdaResult <$> doRun)
  47. (textDiffWithTouch agdaFile)
  48. (return . ShowText)
  49. Nothing
  50. where
  51. testName :: String
  52. testName = asTestName testDir agdaFile
  53. -- We don't really have a golden file. Just use a dummy update
  54. -- function. TODO extend tasty-silver to handle this use case
  55. -- properly
  56. readGolden :: IO (Maybe T.Text)
  57. readGolden = return $ Just $ printAgdaResult TestSuccess
  58. doRun :: IO TestResult
  59. doRun = do
  60. -- ASR (04 January 2016). We don't use the @--ignore-interfaces@
  61. -- option for avoiding type-check the standard library in every
  62. -- test-case. The interface files are deleted in the Makefile.
  63. let agdaArgs :: AgdaArgs
  64. agdaArgs = [ "-v0"
  65. , "-i" ++ testDir
  66. , "-i" ++ "std-lib/src"
  67. , "--no-libraries"
  68. , agdaFile
  69. ] ++ rtsOptions
  70. (res, ret) <- runAgdaWithOptions testName agdaArgs Nothing Nothing
  71. pure $ case ret of
  72. AgdaSuccess{} -> TestSuccess -- TODO: fail if unexpected warnings?
  73. AgdaFailure{} -> TestUnexpectedFail res
  74. printAgdaResult :: TestResult -> T.Text
  75. printAgdaResult TestSuccess = "AGDA_SUCCESS"
  76. printAgdaResult (TestUnexpectedFail p) = "AGDA_UNEXPECTED_FAIL\n\n" <> printProgramResult p