Skip to content

Commit 0d66ebf

Browse files
committed
new: test 1 undefined variable
1 parent 2a7fa19 commit 0d66ebf

File tree

6 files changed

+66
-29
lines changed

6 files changed

+66
-29
lines changed

lambda-buffers-compiler/lambda-buffers-compiler.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ test-suite tests
162162

163163
other-modules:
164164
Test.KindCheck
165+
Test.KindCheck.Errors
165166
Test.LambdaBuffers.Compiler
166167
Test.LambdaBuffers.Compiler.Gen
167168
Test.TypeClassCheck

lambda-buffers-compiler/test/Test/KindCheck.hs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,10 @@ import LambdaBuffers.Compiler.KindCheck.Variable (
1111
Variable (LocalRef),
1212
)
1313

14+
import Test.KindCheck.Errors (testGKindCheckErrors)
1415
import Test.QuickCheck (
15-
Arbitrary (arbitrary, shrink),
16-
Property,
16+
Arbitrary (arbitrary),
1717
forAll,
18-
forAllShrink,
1918
(===),
2019
)
2120
import Test.Tasty (TestTree, testGroup)
@@ -31,7 +30,7 @@ import Test.Utils.Constructors (_CompilerInput)
3130
-- Top Level tests
3231

3332
test :: TestTree
34-
test = testGroup "Compiler tests" [testCheck, testFolds, testRefl]
33+
test = testGroup "Compiler tests" [testCheck, testFolds, testGKindCheckErrors]
3534

3635
--------------------------------------------------------------------------------
3736
-- Module tests
@@ -139,10 +138,3 @@ testSumFold3 =
139138
-- | TyDef to Kind Canonical representation - sums not folded - therefore we get constructor granularity. Might use in a different implementation for more granular errors.
140139
lVar :: Text -> Type
141140
lVar = Var . LocalRef
142-
143-
-- Property Tests
144-
testRefl :: TestTree
145-
testRefl = testProperty "Refl" reflTerm
146-
where
147-
reflTerm :: Property
148-
reflTerm = forAllShrink (arbitrary @Int) shrink (\a -> a == a)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
module Test.Utils.CompilerInput (compilerInput'incoherent, compilerInput'maybe) where
1+
module Test.Utils.CompilerInput (compilerInput'incoherent, compilerInput'maybe, compilerInput'undefinedVariable) where
22

33
import LambdaBuffers.Compiler.ProtoCompat qualified as P
44
import Test.Utils.Constructors (_CompilerInput)
5-
import Test.Utils.Module (module'incoherent, module'maybe)
5+
import Test.Utils.Module (module'incoherent, module'maybe, module'undefinedVar)
66

77
-- | Compiler Input containing 1 module with 1 definition - Maybe.
88
compilerInput'maybe :: P.CompilerInput
@@ -11,3 +11,7 @@ compilerInput'maybe = _CompilerInput [module'maybe]
1111
-- | Contains 2 definitions - 1 wrong one.
1212
compilerInput'incoherent :: P.CompilerInput
1313
compilerInput'incoherent = _CompilerInput [module'maybe, module'incoherent]
14+
15+
-- | Contains 1 undefined variable.
16+
compilerInput'undefinedVariable :: P.CompilerInput
17+
compilerInput'undefinedVariable = _CompilerInput [module'undefinedVar]

lambda-buffers-compiler/test/Test/Utils/Constructors.hs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module Test.Utils.Constructors (
2-
_tyName,
3-
_varName,
4-
_tyVar,
2+
_TyName,
3+
_VarName,
4+
_TyVar,
5+
_TyVar',
56
_TyVarI,
67
_TupleI,
78
_Constructor,
@@ -16,12 +17,15 @@ module Test.Utils.Constructors (
1617
_CompilerInput,
1718
_ModuleName,
1819
_ModuleNamePart,
20+
_TyVarI',
21+
_SourceInfo,
1922
) where
2023

2124
import Control.Lens ((^.))
2225
import Data.Map qualified as Map
2326
import Data.Text (Text)
2427
import LambdaBuffers.Compiler.ProtoCompat qualified as P
28+
import LambdaBuffers.Compiler.ProtoCompat.Types (SourceInfo)
2529

2630
_CompilerInput :: [P.Module] -> P.CompilerInput
2731
_CompilerInput ms =
@@ -50,17 +54,31 @@ _ModuleName ps =
5054
_ModuleNamePart :: Text -> P.ModuleNamePart
5155
_ModuleNamePart n = P.ModuleNamePart n P.defSourceInfo
5256

53-
_tyName :: Text -> P.TyName
54-
_tyName x = P.TyName x P.defSourceInfo
57+
_TyName :: Text -> P.TyName
58+
_TyName x = P.TyName x P.defSourceInfo
5559

56-
_varName :: Text -> P.VarName
57-
_varName x = P.VarName {P.name = x, P.sourceInfo = P.defSourceInfo}
60+
_VarName :: Text -> P.VarName
61+
_VarName x = P.VarName {P.name = x, P.sourceInfo = P.defSourceInfo}
5862

59-
_tyVar :: Text -> P.TyVar
60-
_tyVar x = P.TyVar {P.varName = _varName x, P.sourceInfo = P.defSourceInfo}
63+
_TyVar :: Text -> P.TyVar
64+
_TyVar x = P.TyVar {P.varName = _VarName x, P.sourceInfo = P.defSourceInfo}
65+
66+
-- | TyVar with Source Info - for error precision testing.
67+
_TyVar' :: Text -> SourceInfo -> P.TyVar
68+
_TyVar' x s = P.TyVar {P.varName = _VarName x, P.sourceInfo = s}
6169

6270
_TyVarI :: Text -> P.Ty
63-
_TyVarI x = P.TyVarI $ P.TyVar {P.varName = _varName x, P.sourceInfo = P.defSourceInfo}
71+
_TyVarI x = P.TyVarI $ P.TyVar {P.varName = _VarName x, P.sourceInfo = P.defSourceInfo}
72+
73+
-- | TyVar with Source Info - for error precision testing.
74+
_TyVarI' :: Text -> SourceInfo -> P.Ty
75+
_TyVarI' x s = P.TyVarI $ P.TyVar {P.varName = _VarName x, P.sourceInfo = s}
76+
77+
_SourceInfo :: Int -> Int -> P.SourceInfo
78+
_SourceInfo x y = P.SourceInfo {P.file = "DefaultFile", P.posFrom = _SourcePosition x, P.posTo = _SourcePosition y}
79+
80+
_SourcePosition :: Int -> P.SourcePosition
81+
_SourcePosition x = P.SourcePosition x (x + 1)
6482

6583
_TupleI :: [P.Ty] -> P.Product
6684
_TupleI x =

lambda-buffers-compiler/test/Test/Utils/Module.hs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
module Test.Utils.Module (module'maybe, module'incoherent) where
1+
module Test.Utils.Module (module'maybe, module'incoherent, module'undefinedVar) where
22

33
import LambdaBuffers.Compiler.ProtoCompat qualified as P
44
import Test.Utils.Constructors (_Module, _ModuleName)
5-
import Test.Utils.TyDef (tyDef'incoherent, tyDef'maybe)
5+
import Test.Utils.TyDef (tyDef'incoherent, tyDef'maybe, tyDef'undefinedVar)
66

77
-- _Module mn tds cds ins =
88

@@ -20,3 +20,11 @@ module'maybe = _Module (_ModuleName ["Module"]) [tyDef'maybe] mempty mempty
2020
-}
2121
module'incoherent :: P.Module
2222
module'incoherent = _Module (_ModuleName ["Module"]) [tyDef'maybe, tyDef'incoherent] mempty mempty
23+
24+
{- | 1 Module containing
25+
Foo = Bar b
26+
27+
Should fail as b is undefined.
28+
-}
29+
module'undefinedVar :: P.Module
30+
module'undefinedVar = _Module (_ModuleName ["Module"]) [tyDef'undefinedVar] mempty mempty
Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
module Test.Utils.TyDef (tyDef'maybe, tyDef'incoherent) where
1+
module Test.Utils.TyDef (tyDef'maybe, tyDef'incoherent, tyDef'undefinedVar, tyDef'undefinedVar'var) where
22

33
import LambdaBuffers.Compiler.ProtoCompat qualified as P
4+
import LambdaBuffers.Compiler.ProtoCompat.Types (Ty (TyVarI))
45
import Test.Utils.Constructors (
6+
_SourceInfo,
57
_TupleI,
68
_TyAbs,
79
_TyDef,
10+
_TyName,
811
_TyRefILocal,
12+
_TyVar',
913
_TyVarI,
1014
_Type,
11-
_tyName,
1215
)
1316

1417
-- | Maybe tyDef.
1518
tyDef'maybe :: P.TyDef
1619
tyDef'maybe =
1720
_TyDef
18-
(_tyName "Maybe")
21+
(_TyName "Maybe")
1922
( _TyAbs
2023
[("a", _Type)]
2124
[ ("Nothing", _TupleI [])
@@ -27,10 +30,21 @@ tyDef'maybe =
2730
tyDef'incoherent :: P.TyDef
2831
tyDef'incoherent =
2932
_TyDef
30-
(_tyName "B")
33+
(_TyName "B")
3134
( _TyAbs
3235
[("a", _Type)]
3336
[ ("Nothing", _TupleI [])
3437
, ("B", _TupleI [_TyRefILocal "Maybe"])
3538
]
3639
)
40+
41+
-- | Foo = Bar b
42+
tyDef'undefinedVar :: P.TyDef
43+
tyDef'undefinedVar =
44+
_TyDef
45+
(_TyName "Foo")
46+
(_TyAbs [] [("Bar", _TupleI [TyVarI tyDef'undefinedVar'var])])
47+
48+
-- | The undefined var in tyDef'undefinedVar - exported to see if the test identifies it correctly.
49+
tyDef'undefinedVar'var :: P.TyVar
50+
tyDef'undefinedVar'var = _TyVar' "b" (_SourceInfo 1 2)

0 commit comments

Comments
 (0)