-
Notifications
You must be signed in to change notification settings - Fork 711
Dependency issues with cabal repl
and test-suites
#2032
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
Comments
Trying this again, I can not reproduce it anymore. I would close this and wait if we get more reports like this. |
I just ran into this doing Edit: I couldn't repro using @sol's repro steps though, with or without a sandbox Version info
|
Hi @MaxGabriel - we can re-open this or create a new issue if this problem still occurs, however I was able to get I don't have the whole set of output when I was testing that locally since I cleared my buffer, but essentially the problems I fixed were:
Do the changes I made in my repo make sense to you to fix this issue, or is there still something wrong? I'd appreciate if you could paste all of your build output, perhaps in the form of a new ticket if there is a different problem you're still seeing. |
@jsl Oh, I thought from @sol's issue that it wasn't supposed to be necessary to add the packages from the main project to the build-depends section of the test project to use |
I made the complete output of The output of
I can reproduce this issue in the scaffolding for yesod as well; there may be an issue with how that project is setup. |
@MaxGabriel thanks for providing the complete output. It may be that it's possible to avoid copying the dependencies, but do you have any links to where that feature is described? It's very possible I've missed something in a recent cabal, but I've always copied the dependencies in my projects between the libs and test sections. If we determine that you should be able to get away without copying dependencies between test and lib sections in the cabal file, having |
At PivotCloud, we have reproduced this with an executable target that depends on the library defined in the same cabal file. At this point, we have had to switch to using Has anyone else experienced this for executable targets? It might be that this bug, when it occurs, affects all non-library components which depend on the main library defined in the package. |
It's not entirely clear to me how buggy `cabal repl` still is. So let's just not mention it for now. (related haskell/cabal#2032)
Can anyone associated with this ticket give up-to-date instructions on how to reproduce this, with the latest version of Cabal? That would be very helpful! |
I think the original issue is still relevant with the latest version of |
Please do! The most useful way you can test is by actually creating a test case in one of the Cabal test suites; but clear repro instructions are also good enough (and I can make the test.) |
OK, the original issue appears fixed, but I suspect I know why it still doesn't help in the emacs modes: they don't realize they need to load a separate REPL for the testsuite. I mention this because that's why I taught cabal repl had a bug. (I last tested this with stack's cabal-mode, sorry, should try rechecking with the original emacs mode). OTOH, a separate REPL does sound awful in terms of memory consumption. Another issue in this ticket (EDIT: see #2032 (comment)) was about copying library dependencies to the testsuite. But as far as I can tell, this does not work currently (my testcase below). Is there we have a feature request for that? If not, below's a testcase for what I'd like to work. That should be genuinely useful for Cabal. I'm not sure about @jonsterling's issue, but that seems yet a separate ticket. However, I should probably reproduce this more cleanly in a cabal sandbox. I was impatient and had Test libraries not available in
|
Thank you for the detailed report. Let me address these in reverse order.
This is what you'd expect: the dependencies of a test suite are independent of the dependencies of the library. This behavior is justified by analogy to how library dependencies work: if a library Of course, the code in a test suite is often closely related to the code for the library, so having some way to define a common stanzas between the two would be useful (#2832) (and empirically, probably no one would lose sleep if test suites just inherited the dependencies of the library a priori). Unfortunately, that feature request has languished due to a lack of someone to helm it. My understanding is also that hpack was at least partially motivated in making this case nicer for users (and it supports older Cabal versions, which is not something any fix to #2832 can do). There is one other thing to know about here: there is a common design pattern, especially for executable only packages, for the test suite to contain a "copy" of the library/executable code. This SO question and in fact cabal-install itself are both examples of this pattern. When you look at the file system there is only one copy of the source file, true, but when you build the actual executable and test the module is compiled twice, and those two compilations really are different. This can lead to puzzling errors sometimes (though I don't have a link ready.)
OK. I'll also add that if you This behavior is "by design" but I'm inclined to think the design is wrong in some non-obvious way. Here's what's going on: the design of Cabal's REPL is that it always operates in the context of some particular component. This is because GHCi doesn't know how to handle loading files from multiple packages (https://ghc.haskell.org/trac/ghc/ticket/10827). As a consequence of this, whichever component you pick, only the So what it seems to me is that people want a REPL mode that, at the very least, unions together the build dependencies of ALL configured components, with the idea that if you load any module, all of its dependencies will be in scope. Obviously there are some corner cases where this will not work (e.g., if the library and the test suite have differing dependencies that bring into scope conflicting module names) but by and large it should work. In effect, we are making a fake, "uber-package" which contains all of the source files for all of the components, to work around GHCi's lack of support for handling multi-package things. It will break whenever your code actually needed to have things put in separate packages but it might still be useful. Perhaps there is some recommendation we can give the haskell-modes so that they know which repl to start up? One heuristic is to look at the |
Here's a summary of issues mentioned in this ticket. OP is fixed: checked by #2032 (comment) and myself. I suggest we should close the ticket and open new ones if there's a need. The candidates for new ones are listed in #2032 (comment), and I'll be quoting it
The author admits this is bad, so let's not pursue it. |
Sorry, sent the previous message accidentally.
This is no surprise and works as expected. In the example provided, the test component depends on
This doesn't sound like a proposal for a ticket/feature-request, but if anyone keen on it, they could open a new ticket about it, I guess. Bottom line: I think we can close this ticket. |
FWIW I'm not the original author (since you're replying to #2032 (comment)), but I haven't checked on this bug in year so I can't stand in the way. Some points from @ezyang 's response (#2032 (comment)) might deserve a ticket, but somebody (not me) would have to take a look. In particular:
Anyway, tentatively closing. (Feel free to reopen, but I should best unsubscribe either way). |
cabal repl
still does not work properly for test suites. If the test suite depends on the library component (which is pretty common!), we run into dependency issues.Steps to reproduce
Create the following files:
Running the specs with
cabal test
works, but runningcabal repl spec
fails:The text was updated successfully, but these errors were encountered: