haskell / haskell/cabal

Allow `main-is` as `autogen-modules` in test suites

Open
#10,834 2 comments 0 reactions 0 assignees View on GitHub
re: main type: enhancement
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

I am using `code-generators` to automatically generate my test suite. The `Main.hs` is also generated, I specify `main-is: Main.hs`, the auto-generated file is picked up by Cabal, and I have no problem running the tests. However, `cabal sdist` fails for the package, and depending on that package as a source-package via git also fails. Cabal reports (correctly) an error "Main.hs doesn't exist".

I believe the correct way to tell Cabal that `Main.hs` is auto-generated is to add `Main` to `autogen-modules`, but it does not work (as noted in [the documentation](https://cabal.readthedocs.io/en/3.14/cabal-package-description-file.html#pkg-field-autogen-modules)):
> Right now [`executable:main-is`](https://cabal.readthedocs.io/en/3.14/cabal-package-description-file.html#pkg-field-executable-main-is) modules are not supported on [`autogen-modules`](https://cabal.readthedocs.io/en/3.14/cabal-package-description-file.html#pkg-field-autogen-modules).

Is there any specific reasons that it is not supported?

---

Meanwhile, I figured out a workaround:

1. Instead of `main-is: Main.hs`, I specify the following in the Cabal file:
```cabal
test-suite doctests
main-is: DocTests.hs
hs-source-dirs: test
other-modules: Main
autogen-modules: Main
```
2. I create a dummy main file `test/DocTests.hs` that forwards to the real auto-generated `Main`:
```haskell
module DocTests (main) where
import Main qualified
main :: IO ()
main = Main.main
```

However, this seems to be a really roundabout way to specify something trivial. Maybe there is a simpler workaround that I failed to figure out?

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with a generated test-suite Main.hs, main-is: Main.hs, and autogen-modules: Main, then compare it with the documented workaround using a forwarding DocTests.hs. Read the autogen-modules and executable:main-is documentation sections first; done means cabal sdist and a source-package dependency both accept the generated main without the dummy wrapper.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.