commercialhaskell / stack

The Haskell Tool Stack
http://haskellstack.org
BSD 3-Clause "New" or "Revised" License
3.98k stars 845 forks source link

Doctest integration that doesn't need custom Setup.hs #373

Closed bitemyapp closed 9 years ago

bitemyapp commented 9 years ago

Or at least makes it less painful.

Perhaps Stack could gather up the doctests for you and run them through doctests' API?

Per https://github.com/commercialhaskell/stack/issues/259#issuecomment-114153410

Yuck.

snoyberg commented 9 years ago

Is there a reason why this can't be done by the test suite itself? I'm not really seeing why stack has more information available to it to implement this well.

bitemyapp commented 9 years ago

@snoyberg "the test suite" being doctests or cabal test?

Not to say this is something Stack specifically has to solve, but it was intensely painful and I'm not sure where a scaffold or other solution should live. I kinda doubt doctests wants to be anything more than the bare-bones utility kit, which is partly why the Setup.hs ends up being so gnarly. Cabal isn't going to do anything either, so that really just leaves Stack or posting a scaffold/example that works on doctests' documentation.

Needing to rely on a scaffold/template for something that should, IMO, just work kinda irks me and I'm hoping somebody will have an idea.

snoyberg commented 9 years ago

Have you looked at the way hspec works? It uses a preprocessor to discover all of the relevant files and automatically test them. I was thinking of something along those lines for doctest.

bitemyapp commented 9 years ago

@snoyberg I really like using HSpec, that sounds like a good solution. Question is whether doctest maintainer will be open to it or not. :)

snoyberg commented 9 years ago

I think it's an orthogonal issue. We could have a separate doctest-formatter tool or something that could enable this kind of workflow, or doctest-hspec that ties the two together well.

snoyberg commented 9 years ago

Closing this. I'll be happy to provide feedback on how to implement a helper library to make this easier, but I don't think stack should be building in this functionality.

bitemyapp commented 9 years ago

@snoyberg understood, thank you!

bitemyapp commented 9 years ago

@snoyberg I need this as I've almost completely moved over to Stack for work and personal dev. Would you have time to explain how to get stack to run the doctests successfully? I can write it up after I get it working for the wiki / docs.

snoyberg commented 9 years ago

I've done this without needing to modify Setup.hs at all. You can look at the doctest for warp, which will be much sorter if you can rely on the newest version of doctest.

snoyberg commented 9 years ago

This may be interesting as well: https://github.com/yesodweb/wai/commit/52f892c3c9643a7e0f868832c2d783f3678c980d

bitemyapp commented 9 years ago

@snoyberg these helped a lot. I was able to eventually get it to work but it's still a little persnickety.

<command line>:
    Could not find module ‘Database’
    Use -v to see a list of the files searched for.
*** Exception: ExitFailure 1
Prelude> doctest ["Database.Bloodhound"]

<no location info>:
    module ‘Database.Bloodhound’ is a package module
*** Exception: ExitFailure 1
Prelude> doctest ["-i src"Database.Bloodhound"]

<interactive>:5:39:
    lexical error in string/character literal at end of input
Prelude> doctest ["-i src", "Database.Bloodhound"]
Examples: 83  Tried: 83  Errors: 0  Failures: 0

Nevertheless, this should be considerably less difficult for people to pick up than what I had before. Thank you very much!