-
Notifications
You must be signed in to change notification settings - Fork 510
Expand file tree
/
Copy pathSpec.hs
More file actions
113 lines (101 loc) · 4.3 KB
/
Copy pathSpec.hs
File metadata and controls
113 lines (101 loc) · 4.3 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-}
{-# OPTIONS_GHC -fplugin Plinth.Plugin #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:context-level=0 #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:datatypes=BuiltinCasing #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-cse-iterations=0 #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-simplifier-iterations-pir=0 #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:max-simplifier-iterations-uplc=0 #-}
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:profile-all #-}
{-# HLINT ignore "Eta reduce" #-}
{-# HLINT ignore "Redundant if" #-}
module CallTrace.Spec where
import PlutusTx
import PlutusTx.Prelude
import Test.Tasty.Extras (TestNested, testNested, testNestedGhc)
import UntypedPlutusCore.Evaluation.Machine.Cek qualified as Cek
import CallTrace.Lib
import CallTrace.OtherModule
tests :: TestNested
tests =
testNested "CallTrace"
. pure
$ testNestedGhc
[ goldenEvalCekTraceWithEmitter
Cek.logWithCallTraceEmitter
"nestedLinearFuncions"
$$(compile [||nestedLinear False||])
, goldenEvalCekTraceWithEmitter
Cek.logWithCallTraceEmitter
"nestedLinearFuncions-error"
$$(compile [||nestedLinear True||])
, goldenEvalCekTraceWithEmitter
Cek.logWithCallTraceEmitter
"successfullEvaluationYieldsNoTraceLog"
$$(compile [||functionFromOtherModule False||])
, goldenEvalCekTraceWithEmitter
Cek.logWithCallTraceEmitter
"funcionFromOtherModule-error"
$$(compile [||functionFromOtherModule True||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func01" $$(compile [||func 1||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func02" $$(compile [||func 2||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func03" $$(compile [||func 3||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func04" $$(compile [||func 4||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func05" $$(compile [||func 5||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func06" $$(compile [||func 6||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func07" $$(compile [||func 7||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func08" $$(compile [||func 8||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func09" $$(compile [||func 9||])
, goldenEvalCekTraceWithEmitter Cek.logWithCallTraceEmitter "func42" $$(compile [||func 42||])
]
bob :: Integer -> Integer -> ()
bob x y =
if x == y
then ()
else error ()
nestedLinear, nestedLinear2, nestedLinear3, nestedLinear4 :: Bool -> BuiltinString
nestedLinear x = nestedLinear2 x
nestedLinear2 x = nestedLinear3 x
nestedLinear3 x = nestedLinear4 x
nestedLinear4 True = error ()
nestedLinear4 False = error ()
-- These NOINLINE pragmas ensure that the functions appear in the call trace.
{-# NOINLINE nestedLinear #-}
{-# NOINLINE nestedLinear2 #-}
{-# NOINLINE nestedLinear3 #-}
{-# NOINLINE nestedLinear4 #-}
func :: Integer -> BuiltinString
func 1 = trace "func 1" (\_thunk -> nestedLinear True) ()
func 2 = nestedLinear2 True
func 3 = trace "func 3" $ functionFromOtherModule True
func 4 = myClassFunc @Integer 4
func 5 = trace "func 5" $ myClassFunc @Integer 5
func 6 = myClassFunc ()
func 7 = trace "func 7" $ myClassFuncInOtherModule @Integer 7
func 8 = myClassFuncInOtherModule @Integer 8
func 9 = trace "func 9" $ myClassFuncInOtherModule ()
func n =
if bob 42 n == ()
then error ()
else ""
-- See Note [NOINLINE in some tests]
{-# NOINLINE func #-}
functionFromOtherModule :: Bool -> BuiltinString
functionFromOtherModule x = wraps $ not $ not x
class MyClass a where
myClassFunc :: a -> BuiltinString
instance MyClass Integer where
myClassFunc 5 = trace "myClassFunc 5" $ functionFromOtherModule True
myClassFunc _ = error ()
-- See Note [NOINLINE in some tests]
{-# NOINLINE myClassFunc #-}
instance MyClass () where
myClassFunc () = error ()