`cabal test --write-ghc-environment-files=always` generates GHC environment files _after_ running tests
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
When running `cabal test` with `--write-ghc-environment-files=always`, a GHC environment file is only written _after_ finishing the tests. Tests relying on the presence of these files (e.g., consumers of the GHC API or tests invoking GHCi) therefore fail to run.
**To Reproduce**
```
git clone https://github.com/martijnbastiaan/import-issues-cabal.git
cd import-issues-cabal
```
This project has a test-suite that:
1. Starts GHCi
2. Executes "import Library"
Which yields:
```
$ rm -f .ghc.env*
$ cabal test --enable-tests --test-show-details=always --write-ghc-environment-files=always
[..]
GHCi, version 8.10.3: https://www.haskell.org/ghc/ :? for help
Prelude>
: error:
Could not find module ‘Library’
It is not a module in the current program, or in any known package.
Prelude> Leaving GHCi.
[..]
$ cabal test --enable-tests --test-show-details=always --write-ghc-environment-files=always
[..]
GHCi, version 8.10.3: https://www.haskell.org/ghc/ :? for help
Loaded package environment from /home/martijn/Code/import-issues-cabal/.ghc.environment.x86_64-linux-8.10.3
Prelude> Prelude Library> Leaving GHCi.
[..]
```
Interestingly, `cabal run` does this "correctly":
```
$ rm -f .ghc.env*
$ cabal v2-run import-issues --write-ghc-environment-files=always
Up to date
GHCi, version 8.10.3: https://www.haskell.org/ghc/ :? for help
Loaded package environment from /home/martijn/Code/import-issues-cabal/.ghc.environment.x86_64-linux-8.10.3
Prelude> Prelude Library> Prelude Library LibraryExtra> Leaving GHCi.
```
**Expected behavior**
Like `run` I expect environment files to be written before a test runs. This is important for consumers of the GHC API of GHCi, such as `doctest-parallel` or the Clash project.
**System information**
```
$ cabal --version
cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.3
$ lsb_release -a
[..]
Description: Ubuntu 20.04.3 LTS
[..]
```
Contributor guide
Assessment
This issue has not been assessed yet.