Skip to content

Commit

Permalink
Add an intercepting cabal-testsuite/cabal.project
Browse files Browse the repository at this point in the history
- Reduce duplication in test flag setup
- Avoid "New config" picking cabal's own project

Before this change, this was the test failure:

Unit Tests
  UnitTests.Distribution.Client.Configure
    Configure tests
      New config:                     FAIL
        Exception: project-cabal/pkgs/cabal.config: withBinaryFile: does not exist (No such file or directory)
        Use -p '/New config/' to rerun this test only.
      Replacement + new config:       OK
      Old + new config:               OK
      Old + new config, no appending: OK
      Old + new config, backup check: OK
      Local program options:          OK

1 out of 6 tests failed (0.02s)
  • Loading branch information
philderbeast committed Mar 26, 2024
1 parent 8453ee0 commit d336275
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 26 deletions.
41 changes: 15 additions & 26 deletions cabal-install/tests/UnitTests/Distribution/Client/Configure.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ tests =
[ configureTests
]

defaultTestFlags :: NixStyleFlags ()
defaultTestFlags =
(defaultNixStyleFlags ())
{ projectFlags =
mempty
{ flagProjectDir = Flag projectDir
}
}

configureTests :: TestTree
configureTests =
testGroup
"Configure tests"
[ testCase "New config" $ do
let flags =
(defaultNixStyleFlags ())
defaultTestFlags
{ configFlags =
mempty
{ configOptimization = Flag MaximumOptimisation
Expand All @@ -42,7 +51,7 @@ configureTests =
@=? (packageConfigOptimization . projectConfigLocalPackages $ snd projConfig)
, testCase "Replacement + new config" $ do
let flags =
(defaultNixStyleFlags ())
defaultTestFlags
{ configExFlags =
mempty
{ configAppend = Flag True
Expand All @@ -52,18 +61,14 @@ configureTests =
{ configOptimization = Flag NoOptimisation
, configVerbosity = Flag silent
}
, projectFlags =
mempty
{ flagProjectDir = Flag projectDir
}
}
(_, ProjectConfig{..}) <- configureAction' flags [] defaultGlobalFlags

Flag NoOptimisation @=? packageConfigOptimization projectConfigLocalPackages
Flag silent @=? projectConfigVerbosity projectConfigBuildOnly
, testCase "Old + new config" $ do
let flags =
(defaultNixStyleFlags ())
defaultTestFlags
{ configExFlags =
mempty
{ configAppend = Flag True
Expand All @@ -72,42 +77,30 @@ configureTests =
mempty
{ configVerbosity = Flag silent
}
, projectFlags =
mempty
{ flagProjectDir = Flag projectDir
}
}
(_, ProjectConfig{..}) <- configureAction' flags [] defaultGlobalFlags

Flag MaximumOptimisation @=? packageConfigOptimization projectConfigLocalPackages
Flag silent @=? projectConfigVerbosity projectConfigBuildOnly
, testCase "Old + new config, no appending" $ do
let flags =
(defaultNixStyleFlags ())
defaultTestFlags
{ configFlags =
mempty
{ configVerbosity = Flag silent
}
, projectFlags =
mempty
{ flagProjectDir = Flag projectDir
}
}
(_, ProjectConfig{..}) <- configureAction' flags [] defaultGlobalFlags

NoFlag @=? packageConfigOptimization projectConfigLocalPackages
Flag silent @=? projectConfigVerbosity projectConfigBuildOnly
, testCase "Old + new config, backup check" $ do
let flags =
(defaultNixStyleFlags ())
defaultTestFlags
{ configFlags =
mempty
{ configVerbosity = Flag silent
}
, projectFlags =
mempty
{ flagProjectDir = Flag projectDir
}
}
backup = projectDir </> "cabal.project.local~"

Expand All @@ -122,16 +115,12 @@ configureTests =
, testCase "Local program options" $ do
let ghcFlags = ["-fno-full-laziness"]
flags =
(defaultNixStyleFlags ())
defaultTestFlags
{ configFlags =
mempty
{ configVerbosity = Flag silent
, configProgramArgs = [("ghc", ghcFlags)]
}
, projectFlags =
mempty
{ flagProjectDir = Flag projectDir
}
}
(_, ProjectConfig{..}) <- configureAction' flags [] defaultGlobalFlags

Expand Down
6 changes: 6 additions & 0 deletions cabal-testsuite/cabal.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- This intercepting project is here to avoid tests picking up a cabal.project
-- from a parent directory, such as the one in the root of the `haskell/cabal`
-- project itself. Having `optional-packages: .` avoids the folowing warning
-- being added to the `.out` file:
-- Warning: There are no packages or optional-packages in the project
optional-packages: .

0 comments on commit d336275

Please sign in to comment.