TestAbstractCurry.curry 1.72 KB
Newer Older
Michael Hanus's avatar
Michael Hanus committed
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
------------------------------------------------------------------------------
--- Some tests for AbstractCurry libraries.
---
--- To run all tests automatically by the currycheck tool, use the command:
--- "curry-check testAbstractCurry"
--- 
--- @author Michael Hanus
--- @version September 2017
------------------------------------------------------------------------------

import AbstractCurry.Files
import AbstractCurry.Pretty
import AbstractCurry.Types
import Directory
import Test.EasyCheck

--- Test for equality of an AbstractCurry program with the same program
--- after pretty printing and reading this AbstractCurry program:
readAndTestEqualFcy :: String -> IO Bool
readAndTestEqualFcy mod = do
  prog1 <- readAbstractCurryStrict mod
  let modcurry = mod ++ ".curry"
      modbak   = mod ++ ".BAK"
  renameFile modcurry modbak
  copyFile modbak modcurry
  let modpp = mod ++ ".PP"
  readCurry mod >>= writeFile modpp . showCProg
  removeFile modcurry
  renameFile modpp modcurry
  prog2 <- readAbstractCurryStrict mod
  removeFile modcurry
  renameFile modbak modcurry
  let abstractequal = prog1 == prog2
  unless abstractequal $ do
    putStrLn $ "Original AbstractCurry program:       " ++ show prog1
    putStrLn $ "Pretty printed AbstractCurry program: " ++ show prog2
  return abstractequal

-- Strictly read a AbstractCurry program in order to avoid race conditions
-- due to copying/moving source files:
readAbstractCurryStrict :: String -> IO CurryProg
readAbstractCurryStrict mod = do
  prog <- readCurry mod
  id $!! prog `seq` return prog

testAbstractCurryPretty_rev =
  (readAndTestEqualFcy "Rev") `returns` True
                  
testAbstractCurryPretty_TestAbstractCurry =
  (readAndTestEqualFcy "TestAbstractCurry") `returns` True