Skip to content

Commit 77bc27e

Browse files
sheaftdammers
authored andcommitted
Add regression test for #11411
1 parent e8c9de7 commit 77bc27e

8 files changed

Lines changed: 86 additions & 0 deletions

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cabal-version: 3.0
2+
name: T11411
3+
version: 0.1.0.0
4+
build-type: Simple
5+
6+
library
7+
hs-source-dirs:
8+
src
9+
exposed-modules:
10+
Hello
11+
build-depends:
12+
base
13+
build-tool-depends:
14+
alex:alex
15+
default-language:
16+
Haskell2010
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Test.Cabal.Prelude
2+
3+
-- Test for #11411: cabal should re-invoke build tools (in this case, alex)
4+
-- whose version changes in between builds.
5+
main :: IO ()
6+
main = cabalTest $ withRepo "repo" $ do
7+
-- Expect failure on first build: alex 3.4 outputs invalid Haskell.
8+
fails $ cabal "v2-build" ["all", "-c", "any.alex==3.4.*"]
9+
-- Second build should succeed: switching to alex 3.5 should cause cabal
10+
-- to re-invoke alex, which will output valid Haskell this time around.
11+
-- If this fails, it's because cabal didn't re-run the preprocessing step.
12+
cabal "v2-build" ["all", "-c", "any.alex==3.5.*"]
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cabal-version: 3.0
2+
name: alex
3+
version: 3.4.0.0
4+
build-type: Simple
5+
6+
executable alex
7+
main-is: Main.hs
8+
hs-source-dirs: app
9+
build-depends: base
10+
default-language: Haskell2010
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Main where
2+
3+
import System.Environment (getArgs)
4+
5+
-- Fake alex 3.4: writes invalid Haskell so that GHC rejects the output.
6+
main :: IO ()
7+
main = do
8+
args <- getArgs
9+
case args of
10+
"--version" : _ ->
11+
putStrLn "Alex version 3.4.0, (c) 2003 Chris Dornan and Simon Marlow"
12+
_ ->
13+
writeFile (outputFile args) "THIS IS NOT VALID HASKELL\n"
14+
15+
outputFile :: [String] -> FilePath
16+
outputFile ("-o" : f : _) = f
17+
outputFile (_ : rest) = outputFile rest
18+
outputFile [] = error "alex: no -o flag"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
cabal-version: 3.0
2+
name: alex
3+
version: 3.5.0.0
4+
build-type: Simple
5+
6+
executable alex
7+
main-is: Main.hs
8+
hs-source-dirs: app
9+
build-depends: base
10+
default-language: Haskell2010
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module Main where
2+
3+
import System.Environment (getArgs)
4+
5+
-- Fake alex 3.5: writes valid Haskell so that GHC accepts the output.
6+
main :: IO ()
7+
main = do
8+
args <- getArgs
9+
case args of
10+
"--version" : _ ->
11+
putStrLn "Alex version 3.5.0, (c) 2003 Chris Dornan and Simon Marlow"
12+
_ ->
13+
writeFile (outputFile args) "module Hello where\nhello :: String\nhello = \"hello from alex 3.5\"\n"
14+
15+
outputFile :: [String] -> FilePath
16+
outputFile ("-o" : f : _) = f
17+
outputFile (_ : rest) = outputFile rest
18+
outputFile [] = error "alex: no -o flag"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(contents irrelevant)

0 commit comments

Comments
 (0)