Skip to content

Commit 4c81ae7

Browse files
committed
SetupHooks: add tests
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).
1 parent 9857afe commit 4c81ae7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+834
-5
lines changed

Cabal-tests/tests/UnitTests/Distribution/Utils/Structured.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ md5Check proxy md5Int = structureHash proxy @?= md5FromInteger md5Int
3333
md5CheckGenericPackageDescription :: Proxy GenericPackageDescription -> Assertion
3434
md5CheckGenericPackageDescription proxy = md5Check proxy
3535
#if MIN_VERSION_base(4,19,0)
36-
0x5a48c6570cbcf96af4c51f38962e37b5
36+
0x03b0282cd561d1b1563d16fa061e3dd7
3737
#else
38-
0xc5c0e54b95e651216e92db04c9cd4ecf
38+
0x00633b73694ed591f0437e54905b5b61
3939
#endif
4040

4141
md5CheckLocalBuildInfo :: Proxy LocalBuildInfo -> Assertion
4242
md5CheckLocalBuildInfo proxy = md5Check proxy
4343
#if MIN_VERSION_base(4,19,0)
44-
0x92782413689aba84f1ae8a71e0ff4475
44+
0x6f6302c2aea249e02c17ae5a047eef9f
4545
#else
46-
0xfa44477c60b169f306656c4df793c2c5
46+
0x3032ed4480d707e373e2e627e580e7ae
4747
#endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Main where
2+
3+
import Distribution.Simple ( defaultMainWithSetupHooks )
4+
import SetupHooks ( setupHooks )
5+
6+
main :: IO ()
7+
main = defaultMainWithSetupHooks setupHooks
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module SetupHooks where
2+
3+
import Distribution.Simple.SetupHooks
4+
5+
import Control.Monad ( void )
6+
7+
setupHooks :: SetupHooks
8+
setupHooks =
9+
noSetupHooks
10+
{ configureHooks =
11+
noConfigureHooks
12+
{ preConfComponentHook = Just pccHook }
13+
}
14+
15+
pccHook :: PreConfComponentHook
16+
pccHook _ = return $
17+
PreConfComponentOutputs $ ComponentDiff $ CExe emptyExecutable
18+
-- Bad: component is a library, but we returned an executable!
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
cabal-version: 3.12
2+
name: setup-hooks-bad-diff1-test
3+
version: 0.1.0.0
4+
synopsis: Test 1 for a bad component diff
5+
license: BSD-3-Clause
6+
author: NA
7+
maintainer: NA
8+
category: Testing
9+
build-type: Hooks
10+
11+
custom-setup
12+
setup-depends: Cabal-hooks, base
13+
14+
library
15+
build-depends: base
16+
default-language: Haskell2010
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Setup configure
2+
Configuring setup-hooks-bad-diff1-test-0.1.0.0...
3+
Error: [Cabal-9491]
4+
Hooks: mismatched component types in per-component configure hook.
5+
Trying to apply an executable diff to a library.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Test.Cabal.Prelude
2+
main = setupTest $ do
3+
fails $ setup "configure" []
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module Main where
2+
3+
import Distribution.Simple ( defaultMainWithSetupHooks )
4+
import SetupHooks ( setupHooks )
5+
6+
main :: IO ()
7+
main = defaultMainWithSetupHooks setupHooks
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
3+
module SetupHooks where
4+
5+
import Distribution.Simple.SetupHooks
6+
7+
import Control.Monad ( void )
8+
9+
setupHooks :: SetupHooks
10+
setupHooks =
11+
noSetupHooks
12+
{ configureHooks =
13+
noConfigureHooks
14+
{ preConfComponentHook = Just pccHook }
15+
}
16+
17+
pccHook :: PreConfComponentHook
18+
pccHook _ = return $
19+
-- Make invalid changes to a library
20+
PreConfComponentOutputs $ ComponentDiff $ CLib $
21+
emptyLibrary
22+
{ libName = LSubLibName "hocus-pocus"
23+
, libExposed = False
24+
, libBuildInfo =
25+
emptyBuildInfo
26+
{ buildable = False }
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .

0 commit comments

Comments
 (0)