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

Support for mixins? #289

Closed
dcastro opened this issue Feb 9, 2021 · 2 comments
Closed

Support for mixins? #289

dcastro opened this issue Feb 9, 2021 · 2 comments

Comments

@dcastro
Copy link

dcastro commented Feb 9, 2021

I'm not sure whether to ask this question here or in cabal-doctest. If it's the latter, please let me know and I'll move this issue.

I'm trying to get doctest to work on a project, but I can't get it to play ball with mixins.

Namely, I'm using a custom prelude and using mixins: base hiding (Prelude) to hide the default one. But it seems doctest doesn't seem to recognize this mixin and says there are two preludes in scope.

I've created a test project here, so we can reproduce this issue: https://github.com/dcastro/doctest-mixins
stack build works fine, but stack test fails.

$ stack build doctest-mixins:lib doctest-mixins:test:doctests --no-run-tests
doctest-mixins> configure (lib + test)
Configuring doctest-mixins-0.1.0.0...
doctest-mixins> build (lib + test)
Preprocessing library for doctest-mixins-0.1.0.0..
Building library for doctest-mixins-0.1.0.0..
Preprocessing test suite 'doctests' for doctest-mixins-0.1.0.0..
Building test suite 'doctests' for doctest-mixins-0.1.0.0..
[1 of 2] Compiling Build_doctests
Linking .stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/doctests/doctests ...
            
Warning: The following modules should be added to exposed-modules or other-modules in /home/dc/dev/other/doctest-mixins/doctest-mixins.cabal:
             - In test:doctests:
                 Build_doctests
             - In test:doctests:
                 Build_doctests
         
         Missing modules in the cabal file are likely to cause undefined reference errors from the linker, along with other problems.
doctest-mixins> copy/register
Installing library in /home/dc/dev/other/doctest-mixins/.stack-work/install/x86_64-linux-tinfo6/f379cbdb645e2f7b975c4e9af6625e7b004143a74d5f8f815a31249737060a3e/8.8.3/lib/x86_64-linux-ghc-8.8.3/doctest-mixins-0.1.0.0-J9NorAghXcQDDEeMJ3tfFn
Registering library for doctest-mixins-0.1.0.0..
doctest-mixins> Test running disabled by --no-run-tests flag.
Completed 2 action(s).
$ stack test doctest-mixins:test:doctests

doctest-mixins> test (suite: doctests)
            
Progress 1/2: doctest-mixins-i
-i/home/dc/dev/other/doctest-mixins/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/autogen
-i/home/dc/dev/other/doctest-mixins/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build
-i/home/dc/dev/other/doctest-mixins/src
-package-env=-
-hide-all-packages
-no-user-package-db
-package-db=/home/dc/.stack/snapshots/x86_64-linux-tinfo6/f379cbdb645e2f7b975c4e9af6625e7b004143a74d5f8f815a31249737060a3e/8.8.3/pkgdb
-package-db=/home/dc/dev/other/doctest-mixins/.stack-work/install/x86_64-linux-tinfo6/f379cbdb645e2f7b975c4e9af6625e7b004143a74d5f8f815a31249737060a3e/8.8.3/pkgdb
-package-db=.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/package.conf.inplace
-optP-include
-optP.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.0.1.0/build/autogen/cabal_macros.h
-package-id=base-4.13.0.0
-package-id=morley-prelude-0.3.0-emFluUQAgu2cOHiMlTd8V
-package-id=doctest-0.16.3-AoCHnIRCAFH3tdcWc14oMy
-package=doctest-mixins-0.1.0.0
Main
Paths_doctest_mixins

/home/dc/dev/other/doctest-mixins/src/Main.hs:1:8: error:
    Ambiguous module name ‘Prelude’:
      it was found in multiple packages:
      base-4.13.0.0 morley-prelude-0.3.0
  |
1 | module Main where
  |        ^^^^
                            
doctest-mixins> Test suite doctests failed
Completed 2 action(s).      
Test suite failure for package doctest-mixins-0.1.0.0
    doctests:  exited with: ExitFailure 1
Logs printed to console

My first thought was that I should be passing an extra flag to doctest, but I'm not sure which.

Is there a workaround for this, am I doing something wrong, or is this simply not supported at the moment?

@quasicomputational
Copy link
Collaborator

I don't think you're doing anything wrong - this definitely looks unsupported at the moment. I like mixins, so I would also like for this to Just Work.

doctest is, at its heart, a wrapper around (a) the GHC API, used to parse source files and discover tests, and (b) GHCi, to run the tests. It doesn't really know anything about packages, which includes mixins, and I feel like this is a sensible layering.

The way that cabal-doctest works is that it figures out the correct arguments to pass to GHCi that will bring the necessary packages (with the correct versions) in to scope, and doctest duly passes those through when it invokes GHCi and everything works out (hopefully!).

I think that mixins are also passed on the command line in a similar way, so cabal-doctest feels like the most natural place to put this logic - it is already dealing with linking packages together and turning that into command-line arguments for GHCi consumption.

Having said that, I'm not certain that the necessary information is available to cabal-doctest anyway, so it might wind up that there need to be upstream changes to Cabal or cabal-install/Stack for this to work out.

@dcastro
Copy link
Author

dcastro commented Feb 10, 2021

@quasicomputational Thank you for your reply!

Yup, that makes sense, I've opened an issue in ulidtko/cabal-doctest#68, I hope there's an easy fix 😃

@dcastro dcastro closed this as completed Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants