Skip to content

Commit 81fc0b9

Browse files
committed
Add test-cases for extracting build-info, even if a component failed to build
1 parent 5bf69e7 commit 81fc0b9

File tree

10 files changed

+113
-2
lines changed

10 files changed

+113
-2
lines changed

cabal-testsuite/PackageTests/ShowBuildInfo/A/remove-outdated.test.hs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import Test.Cabal.Prelude
33
import Test.Cabal.DecodeShowBuildInfo
44
import Test.Cabal.Plan
55
import Control.Monad.Trans.Reader
6-
import System.Directory
76

87
main = cabalTest $ do
98
runShowBuildInfo ["exe:A"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
cabal-version: 3.0
2+
name: CompileFail
3+
version: 0.1.0.0
4+
build-type: Simple
5+
6+
library
7+
exposed-modules: MyLib
8+
build-depends: base
9+
hs-source-dirs: src
10+
default-language: Haskell2010
11+
12+
library failing
13+
exposed-modules: MyLib2
14+
build-depends: base
15+
hs-source-dirs: src
16+
default-language: Haskell2010
17+
18+
test-suite CompileFail-test
19+
default-language: Haskell2010
20+
type: exitcode-stdio-1.0
21+
hs-source-dirs: test
22+
main-is: Main.hs
23+
build-depends: base, CompileFail
24+
25+
executable CompileFail-exe
26+
default-language: Haskell2010
27+
hs-source-dirs: app
28+
main-is: Main.hs
29+
build-depends: base, failing
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main where
2+
3+
import MyLib2 (someFunc2)
4+
5+
main :: IO ()
6+
main = someFunc2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: ./
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# cabal build
2+
Resolving dependencies...
3+
Build profile: -w ghc-<GHCVER> -O1
4+
In order, the following will be built:
5+
- CompileFail-0.1.0.0 (lib) (first run)
6+
- CompileFail-0.1.0.0 (test:CompileFail-test) (first run)
7+
Configuring library for CompileFail-0.1.0.0..
8+
Preprocessing library for CompileFail-0.1.0.0..
9+
Building library for CompileFail-0.1.0.0..
10+
Configuring test suite 'CompileFail-test' for CompileFail-0.1.0.0..
11+
Preprocessing test suite 'CompileFail-test' for CompileFail-0.1.0.0..
12+
Building test suite 'CompileFail-test' for CompileFail-0.1.0.0..
13+
# cabal build
14+
Build profile: -w ghc-<GHCVER> -O1
15+
In order, the following will be built:
16+
- CompileFail-0.1.0.0 (lib:failing) (first run)
17+
- CompileFail-0.1.0.0 (exe:CompileFail-exe) (first run)
18+
Configuring library 'failing' for CompileFail-0.1.0.0..
19+
Preprocessing library 'failing' for CompileFail-0.1.0.0..
20+
Building library 'failing' for CompileFail-0.1.0.0..
21+
cabal: Failed to build CompileFail-0.1.0.0 because it depends on CompileFail-0.1.0.0 which itself failed to build.
22+
Failed to build CompileFail-0.1.0.0-inplace-failing.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
import Test.Cabal.Prelude
3+
import Test.Cabal.DecodeShowBuildInfo
4+
import Test.Cabal.Plan
5+
import Control.Monad.Trans.Reader
6+
7+
main = cabalTest $ do
8+
-- Leaf component fails to compile, should still dump
9+
-- build info for both components.
10+
fails $ runShowBuildInfo ["test:CompileFail-test"]
11+
withPlan $ do
12+
-- Lib has to be built, thus info is dumped
13+
assertComponent "CompileFail" mainLib
14+
defCompAssertion
15+
{ modules = ["MyLib"]
16+
, sourceDirs = ["src"]
17+
}
18+
19+
-- Build Info is still dumped, although compilation failed
20+
assertComponent "CompileFail" (test "CompileFail-test")
21+
defCompAssertion
22+
{ sourceFiles = ["Main.hs"]
23+
, sourceDirs = ["test"]
24+
}
25+
26+
fails $ runShowBuildInfo ["exe:CompileFail-exe"]
27+
withPlan $ do
28+
-- Internal Lib has to be built, thus info is dumped
29+
assertComponent "CompileFail" (lib "failing")
30+
defCompAssertion
31+
{ modules = ["MyLib2"]
32+
, sourceDirs = ["src"]
33+
}
34+
-- However, since the internal lib failed to compile
35+
-- we can not have executable build information.
36+
Just plan <- fmap testPlan ask
37+
let fp = buildInfoFile plan "CompileFail" (exe "CompileFail-exe")
38+
shouldNotExist fp
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module MyLib (someFunc) where
2+
3+
someFunc :: IO ()
4+
someFunc = putStrLn "someFunc"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module MyLib2 (someFunc2) where
2+
3+
someFunc2 :: IO ()
4+
-- Intentional typo, should fail to compile
5+
someFunc2 = putStrn "someFunc"
6+
-- ^^------- missing 'L'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module Main (main) where
2+
3+
main :: IO ()
4+
-- Intentional typo, should fail to compile
5+
main = putStrn "Test suite not yet implemented."
6+
-- ^^------- missing 'L'

cabal-testsuite/src/Test/Cabal/DecodeShowBuildInfo.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ defCompAssertion = ComponentAssertion
111111
, modules = []
112112
, sourceFiles = []
113113
, sourceDirs = []
114-
, compType = mempty
114+
, compType = ""
115115
}
116116

117117
-- | Assert common build information, such as compiler location, compiler version

0 commit comments

Comments
 (0)