2022-02-15 16:12:53 +03:00
|
|
|
module Scope.Negative (allTests) where
|
|
|
|
|
|
|
|
import Base
|
2022-11-07 16:47:56 +03:00
|
|
|
import Juvix.Compiler.Builtins (iniState)
|
2022-08-03 14:20:40 +03:00
|
|
|
import Juvix.Compiler.Concrete.Translation.FromParsed.Analysis.Scoping.Error
|
|
|
|
import Juvix.Compiler.Pipeline
|
2022-02-15 16:12:53 +03:00
|
|
|
|
|
|
|
type FailMsg = String
|
|
|
|
|
2022-07-05 16:54:01 +03:00
|
|
|
data NegTest a = NegTest
|
2022-04-07 19:10:53 +03:00
|
|
|
{ _name :: String,
|
|
|
|
_relDir :: FilePath,
|
|
|
|
_file :: FilePath,
|
2022-07-05 16:54:01 +03:00
|
|
|
_checkErr :: a -> Maybe FailMsg
|
2022-02-15 16:12:53 +03:00
|
|
|
}
|
|
|
|
|
2022-04-07 19:10:53 +03:00
|
|
|
root :: FilePath
|
|
|
|
root = "tests/negative"
|
|
|
|
|
2022-07-05 16:54:01 +03:00
|
|
|
testDescr :: Typeable a => NegTest a -> TestDescr
|
2022-04-05 20:57:21 +03:00
|
|
|
testDescr NegTest {..} =
|
2022-04-07 19:10:53 +03:00
|
|
|
let tRoot = root </> _relDir
|
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Single $ do
|
2022-05-30 14:40:52 +03:00
|
|
|
let entryPoint = defaultEntryPoint _file
|
2022-11-07 16:47:56 +03:00
|
|
|
res <- runIOEither iniState entryPoint upToAbstract
|
2022-07-08 14:59:45 +03:00
|
|
|
case mapLeft fromJuvixError res of
|
2022-04-07 19:10:53 +03:00
|
|
|
Left (Just err) -> whenJust (_checkErr err) assertFailure
|
2022-05-06 12:48:07 +03:00
|
|
|
Left Nothing -> assertFailure "The scope checker did not find an error."
|
|
|
|
Right _ -> assertFailure "An error ocurred but it was not in the scoper."
|
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"
|
2022-07-05 16:54:01 +03:00
|
|
|
( map (mkTest . testDescr) scoperErrorTests
|
|
|
|
<> map (mkTest . testDescr) filesErrorTests
|
|
|
|
)
|
2022-02-16 22:15:14 +03:00
|
|
|
|
2022-02-16 17:18:08 +03:00
|
|
|
wrongError :: Maybe FailMsg
|
2022-02-15 16:12:53 +03:00
|
|
|
wrongError = Just "Incorrect error"
|
|
|
|
|
2022-07-05 16:54:01 +03:00
|
|
|
scoperErrorTests :: [NegTest ScoperError]
|
|
|
|
scoperErrorTests =
|
2022-04-05 20:57:21 +03:00
|
|
|
[ NegTest
|
|
|
|
"Not in scope"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"NotInScope.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrSymNotInScope {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-05-18 18:10:10 +03:00
|
|
|
NegTest
|
|
|
|
"Qualified not in scope"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"QualSymNotInScope.juvix"
|
2022-05-18 18:10:10 +03:00
|
|
|
$ \case
|
|
|
|
ErrQualSymNotInScope {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-04-05 20:57:21 +03:00
|
|
|
NegTest
|
|
|
|
"Multiple declarations"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"MultipleDeclarations.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrMultipleDeclarations {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Import cycle"
|
|
|
|
"ImportCycle"
|
2022-07-08 14:59:45 +03:00
|
|
|
"A.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrImportCycle {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Binding group conflict (function clause)"
|
|
|
|
"BindGroupConflict"
|
2022-07-08 14:59:45 +03:00
|
|
|
"Clause.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrBindGroup {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Binding group conflict (lambda clause)"
|
|
|
|
"BindGroupConflict"
|
2022-07-08 14:59:45 +03:00
|
|
|
"Lambda.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrBindGroup {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Infix error (expression)"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"InfixError.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrInfixParser {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Infix error (pattern)"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"InfixErrorP.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrInfixPattern {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Duplicate fixity declaration"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"DuplicateFixity.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrDuplicateFixity {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Multiple export conflict"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"MultipleExportConflict.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrMultipleExport {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Module not in scope"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"ModuleNotInScope.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrModuleNotInScope {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Unused operator syntax definition"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"UnusedOperatorDef.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrUnusedOperatorDef {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Ambiguous symbol"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"AmbiguousSymbol.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrAmbiguousSym {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Lacks function clause"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"LacksFunctionClause.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrLacksFunctionClause {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Incorrect top module path"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"WrongModuleName.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrWrongTopModuleName {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Ambiguous export"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"AmbiguousExport.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrMultipleExport {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Ambiguous nested modules"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"AmbiguousModule.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrAmbiguousModuleSym {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Ambiguous nested constructors"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"AmbiguousConstructor.juvix"
|
2022-04-05 20:57:21 +03:00
|
|
|
$ \case
|
|
|
|
ErrAmbiguousSym {} -> Nothing
|
2022-04-28 18:42:15 +03:00
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Wrong location of a compile block"
|
|
|
|
"CompileBlocks"
|
2022-07-08 14:59:45 +03:00
|
|
|
"WrongLocationCompileBlock.juvix"
|
2022-04-28 18:42:15 +03:00
|
|
|
$ \case
|
|
|
|
ErrWrongLocationCompileBlock {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-06-14 09:56:48 +03:00
|
|
|
NegTest
|
|
|
|
"Implicit argument on the left of an application"
|
|
|
|
"."
|
2022-07-08 14:59:45 +03:00
|
|
|
"AppLeftImplicit.juvix"
|
2022-06-14 09:56:48 +03:00
|
|
|
$ \case
|
|
|
|
ErrAppLeftImplicit {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-04-28 18:42:15 +03:00
|
|
|
NegTest
|
|
|
|
"Multiple compile blocks for the same name"
|
|
|
|
"CompileBlocks"
|
2022-07-08 14:59:45 +03:00
|
|
|
"MultipleCompileBlockSameName.juvix"
|
2022-04-28 18:42:15 +03:00
|
|
|
$ \case
|
|
|
|
ErrMultipleCompileBlockSameName {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Multiple rules for a backend inside a compile block"
|
|
|
|
"CompileBlocks"
|
2022-07-08 14:59:45 +03:00
|
|
|
"MultipleCompileRuleSameBackend.juvix"
|
2022-04-28 18:42:15 +03:00
|
|
|
$ \case
|
|
|
|
ErrMultipleCompileRuleSameBackend {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-07-04 17:40:10 +03:00
|
|
|
NegTest
|
|
|
|
"issue 230"
|
|
|
|
"230"
|
2022-07-08 14:59:45 +03:00
|
|
|
"Prod.juvix"
|
2022-07-04 17:40:10 +03:00
|
|
|
$ \case
|
|
|
|
ErrQualSymNotInScope {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-07-20 17:24:03 +03:00
|
|
|
NegTest
|
|
|
|
"Double braces in pattern"
|
|
|
|
"."
|
|
|
|
"NestedPatternBraces.juvix"
|
|
|
|
$ \case
|
|
|
|
ErrDoubleBracesPattern {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-11-03 12:02:22 +03:00
|
|
|
NegTest
|
|
|
|
"As-Pattern aliasing variable"
|
|
|
|
"."
|
|
|
|
"AsPatternAlias.juvix"
|
|
|
|
$ \case
|
|
|
|
ErrAliasBinderPattern {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Nested As-Patterns"
|
|
|
|
"."
|
|
|
|
"NestedAsPatterns.juvix"
|
|
|
|
$ \case
|
|
|
|
ErrDoubleBinderPattern {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-07-20 17:24:03 +03:00
|
|
|
NegTest
|
|
|
|
"Pattern matching an implicit argument on the left of an application"
|
|
|
|
"."
|
|
|
|
"ImplicitPatternLeftApplication.juvix"
|
|
|
|
$ \case
|
|
|
|
ErrImplicitPatternLeftApplication {} -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"Constructor expected on the left of a pattern application"
|
|
|
|
"."
|
|
|
|
"ConstructorExpectedLeftApplication.juvix"
|
|
|
|
$ \case
|
|
|
|
ErrConstructorExpectedLeftApplication {} -> Nothing
|
|
|
|
_ -> wrongError,
|
2022-04-28 18:42:15 +03:00
|
|
|
NegTest
|
|
|
|
"Compile block for a unsupported kind of expression"
|
|
|
|
"CompileBlocks"
|
2022-07-08 14:59:45 +03:00
|
|
|
"WrongKindExpressionCompileBlock.juvix"
|
2022-04-28 18:42:15 +03:00
|
|
|
$ \case
|
|
|
|
ErrWrongKindExpressionCompileBlock {} -> Nothing
|
2022-07-15 11:58:49 +03:00
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"A type parameter name occurs twice when declaring an inductive type"
|
|
|
|
"."
|
|
|
|
"DuplicateInductiveParameterName.juvix"
|
|
|
|
$ \case
|
|
|
|
ErrDuplicateInductiveParameterName {} -> Nothing
|
2022-04-05 20:57:21 +03:00
|
|
|
_ -> wrongError
|
2022-02-16 22:15:14 +03:00
|
|
|
]
|
2022-07-05 16:54:01 +03:00
|
|
|
|
|
|
|
filesErrorTests :: [NegTest FilesError]
|
|
|
|
filesErrorTests =
|
|
|
|
[ NegTest
|
|
|
|
"A module that conflicts with a module in the stdlib"
|
|
|
|
"StdlibConflict"
|
2022-07-08 14:59:45 +03:00
|
|
|
"Stdlib/Data/Bool.juvix"
|
2022-07-05 16:54:01 +03:00
|
|
|
$ \case
|
|
|
|
FilesError {} -> Nothing,
|
|
|
|
NegTest
|
|
|
|
"Importing a module that conflicts with a module in the stdlib"
|
|
|
|
"StdlibConflict"
|
2022-07-08 14:59:45 +03:00
|
|
|
"Input.juvix"
|
2022-07-05 16:54:01 +03:00
|
|
|
$ \case
|
|
|
|
FilesError {} -> Nothing
|
|
|
|
]
|