testAbstractCurry.curry 1.85 KB
Newer Older
Michael Hanus's avatar
Michael Hanus committed
1
2
3
4
5
6
7
8
9
10
11
12
13
------------------------------------------------------------------------------
--- Some tests for AbstractCurry libraries.
---
--- To run all tests automatically by the currytest tool, use the command:
--- "currytest testAbstractCurry"
--- 
--- @author Michael Hanus
--- @version September 2015
------------------------------------------------------------------------------

import AbstractCurry.Files
import AbstractCurry.Pretty
import Directory
14
15
import FlatCurry.Types
import FlatCurry.Files
Michael Hanus's avatar
Michael Hanus committed
16
17
18
19
import Assertion

--- Test for equality of a FlatCurry program with the same program
--- after pretty printing the AbstractCurry program:
Michael Hanus's avatar
Michael Hanus committed
20
readAndTestEqualFcy :: String -> IO Bool
Michael Hanus's avatar
Michael Hanus committed
21
readAndTestEqualFcy mod = do
Michael Hanus's avatar
Michael Hanus committed
22
  prog1 <- readFlatCurryStrict mod
Michael Hanus's avatar
Michael Hanus committed
23
24
25
26
27
28
29
30
  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
Michael Hanus's avatar
Michael Hanus committed
31
  prog2 <- readFlatCurryStrict mod
Michael Hanus's avatar
Michael Hanus committed
32
33
  removeFile modcurry
  renameFile modbak modcurry
Michael Hanus's avatar
Michael Hanus committed
34
35
36
37
38
  let flatequal = prog1 == prog2
  unless flatequal $ do
    putStrLn ("Original flat program:        " ++ show prog1)
    putStrLn ("Pretty printed  flat program: " ++ show prog2)
  return flatequal
Michael Hanus's avatar
Michael Hanus committed
39

Michael Hanus's avatar
Michael Hanus committed
40
41
42
43
44
45
46
-- Strictly read a FlatCurry program in order to avoid race conditions
-- due to copying/moving source files:
readFlatCurryStrict :: String -> IO Prog
readFlatCurryStrict mod = do
  prog <- readFlatCurry mod
  id $!! prog `seq` return prog

Michael Hanus's avatar
Michael Hanus committed
47
48
test1  = assertIO "AbstractCurry.Pretty test for rev"
                  (readAndTestEqualFcy "rev") True
Michael Hanus's avatar
Michael Hanus committed
49
50
51
                  
test2  = assertIO "AbstractCurry.Pretty test for testSetFunctions"
                  (readAndTestEqualFcy "testSetFunctions") True
Michael Hanus's avatar
Michael Hanus committed
52

Michael Hanus's avatar
Michael Hanus committed
53
54
test3  = assertIO "AbstractCurry.Pretty test for testFuncPattern"
                  (readAndTestEqualFcy "testFuncPattern") True