Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow main-is as autogen-modules in test suites #10834

Open
ruifengx opened this issue Mar 16, 2025 · 2 comments
Open

Allow main-is as autogen-modules in test suites #10834

ruifengx opened this issue Mar 16, 2025 · 2 comments
Labels
re: main Concerning the `main-is` field type: enhancement

Comments

@ruifengx
Copy link

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):

Right now executable:main-is modules are not supported on 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:
    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:
    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?

ruifengx added a commit to ruifengx/doctest-driver that referenced this issue Mar 16, 2025
Cabal does not really support main-is to also be listed in autogen-modules (it has no effect, to be precise), so we apply a workaround. Reported as haskell/cabal#10834, but we have to stick with this workaround in the meantime.
@andreasabel andreasabel added the re: main Concerning the `main-is` field label Mar 17, 2025
@andreasabel
Copy link
Member

@ruifengx
Copy link
Author

Oops! Thanks for the link. It seems main-is is not doing what I expected it to (in my case, I suspect the generated Main.hs is still chosen as the main module because its name is Main, but it works either way, so it doesn't really matter).

But I still think that is orthogonal to what I report here. The problem is that a test-suite with type exitcode-stdio-1.0 is required to have a main-is field (otherwise the cabal file is considered invalid), so I have to refer to some Main module in my cabal file, and that file cannot be specified as autogen-modules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
re: main Concerning the `main-is` field type: enhancement
Projects
None yet
Development

No branches or pull requests

2 participants