Skip to content

Commit 8fba8d2

Browse files
mpickeringmergify[bot]
authored andcommitted
Add a test to check that build-tool-depends are used (#10692)
The testcase is not so easy to write because * The bug only surfaces when the build-tool you are depending on is known (ie alex, happy etc) * But then it is tricky to write a test, as we can't depend on the known tools or bundle the source for them. * So we create a fake "alex", which cabal then invokes on a fake ".x" file. This is maybe a bit fragile if the way cabal invokes alex changes in future, but then the test can be modified as well. Ticket #10692 (cherry picked from commit 24f8395)
1 parent f59677b commit 8fba8d2

File tree

8 files changed

+71
-0
lines changed

8 files changed

+71
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages: client
2+
optional-packages: pre-proc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Main where
2+
3+
main = print 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: client
2+
version: 0.1.0.0
3+
synopsis: Checks build-tool-depends are put in PATH
4+
license: BSD3
5+
category: Testing
6+
build-type: Simple
7+
cabal-version: >=1.10
8+
9+
executable hello-world
10+
main-is: Hello.hs
11+
build-depends: base
12+
build-tool-depends: pre-proc:alex
13+
default-language: Haskell2010
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Main where
2+
3+
import System.Environment
4+
import System.IO
5+
6+
-- This is a "fake" version of alex, so it should take the command line arguments
7+
-- as alex.
8+
main :: IO ()
9+
main = do
10+
(_:"-o":target:source:_) <- getArgs
11+
let f '0' = '1'
12+
f c = c
13+
writeFile target . map f =<< readFile source
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: pre-proc
2+
version: 999.999.999
3+
synopsis: Checks build-tool-depends are put in PATH
4+
license: BSD3
5+
category: Testing
6+
build-type: Simple
7+
cabal-version: >=1.10
8+
9+
executable alex
10+
main-is: MyCustomPreprocessor.hs
11+
build-depends: base, directory
12+
default-language: Haskell2010
13+
14+
executable bad-do-not-build-me
15+
main-is: MyMissingPreprocessor.hs
16+
build-depends: base, directory
17+
default-language: Haskell2010
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#! /usr/bin/env bash
2+
3+
echo "I am not the alex you are looking for"
4+
exit 1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# cabal v2-build
2+
Configuration is affected by the following files:
3+
- cabal.project
4+
Resolving dependencies...
5+
Build profile: -w ghc-<GHCVER> -O1
6+
In order, the following will be built:
7+
- pre-proc-999.999.999 (exe:alex) (first run)
8+
- client-0.1.0.0 (exe:hello-world) (first run)
9+
Configuring executable 'alex' for pre-proc-999.999.999...
10+
Preprocessing executable 'alex' for pre-proc-999.999.999...
11+
Building executable 'alex' for pre-proc-999.999.999...
12+
Configuring executable 'hello-world' for client-0.1.0.0...
13+
Preprocessing executable 'hello-world' for client-0.1.0.0...
14+
Building executable 'hello-world' for client-0.1.0.0...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Test.Cabal.Prelude
2+
-- Test build-tool-depends isn't influenced by PATH
3+
main = cabalTest $ do
4+
env <- getTestEnv
5+
addToPath (testTmpDir env </> "scripts/") $ cabal "v2-build" ["client"]

0 commit comments

Comments
 (0)