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 #68

Open
dcastro opened this issue Feb 10, 2021 · 6 comments
Open

Support for mixins #68

dcastro opened this issue Feb 10, 2021 · 6 comments

Comments

@dcastro
Copy link

dcastro commented Feb 10, 2021

I'm trying to get doctest+cabal-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

I've first reported this issue in sol/doctest#289. It was suggested that maybe cabal-doctest would be the ideal place to solve this issue.

If it helps, I've also uploaded the output of cabal build lib:doctest-mixins -v3 in a gist.

@phadej
Copy link
Collaborator

phadej commented Feb 10, 2021

build-type: Custom and mixins (or backpack in general) just don't work together.

@dcastro
Copy link
Author

dcastro commented Feb 11, 2021

@phadej Ah, that's sad to hear :/ Is that an intrinsic limitation, or is there a chance (even if slim) mixins and Custom may work in the future?

@phadej
Copy link
Collaborator

phadej commented Feb 11, 2021

In theory they could. In practice it requires a lot of engineering (which I think is wasted work).

I have made cabal-docspec which allows to run doctests on anything you can build with cabal-install: https://github.com/phadej/cabal-extras/tree/master/cabal-docspec; If you have a choice use it. I'm tempted to deprecate cabal-doctest in the near future, as I have no use for it myself and there is a replacement (though not strictly better, there are different - IMHO better - trade-offs).

@dcastro
Copy link
Author

dcastro commented Feb 11, 2021

Interesting! How would I go about using it? For example, in this test repo, how would I enable cabal-docspec?

@phadej
Copy link
Collaborator

phadej commented Feb 12, 2021

Please read the manual first.

@dcastro
Copy link
Author

dcastro commented Feb 12, 2021

Oh, I completely missed the manual.md, I was looking for a readme.md 😅 Thanks, I'll have a look!

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