cabal
cabal copied to clipboard
Add Cabal-tests workaround project
A workaround for #9901 so that we can use released versions of cabal-install, such as cabal-3.8.* and cabal-3.10.*, with Cabal-tests:parser-tests and Cabal-tests:check-tests test suites when cabal run running them to accept updated test outputs.
To repeat the problem; when we run cabal test Cabal-tests, the working directory will be Cabal-tests but when we run cabal run Cabal-tests:parser-tests or Cabal-tests:check-tests it will be the current directory. To update the expected outputs we need to first change directory to Cabal-tests. That is good for the package but not for the root cabal.project that will be unable to resolve imports failing with;
$ cd Cabal-tests/
$ cabal run Cabal-tests:parser-tests -- --accept
project-cabal/pkgs/cabal.config: withBinaryFile: does not exist (No such file or directory)
I deliberately named Cabal-tests/cabal.workaround.project so that we might notice to delete it at a later time. This is at the cost of having to do the following with earlier versions of cabal;
$ cd Cabal-tests/
$ ~/.ghcup/bin/cabal run Cabal-tests:parser-tests --project-file=cabal.workaround.project -- --accept
$ ~/.ghcup/bin/cabal --version
cabal-install version 3.10.1.0
compiled using version 3.10.1.0 of the Cabal library
[!NOTE] With #9578 and later versions of
cabal-install, the above problem does not occur and the workaround project is not needed. I did not set out to fix this exact problem but left the comment "I also fix some bugs around project imports" on that pull request. Related, we should check the behavior before and after #9578 to see if it helps with #8795.
- I updated the readme for
Cabal-testsand put it in that package's directory, up one from where it was before. - I noticed that docs for
cabal testandcabal runmake no mention of working directory. - I noticed an inconsistency between
Cabal-tests --acceptandcabal-testsuite --accept. With the former we need to be in theCabal-testsdirectory for it to work but for the later we need to be in the root of the project and running--acceptfrom thecabal-testsuitedirectory fails. Currently it fails for the same reason asCabal-testsdoes but prior to the project changes of #9565, it also fails;
$ git rev-parse HEAD
1c1230ca228cc03a9ee68166243af358ab3992fc
$ cabal install cabal-install:exe:cabal --overwrite-policy=always
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 9.8.2
$ cabal build all --enable-tests --enable-benchmarks
$ ls cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
$ cabal run cabal-testsuite:cabal-tests -- --with-cabal=./dist-newstyle/build/x86_64-linux/ghc-9.8.2/cabal-install-3.11.0.0/x/cabal/build/cabal/cabal cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs --accept
...
OK
$ cd cabal-testsuite
$ cabal run cabal-testsuite:cabal-tests -- --with-cabal=./dist-newstyle/build/x86_64-linux/ghc-9.8.2/cabal-install-3.11.0.0/x/cabal/build/cabal/cabal cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs --accept
...
<no location info>: error: [GHC-49196]
Can't find cabal-testsuite/PackageTests/ConditionalAndImport/cabal.test.hs
*** Exception: ExitFailure 1
...
Template Β: This PR does not modify cabal behaviour (documentation, tests, refactoring, etc.)
Include the following checklist in your PR:
- [x] Patches conform to the coding conventions.
- [ ] Is this a PR that fixes CI? If so, it will need to be backported to older cabal release branches (ask maintainers for directions).
A ping about https://github.com/haskell/cabal/issues/9901#issuecomment-2072965636 in case it goes under the radar. :)
[!Note]
With #9578 and later versions of
cabal-install, the above problem does not occur and the workaround project is not needed. I did not set out to fix this exact problem but left the comment "I also fix some bugs around project imports" on that pull request.
@grayjay the effort we put into #9578 may be paying dividends.
@philderbeast: thank you for you prompt action. The reporter of the issue is on holidays, so let me add another reviewer.
@Mikolaj, I've renamed the workaround project so that it will be picked up automatically from the Cabal-tests directory, the directory that we need to be in for cabal run --accept to update expected outputs for the test suite.
Yay, so does this solve all plausible cases of this failure? Or is there a common workflow that does not enter that directory?
Can the reviewers/reporters comment?
Yay, so does this solve all plausible cases of this failure?
It fixes the reproduction of #9901 for cabal run. This workaround project will only be picked up if in the Cabal-tests directory.
Or is there a common workflow that does not enter that directory?
For cabal test, there's no directory restriction as long as cabal can sight the project. We can test the parser-tests test suite from the root directory or any subdirectory of the project except those with a intercepting project such as cabal-testsuite that blocks access to the root project.
I am not sure this fixes the regression, you are still unable to run cabal in a subdirectory (it partially fixes the issue with running it in one specific subdirectory).
@Mikolaj & @mpickering , I'm closing this now in anticipation of the imminent cabal-install-3.12.* release that will be able to cabal run from the Cabal-tests subdirectory without the workaround.