1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-15 01:52:11 +03:00
juvix/test/Scope/Negative.hs

334 lines
9.4 KiB
Haskell
Raw Normal View History

2022-02-15 16:12:53 +03:00
module Scope.Negative (allTests) where
import Base
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping.Error
2022-02-15 16:12:53 +03:00
type FailMsg = String
data NegTest a = NegTest
2022-04-07 19:10:53 +03:00
{ _name :: String,
2022-12-20 15:05:40 +03:00
_relDir :: Path Rel Dir,
_file :: Path Rel File,
_checkErr :: a -> Maybe FailMsg
2022-02-15 16:12:53 +03:00
}
2022-12-20 15:05:40 +03:00
root :: Path Abs Dir
root = relToProject $(mkRelDir "tests/negative")
2022-04-07 19:10:53 +03:00
testDescr :: (Typeable a) => NegTest a -> TestDescr
2022-04-05 20:57:21 +03:00
testDescr NegTest {..} =
2022-12-20 15:05:40 +03:00
let tRoot = root <//> _relDir
file' = tRoot <//> _file
2022-04-07 19:10:53 +03:00
in TestDescr
{ _testName = _name,
_testRoot = tRoot,
_testAssertion = Single $ do
entryPoint <- defaultEntryPointCwdIO file'
res <- runIOEither entryPoint upToInternal
case mapLeft fromJuvixError res of
2022-04-07 19:10:53 +03:00
Left (Just err) -> whenJust (_checkErr err) assertFailure
2022-12-20 15:05:40 +03:00
Left Nothing -> assertFailure "An error ocurred but it was not in the scoper."
Right {} -> assertFailure "The scope checker did not find an error."
2022-04-07 19:10:53 +03:00
}
2022-02-15 16:12:53 +03:00
2022-02-18 15:01:42 +03:00
allTests :: TestTree
2022-04-05 20:57:21 +03:00
allTests =
testGroup
"Scope negative tests"
( map (mkTest . testDescr) scoperErrorTests
)
2022-02-16 22:15:14 +03:00
wrongError :: Maybe FailMsg
2022-02-15 16:12:53 +03:00
wrongError = Just "Incorrect error"
scoperErrorTests :: [NegTest ScoperError]
scoperErrorTests =
2022-04-05 20:57:21 +03:00
[ NegTest
"Not in scope"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "NotInScope.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrSymNotInScope {} -> Nothing
_ -> wrongError,
NegTest
"Qualified not in scope"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "QualSymNotInScope.juvix")
$ \case
ErrQualSymNotInScope {} -> Nothing
_ -> wrongError,
2022-04-05 20:57:21 +03:00
NegTest
"Multiple declarations"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "MultipleDeclarations.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrMultipleDeclarations {} -> Nothing
_ -> wrongError,
NegTest
"Import cycle"
2022-12-20 15:05:40 +03:00
$(mkRelDir "ImportCycle")
$(mkRelFile "A.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrImportCycle {} -> Nothing
_ -> wrongError,
NegTest
"Binding group conflict (function clause)"
2022-12-20 15:05:40 +03:00
$(mkRelDir "BindGroupConflict")
$(mkRelFile "Clause.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrMultipleDeclarations {} -> Nothing
2022-04-05 20:57:21 +03:00
_ -> wrongError,
NegTest
"Binding group conflict (lambda clause)"
2022-12-20 15:05:40 +03:00
$(mkRelDir "BindGroupConflict")
$(mkRelFile "Lambda.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrMultipleDeclarations {} -> Nothing
2022-04-05 20:57:21 +03:00
_ -> wrongError,
NegTest
"Infix error (expression)"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "InfixError.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrInfixParser {} -> Nothing
_ -> wrongError,
NegTest
"Infix error (pattern)"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "InfixErrorP.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrInfixPattern {} -> Nothing
_ -> wrongError,
NegTest
"Duplicate operator declaration"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "DuplicateOperator.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrDuplicateOperator {} -> Nothing
2022-04-05 20:57:21 +03:00
_ -> wrongError,
NegTest
"Multiple export conflict"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "MultipleExportConflict.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrMultipleExport {} -> Nothing
_ -> wrongError,
NegTest
"Module not in scope"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "ModuleNotInScope.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrModuleNotInScope {} -> Nothing
_ -> wrongError,
NegTest
"Unused operator syntax definition"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "UnusedOperatorDef.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrUnusedOperatorDef {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous symbol"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "AmbiguousSymbol.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrAmbiguousSym {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous export"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "AmbiguousExport.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrMultipleExport {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous nested modules"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "AmbiguousModule.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrAmbiguousModuleSym {} -> Nothing
_ -> wrongError,
NegTest
"Ambiguous nested constructors"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "AmbiguousConstructor.juvix")
2022-04-05 20:57:21 +03:00
$ \case
ErrAmbiguousSym {} -> Nothing
_ -> wrongError,
NegTest
"Implicit argument on the left of an application"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "AppLeftImplicit.juvix")
$ \case
ErrAppLeftImplicit {} -> Nothing
_ -> wrongError,
NegTest
"issue 230"
2022-12-20 15:05:40 +03:00
$(mkRelDir "230")
$(mkRelFile "Prod.juvix")
$ \case
ErrQualSymNotInScope {} -> Nothing
_ -> wrongError,
NegTest
"Double braces in pattern"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "NestedPatternBraces.juvix")
$ \case
ErrDoubleBracesPattern {} -> Nothing
_ -> wrongError,
NegTest
"As-Pattern aliasing variable"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "AsPatternAlias.juvix")
$ \case
ErrAliasBinderPattern {} -> Nothing
_ -> wrongError,
NegTest
"Nested As-Patterns"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "NestedAsPatterns.juvix")
$ \case
ErrDoubleBinderPattern {} -> Nothing
_ -> wrongError,
NegTest
"Pattern matching an implicit argument on the left of an application"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "ImplicitPatternLeftApplication.juvix")
$ \case
ErrImplicitPatternLeftApplication {} -> Nothing
_ -> wrongError,
NegTest
"Constructor expected on the left of a pattern application"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "ConstructorExpectedLeftApplication.juvix")
$ \case
ErrConstructorExpectedLeftApplication {} -> Nothing
_ -> wrongError,
NegTest
"A type parameter name occurs twice when declaring an inductive type"
2022-12-20 15:05:40 +03:00
$(mkRelDir ".")
$(mkRelFile "DuplicateInductiveParameterName.juvix")
$ \case
ErrNameSignature (ErrDuplicateName DuplicateName {}) -> Nothing
_ -> wrongError,
NegTest
"Using symbol that is not exported"
$(mkRelDir "UsingHiding")
$(mkRelFile "Main.juvix")
$ \case
ErrModuleDoesNotExportSymbol {} -> Nothing
_ -> wrongError,
NegTest
"Wrong number of interator initializers"
$(mkRelDir ".")
$(mkRelFile "Iterators1.juvix")
$ \case
ErrIteratorInitializer {} -> Nothing
_ -> wrongError,
NegTest
"Wrong number of interator ranges"
$(mkRelDir ".")
$(mkRelFile "Iterators2.juvix")
$ \case
ErrIteratorRange {} -> Nothing
_ -> wrongError,
NegTest
"Undeclared iterator"
$(mkRelDir ".")
$(mkRelFile "Iterators3.juvix")
$ \case
ErrIteratorUndefined {} -> Nothing
_ -> wrongError,
NegTest
"Duplicate iterator declaration"
$(mkRelDir ".")
$(mkRelFile "Iterators4.juvix")
$ \case
ErrDuplicateIterator {} -> Nothing
_ -> wrongError,
NegTest
"Unused iterator declaration"
$(mkRelDir ".")
$(mkRelFile "Iterators5.juvix")
$ \case
ErrUnusedIteratorDef {} -> Nothing
_ -> wrongError,
NegTest
"Repeated name in named application"
$(mkRelDir ".")
$(mkRelFile "DuplicateArgument.juvix")
$ \case
ErrNamedArgumentsError (ErrDuplicateArgument {}) -> Nothing
_ -> wrongError,
NegTest
"Unexpected named argument after wildcard"
$(mkRelDir ".")
$(mkRelFile "UnexpectedArgumentWildcard.juvix")
$ \case
ErrNamedArgumentsError ErrUnexpectedArguments {} -> Nothing
_ -> wrongError,
NegTest
"Unexpected named argument"
$(mkRelDir ".")
$(mkRelFile "UnexpectedArgument.juvix")
$ \case
ErrNamedArgumentsError ErrUnexpectedArguments {} -> Nothing
_ -> wrongError,
NegTest
"Missing argument"
$(mkRelDir ".")
$(mkRelFile "MissingArgument.juvix")
$ \case
ErrNamedArgumentsError ErrMissingArguments {} -> Nothing
_ -> wrongError,
NegTest
"Repeated name in name signature"
$(mkRelDir ".")
$(mkRelFile "RepeatedNameSignature.juvix")
$ \case
ErrNameSignature ErrDuplicateName {} -> Nothing
_ -> wrongError,
NegTest
"No named arguments"
$(mkRelDir ".")
$(mkRelFile "NoNamedArguments.juvix")
$ \case
ErrNoNameSignature NoNameSignature {} -> Nothing
_ -> wrongError,
NegTest
"Not a record"
$(mkRelDir ".")
$(mkRelFile "NotARecord.juvix")
$ \case
ErrNotARecord NotARecord {} -> Nothing
_ -> wrongError,
NegTest
"Unexpected field in record update"
$(mkRelDir ".")
$(mkRelFile "UnexpectedFieldUpdate.juvix")
$ \case
ErrUnexpectedField UnexpectedField {} -> Nothing
_ -> wrongError,
NegTest
"Repeated field in record pattern"
$(mkRelDir ".")
$(mkRelFile "RepeatedFieldPattern.juvix")
$ \case
ErrRepeatedField RepeatedField {} -> Nothing
_ -> wrongError,
NegTest
"Incomparable precedences"
$(mkRelDir ".")
$(mkRelFile "IncomparablePrecedences.juvix")
$ \case
ErrIncomparablePrecedences {} -> Nothing
_ -> wrongError,
NegTest
"Alias cycle"
$(mkRelDir ".")
$(mkRelFile "AliasCycle.juvix")
$ \case
ErrAliasCycle {} -> Nothing
2022-04-05 20:57:21 +03:00
_ -> wrongError
2022-02-16 22:15:14 +03:00
]