Skip to content

How to install library with tests #9444

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

Closed
ivanperez-keera opened this issue Nov 14, 2023 · 9 comments
Closed

How to install library with tests #9444

ivanperez-keera opened this issue Nov 14, 2023 · 9 comments

Comments

@ivanperez-keera
Copy link
Contributor

I'm using GHC 9.4.8 and cabal 3.8.

I'm trying to install copilot-language-3.17 from hackage with tests.

The obvious way cabal install copilot-language --enable-tests results in an error message:

Error: cabal: --enable-tests was specified, but tests can't be enabled in a remote package

What is currently the way to install a package with tests enabled?

@Mikolaj
Copy link
Member

Mikolaj commented Nov 14, 2023

I think you can't. I'm not sure why. Perhaps because tests are permitted to assume they are run in a checked in repo, with data files at the repo location, not the installed location, etc.

I imagine cabal get foo; unpack; cabal test might work, if there's enough of the repo contained in the Hackage package.

Or, if the test is self-contained, standalone and user-facing, perhaps turn it into an executable component, for the user to install and run.

@Mikolaj
Copy link
Member

Mikolaj commented Nov 14, 2023

for the user to install and run.

Actually, don't install, just run (cabal run). But you probably want to test the library you installed. I'm afraid, regardless if that's cabal install or cabal run, the executable will not use the installed library, but will have a library statically linked in. I think that's the case with tests, too. Unless you use v1-test, if that's a thing. Or if the executable is in another package and built with v1.

BTW, the commandline you provided won't install the library. It's only used to install executables. You probably want --lib or cabal-env (or v1, but it's mostly unmaintained) or a makefile or a shell script (which can also ensure tests are built against the installed library).

@mpickering
Copy link
Collaborator

Do you want to run the tests during the install process or also install the test executables?

@ivanperez-keera
Copy link
Contributor Author

I want to make sure I run the tests.

Ideally, I'd like to do what used to happen with:

$ cabal v1-install --enable-tests --only-dependencies
$ cabal v1-test

@gbaz
Copy link
Collaborator

gbaz commented Nov 14, 2023

I think this would need to be a feature request for v2-install that it have a flag to run test-suites as part of installation -- I don't see another way for this to work exactly as desired.

note that even in v1-install this didn't actually occur -- rather, the tests would get run on the downloaded package and entirely independently the package would get installed -- it would just so happen that produced binary artifacts would be reused between the two. the equivalent in v2 is what mikolaj suggested -- cabal get foo; unpack; cabal test; cabal install;. This sequence just makes it more explicit that the testing and the installation are actually independent.

@ulysses4ever
Copy link
Collaborator

Relevant prior discussion:

@ivanperez-keera
Copy link
Contributor Author

Running cabal test results in:

Resolving dependencies...
No tests to run for the package copilot-libraries-3.17

@gbaz
Copy link
Collaborator

gbaz commented Nov 15, 2023

right. copilot-libraries doesn't have any tests. its also a library and not an executable.

is the ask that i can cabal v2-install lib foo and then all dependencies of foo have their tests run?

@ivanperez-keera
Copy link
Contributor Author

copilot-libraries doesn't have any tests

I'm an idiot and you're right. I meant to try copilot-language. That one I cannot install with cabal install --only-dependencies --enable-tests, but I can test with cabal test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants