-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This adds tests for error messages related to SetupHooks: - error when returning an invalid component diff in a per-component pre-configure hook - error when declaring pre-build rules whose dependency graph contains cycles - error when we cannot find a dependency of a pre-build rule - warning when there are pre-build rules that are declared but never demanded It also adds some correctness tests for SetupHooks, e.g. that pre-build rules are run in dependency order (see the `SetupHooksRuleOrdering` test).
- Loading branch information
Showing
55 changed files
with
505 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Main where | ||
|
||
import Distribution.Simple ( defaultMainWithSetupHooks ) | ||
import SetupHooks ( setupHooks ) | ||
|
||
main :: IO () | ||
main = defaultMainWithSetupHooks setupHooks |
18 changes: 18 additions & 0 deletions
18
cabal-testsuite/PackageTests/SetupHooksBadDiff1/SetupHooks.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module SetupHooks where | ||
|
||
import Distribution.Simple.SetupHooks | ||
|
||
import Control.Monad ( void ) | ||
|
||
setupHooks :: SetupHooks | ||
setupHooks = | ||
noSetupHooks | ||
{ configureHooks = | ||
noConfigureHooks | ||
{ preConfComponentHook = Just pccHook } | ||
} | ||
|
||
pccHook :: PreConfComponentHook | ||
pccHook _ = return $ | ||
PreConfComponentOutputs $ ComponentDiff $ CExe emptyExecutable | ||
-- Bad: component is a library, but we returned an executable! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: . |
16 changes: 16 additions & 0 deletions
16
cabal-testsuite/PackageTests/SetupHooksBadDiff1/setup-hooks-bad-diff1-test.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cabal-version: 2.2 | ||
name: setup-hooks-bad-diff1-test | ||
version: 0.1.0.0 | ||
synopsis: Test 1 for a bad component diff | ||
license: BSD-3-Clause | ||
author: NA | ||
maintainer: NA | ||
category: Testing | ||
build-type: Hooks | ||
|
||
custom-setup | ||
setup-depends: Cabal-hooks, base | ||
|
||
library | ||
build-depends: base | ||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Setup configure | ||
Configuring setup-hooks-bad-diff1-test-0.1.0.0... | ||
Error: [Cabal-9491] | ||
Hooks: mismatched component types in per-component configure hook. | ||
Trying to apply an executable diff to a library. |
3 changes: 3 additions & 0 deletions
3
cabal-testsuite/PackageTests/SetupHooksBadDiff1/setup.test.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Test.Cabal.Prelude | ||
main = setupTest $ do | ||
fails $ setup "configure" [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Main where | ||
|
||
import Distribution.Simple ( defaultMainWithSetupHooks ) | ||
import SetupHooks ( setupHooks ) | ||
|
||
main :: IO () | ||
main = defaultMainWithSetupHooks setupHooks |
27 changes: 27 additions & 0 deletions
27
cabal-testsuite/PackageTests/SetupHooksBadDiff2/SetupHooks.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module SetupHooks where | ||
|
||
import Distribution.Simple.SetupHooks | ||
|
||
import Control.Monad ( void ) | ||
|
||
setupHooks :: SetupHooks | ||
setupHooks = | ||
noSetupHooks | ||
{ configureHooks = | ||
noConfigureHooks | ||
{ preConfComponentHook = Just pccHook } | ||
} | ||
|
||
pccHook :: PreConfComponentHook | ||
pccHook _ = return $ | ||
-- Make invalid changes to a library | ||
PreConfComponentOutputs $ ComponentDiff $ CLib $ | ||
emptyLibrary | ||
{ libName = LSubLibName "hocus-pocus" | ||
, libExposed = False | ||
, libBuildInfo = | ||
emptyBuildInfo | ||
{ buildable = False } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: . |
16 changes: 16 additions & 0 deletions
16
cabal-testsuite/PackageTests/SetupHooksBadDiff2/setup-hooks-bad-diff2-test.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
cabal-version: 2.2 | ||
name: setup-hooks-bad-diff2-test | ||
version: 0.1.0.0 | ||
synopsis: Test 2 for a bad component diff | ||
license: BSD-3-Clause | ||
author: NA | ||
maintainer: NA | ||
category: Testing | ||
build-type: Hooks | ||
|
||
custom-setup | ||
setup-depends: Cabal-hooks, base | ||
|
||
library | ||
build-depends: base | ||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Setup configure | ||
Configuring setup-hooks-bad-diff2-test-0.1.0.0... | ||
Error: [Cabal-7634] | ||
Hooks: illegal component diff in per-component pre-configure hook for main library: | ||
- cannot change the name of a component. | ||
- cannot change component field 'libExposed'. | ||
- cannot change BuildInfo field 'buildable'. |
3 changes: 3 additions & 0 deletions
3
cabal-testsuite/PackageTests/SetupHooksBadDiff2/setup.test.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Test.Cabal.Prelude | ||
main = setupTest $ do | ||
fails $ setup "configure" [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Main where | ||
|
||
import Distribution.Simple ( defaultMainWithSetupHooks ) | ||
import SetupHooks ( setupHooks ) | ||
|
||
main :: IO () | ||
main = defaultMainWithSetupHooks setupHooks |
34 changes: 34 additions & 0 deletions
34
cabal-testsuite/PackageTests/SetupHooksCyclicRules/SetupHooks.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE RecursiveDo #-} | ||
|
||
module SetupHooks where | ||
|
||
import Distribution.Simple.SetupHooks | ||
|
||
import qualified Data.List.NonEmpty as NE ( NonEmpty(..) ) | ||
|
||
setupHooks :: SetupHooks | ||
setupHooks = | ||
noSetupHooks | ||
{ buildHooks = | ||
noBuildHooks | ||
{ preBuildComponentRules = Just cyclicPreBuildRules | ||
} | ||
} | ||
|
||
cyclicPreBuildRules :: Rules PreBuildComponentInputs | ||
cyclicPreBuildRules = rules $ \ (PreBuildComponentInputs { localBuildInfo = lbi, targetInfo = tgt }) -> do | ||
let clbi = targetCLBI tgt | ||
autogenDir = autogenComponentModulesDir lbi clbi | ||
actId <- registerAction "a" $ simpleAction $ \ _ _ -> error "This should not run" | ||
return $ mdo | ||
r1 <- registerRule "r1" $ | ||
simpleRule actId | ||
[ RuleDependency $ RuleOutput r2 0 ] | ||
( ( autogenDir, "G2.hs" ) NE.:| [] ) | ||
r2 <- registerRule "r2" $ | ||
simpleRule actId | ||
[ RuleDependency $ RuleOutput r1 0 ] | ||
( ( autogenDir, "G1.hs" ) NE.:| [] ) | ||
return () |
1 change: 1 addition & 0 deletions
1
cabal-testsuite/PackageTests/SetupHooksCyclicRules/cabal.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: . |
18 changes: 18 additions & 0 deletions
18
cabal-testsuite/PackageTests/SetupHooksCyclicRules/setup-hooks-cyclic-rules-test.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cabal-version: 2.2 | ||
name: setup-hooks-cyclic-rules-test | ||
version: 0.1.0.0 | ||
synopsis: Test for cyclic rules | ||
license: BSD-3-Clause | ||
author: NA | ||
maintainer: NA | ||
category: Testing | ||
build-type: Hooks | ||
|
||
custom-setup | ||
setup-depends: Cabal-hooks, base | ||
|
||
library | ||
exposed-modules: G1, G2 | ||
autogen-modules: G1, G2 | ||
build-depends: base | ||
default-language: Haskell2010 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Setup configure | ||
Configuring setup-hooks-cyclic-rules-test-0.1.0.0... | ||
# Setup build | ||
Error: [Cabal-9077] | ||
Hooks: cycle in dependency structure of rules: | ||
Rule: [(RuleId {ruleUnitId = "main", ruleId = "r2"})[0]] --> [setup.dist/work/dist/build/autogen/G2.hs] | ||
| | ||
`- Rule: [(RuleId {ruleUnitId = "main", ruleId = "r1"})[0]] --> [setup.dist/work/dist/build/autogen/G1.hs] | ||
|
4 changes: 4 additions & 0 deletions
4
cabal-testsuite/PackageTests/SetupHooksCyclicRules/setup.test.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Test.Cabal.Prelude | ||
main = setupTest $ do | ||
setup "configure" [] | ||
fails $ setup "build" [] |
7 changes: 7 additions & 0 deletions
7
cabal-testsuite/PackageTests/SetupHooksMissingRuleDep/Setup.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Main where | ||
|
||
import Distribution.Simple ( defaultMainWithSetupHooks ) | ||
import SetupHooks ( setupHooks ) | ||
|
||
main :: IO () | ||
main = defaultMainWithSetupHooks setupHooks |
28 changes: 28 additions & 0 deletions
28
cabal-testsuite/PackageTests/SetupHooksMissingRuleDep/SetupHooks.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{-# LANGUAGE DuplicateRecordFields #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
|
||
module SetupHooks where | ||
|
||
import Distribution.Simple.SetupHooks | ||
|
||
import qualified Data.List.NonEmpty as NE ( NonEmpty(..) ) | ||
|
||
setupHooks :: SetupHooks | ||
setupHooks = | ||
noSetupHooks | ||
{ buildHooks = | ||
noBuildHooks | ||
{ preBuildComponentRules = Just missingDepRules | ||
} | ||
} | ||
|
||
missingDepRules :: Rules PreBuildComponentInputs | ||
missingDepRules = rules $ \ (PreBuildComponentInputs { localBuildInfo = lbi, targetInfo = tgt }) -> do | ||
let clbi = targetCLBI tgt | ||
autogenDir = autogenComponentModulesDir lbi clbi | ||
actId <- registerAction "a" $ simpleAction $ \ _ _ -> error "This should not run" | ||
return $ | ||
registerRule_ "r" $ | ||
simpleRule actId | ||
[ FileDependency ( ".", "Missing.hs" ) ] | ||
( ( autogenDir, "G.hs" ) NE.:| [] ) |
1 change: 1 addition & 0 deletions
1
cabal-testsuite/PackageTests/SetupHooksMissingRuleDep/cabal.project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
packages: . |
18 changes: 18 additions & 0 deletions
18
...l-testsuite/PackageTests/SetupHooksMissingRuleDep/setup-hooks-missing-rule-dep-test.cabal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
cabal-version: 2.2 | ||
name: setup-hooks-missing-rule-dep-test | ||
version: 0.1.0.0 | ||
synopsis: Test for missing dependency in rules | ||
license: BSD-3-Clause | ||
author: NA | ||
maintainer: NA | ||
category: Testing | ||
build-type: Hooks | ||
|
||
custom-setup | ||
setup-depends: Cabal-hooks, base | ||
|
||
library | ||
exposed-modules: G | ||
autogen-modules: G | ||
build-depends: base | ||
default-language: Haskell2010 |
6 changes: 6 additions & 0 deletions
6
cabal-testsuite/PackageTests/SetupHooksMissingRuleDep/setup.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Setup configure | ||
Configuring setup-hooks-missing-rule-dep-test-0.1.0.0... | ||
# Setup build | ||
Error: [Cabal-1071] | ||
Pre-build rules: can't find source for rule dependency: | ||
- Missing.hs |
4 changes: 4 additions & 0 deletions
4
cabal-testsuite/PackageTests/SetupHooksMissingRuleDep/setup.test.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import Test.Cabal.Prelude | ||
main = setupTest $ do | ||
setup "configure" [] | ||
fails $ setup "build" [] |
7 changes: 7 additions & 0 deletions
7
cabal-testsuite/PackageTests/SetupHooksMissingRuleRes/Setup.hs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Main where | ||
|
||
import Distribution.Simple ( defaultMainWithSetupHooks ) | ||
import SetupHooks ( setupHooks ) | ||
|
||
main :: IO () | ||
main = defaultMainWithSetupHooks setupHooks |
Oops, something went wrong.