diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/A/remove-outdated.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/A/remove-outdated.test.hs index f6bcdf047fe..f2f0c4302fc 100644 --- a/cabal-testsuite/PackageTests/ShowBuildInfo/A/remove-outdated.test.hs +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/A/remove-outdated.test.hs @@ -3,7 +3,6 @@ import Test.Cabal.Prelude import Test.Cabal.DecodeShowBuildInfo import Test.Cabal.Plan import Control.Monad.Trans.Reader -import System.Directory main = cabalTest $ do runShowBuildInfo ["exe:A"] diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/CompileFail.cabal b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/CompileFail.cabal new file mode 100644 index 00000000000..0fd965fb985 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/CompileFail.cabal @@ -0,0 +1,29 @@ +cabal-version: 3.0 +name: CompileFail +version: 0.1.0.0 +build-type: Simple + +library + exposed-modules: MyLib + build-depends: base + hs-source-dirs: src + default-language: Haskell2010 + +library failing + exposed-modules: MyLib2 + build-depends: base + hs-source-dirs: src + default-language: Haskell2010 + +test-suite CompileFail-test + default-language: Haskell2010 + type: exitcode-stdio-1.0 + hs-source-dirs: test + main-is: Main.hs + build-depends: base, CompileFail + +executable CompileFail-exe + default-language: Haskell2010 + hs-source-dirs: app + main-is: Main.hs + build-depends: base, failing diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/app/Main.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/app/Main.hs new file mode 100644 index 00000000000..1a3121450a4 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/app/Main.hs @@ -0,0 +1,6 @@ +module Main where + +import MyLib2 (someFunc2) + +main :: IO () +main = someFunc2 diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/cabal.project b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/cabal.project new file mode 100644 index 00000000000..6f920794c80 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/cabal.project @@ -0,0 +1 @@ +packages: ./ diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/compile-fail.out b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/compile-fail.out new file mode 100644 index 00000000000..3c13bf35ea9 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/compile-fail.out @@ -0,0 +1,22 @@ +# cabal build +Resolving dependencies... +Build profile: -w ghc- -O1 +In order, the following will be built: + - CompileFail-0.1.0.0 (lib) (first run) + - CompileFail-0.1.0.0 (test:CompileFail-test) (first run) +Configuring library for CompileFail-0.1.0.0.. +Preprocessing library for CompileFail-0.1.0.0.. +Building library for CompileFail-0.1.0.0.. +Configuring test suite 'CompileFail-test' for CompileFail-0.1.0.0.. +Preprocessing test suite 'CompileFail-test' for CompileFail-0.1.0.0.. +Building test suite 'CompileFail-test' for CompileFail-0.1.0.0.. +# cabal build +Build profile: -w ghc- -O1 +In order, the following will be built: + - CompileFail-0.1.0.0 (lib:failing) (first run) + - CompileFail-0.1.0.0 (exe:CompileFail-exe) (first run) +Configuring library 'failing' for CompileFail-0.1.0.0.. +Preprocessing library 'failing' for CompileFail-0.1.0.0.. +Building library 'failing' for CompileFail-0.1.0.0.. +cabal: Failed to build CompileFail-0.1.0.0 because it depends on CompileFail-0.1.0.0 which itself failed to build. +Failed to build CompileFail-0.1.0.0-inplace-failing. diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/compile-fail.test.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/compile-fail.test.hs new file mode 100644 index 00000000000..fc1fba234d5 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/compile-fail.test.hs @@ -0,0 +1,38 @@ +{-# LANGUAGE OverloadedStrings #-} +import Test.Cabal.Prelude +import Test.Cabal.DecodeShowBuildInfo +import Test.Cabal.Plan +import Control.Monad.Trans.Reader + +main = cabalTest $ do + -- Leaf component fails to compile, should still dump + -- build info for both components. + fails $ runShowBuildInfo ["test:CompileFail-test"] + withPlan $ do + -- Lib has to be built, thus info is dumped + assertComponent "CompileFail" mainLib + defCompAssertion + { modules = ["MyLib"] + , sourceDirs = ["src"] + } + + -- Build Info is still dumped, although compilation failed + assertComponent "CompileFail" (test "CompileFail-test") + defCompAssertion + { sourceFiles = ["Main.hs"] + , sourceDirs = ["test"] + } + + fails $ runShowBuildInfo ["exe:CompileFail-exe"] + withPlan $ do + -- Internal Lib has to be built, thus info is dumped + assertComponent "CompileFail" (lib "failing") + defCompAssertion + { modules = ["MyLib2"] + , sourceDirs = ["src"] + } + -- However, since the internal lib failed to compile + -- we can not have executable build information. + Just plan <- fmap testPlan ask + let fp = buildInfoFile plan "CompileFail" (exe "CompileFail-exe") + shouldNotExist fp diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/src/MyLib.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/src/MyLib.hs new file mode 100644 index 00000000000..e657c4403f6 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/src/MyLib.hs @@ -0,0 +1,4 @@ +module MyLib (someFunc) where + +someFunc :: IO () +someFunc = putStrLn "someFunc" diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/src/MyLib2.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/src/MyLib2.hs new file mode 100644 index 00000000000..9b620c62fcd --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/src/MyLib2.hs @@ -0,0 +1,6 @@ +module MyLib2 (someFunc2) where + +someFunc2 :: IO () +-- Intentional typo, should fail to compile +someFunc2 = putStrn "someFunc" +-- ^^------- missing 'L' diff --git a/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/test/Main.hs b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/test/Main.hs new file mode 100644 index 00000000000..bae4112fa97 --- /dev/null +++ b/cabal-testsuite/PackageTests/ShowBuildInfo/CompileFail/test/Main.hs @@ -0,0 +1,6 @@ +module Main (main) where + +main :: IO () +-- Intentional typo, should fail to compile +main = putStrn "Test suite not yet implemented." +-- ^^------- missing 'L' diff --git a/cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs b/cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs index 47fbcc83795..02c1cb7e733 100644 --- a/cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs +++ b/cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs @@ -111,7 +111,7 @@ defCompAssertion = ComponentAssertion , modules = [] , sourceFiles = [] , sourceDirs = [] - , compType = mempty + , compType = "" } -- | Assert common build information, such as compiler location, compiler version