Commit b2c587b2 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Proper error messages for per-package compiler path config errors

Plus test case.
parent 010c71bf
......@@ -819,12 +819,34 @@ readSourcePackage _verbosity _ =
data BadPerPackageCompilerPaths
= BadPerPackageCompilerPaths [(PackageName, String)]
#if MIN_VERSION_base(4,8,0)
deriving (Show, Typeable)
#else
deriving (Typeable)
instance Show BadPerPackageCompilerPaths where
show = renderBadPerPackageCompilerPaths
#endif
instance Exception BadPerPackageCompilerPaths
--TODO: [required eventually] displayException for nice rendering
instance Exception BadPerPackageCompilerPaths where
#if MIN_VERSION_base(4,8,0)
displayException = renderBadPerPackageCompilerPaths
#endif
--TODO: [nice to have] custom exception subclass for Doc rendering, colour etc
renderBadPerPackageCompilerPaths :: BadPerPackageCompilerPaths -> String
renderBadPerPackageCompilerPaths
(BadPerPackageCompilerPaths ((pkgname, progname) : _)) =
"The path to the compiler program (or programs used by the compiler) "
++ "cannot be specified on a per-package basis in the cabal.project file "
++ "(ie setting the '" ++ progname ++ "-location' for package '"
++ display pkgname ++ "'). All packages have to use the same compiler, so "
++ "specify the path in a global 'program-locations' section."
--TODO: [nice to have] better format control so we can pretty-print the
-- offending part of the project file. Currently the line wrapping breaks any
-- formatting.
renderBadPerPackageCompilerPaths _ = error "renderBadPerPackageCompilerPaths"
-- | The project configuration is not allowed to specify program locations for
-- programs used by the compiler as these have to be the same for each set of
-- packages.
......
......@@ -174,6 +174,7 @@ Extra-Source-Files:
tests/IntegrationTests2/exception/configure/a.cabal
tests/IntegrationTests2/exception/no-pkg/empty.in
tests/IntegrationTests2/exception/no-pkg2/cabal.project
tests/IntegrationTests2/exception/bad-config/cabal.project
tests/IntegrationTests2/regression/3324/cabal.project
tests/IntegrationTests2/regression/3324/p/P.hs
tests/IntegrationTests2/regression/3324/p/p.cabal
......
......@@ -48,6 +48,7 @@ tests config =
[ testGroup "Exceptions during discovey and planning" $
[ testCase "no package" (testExceptionInFindingPackage config)
, testCase "no package2" (testExceptionInFindingPackage2 config)
, testCase "proj conf1" (testExceptionInProjectConfig config)
]
, testGroup "Exceptions during building (local inplace)" $
[ testCase "configure" (testExceptionInConfigureStep config)
......@@ -90,6 +91,19 @@ testExceptionInFindingPackage2 config = do
testdir = "exception/no-pkg2"
testExceptionInProjectConfig :: ProjectConfig -> Assertion
testExceptionInProjectConfig config = do
BadPerPackageCompilerPaths ps <- expectException "BadPerPackageCompilerPaths" $
void $ planProject testdir config
case ps of
[(PackageName "foo","ghc")] -> return ()
_ -> assertFailure $ "expected (PackageName \"foo\",\"ghc\"), got "
++ show ps
cleanProject testdir
where
testdir = "exception/bad-config"
testExceptionInConfigureStep :: ProjectConfig -> Assertion
testExceptionInConfigureStep config = do
(plan, res) <- executePlan =<< planProject testdir config
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment