Repository navigation
project with test-only package fails both build and test #2862
Description
I would like to move my organization to stack.
In my first experiments, I noticed a behaviour that is according to me a bug.
Our projects have tests localized in separate packages:
among other to prevent test dependencies end up as development dependencies.
One can argue whether or not this is a good pattern,
but I can't change it just to get stack accepted.
On Microsoft Windows [Version 6.1.7601]
with stack [Version 1.3.0, Git revision 99b910d x86_64 hpack-0.15.0]
my multi-package project with a test-only package fails to build and to execute the test suite.
Steps to reproduce
The following multi-package project
Multiple.zip
yields for stack build
test-0.1.0.0: configure
src-0.1.0.0: build (lib)
src-0.1.0.0: copy/register
app-0.1.0.0: build (exe)
test-0.1.0.0: build
app-0.1.0.0: copy/register
Completed 3 action(s).
Log files have been written to: C:\multiple\.stack-work\logs\
-- While building package test-0.1.0.0 using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_1.24.0.0_ghc-8.0.1.exe --builddir=.stack-work\dist\b7fec021 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: C:\multiple\.stack-work\logs\test-0.1.0.0.log
Configuring test-0.1.0.0...
Cabal-simple_Z6RU0evB_1.24.0.0_ghc-8.0.1.exe: No libraries, executables,
tests, or benchmarks are enabled for package test-0.1.0.0.
This behaviour surprises me, since
- test.cabal specifies a test-suite, so tests should be enabled for package test-0.1.0.0.
- Test suite are irrelevant for a build, so build should not fail when only tests (and benchmarks) are available.
And for 'stack test'
test-0.1.0.0: configure (test)
test-0.1.0.0: build (test)
test-0.1.0.0: copy/register
Log files have been written to: C:\multiple\.stack-work\logs\
Progress: 1/2'cabal copy' failed. Error message:
-- While building package test-0.1.0.0 using:
C:\sr\setup-exe-cache\x86_64-windows\Cabal-simple_Z6RU0evB_1.24.0.0_ghc-8.0.1.exe --builddir=.stack-work\dist\b7fec021 copy
Process exited with code: ExitFailure 1
Logs have been written to: C:\multiple\.stack-work\logs\test-0.1.0.0.log
Configuring test-0.1.0.0...
Preprocessing test suite 'test-test' for test-0.1.0.0...
Cabal-simple_Z6RU0evB_1.24.0.0_ghc-8.0.1.exe: No executables and no library
found. Nothing to do.
One possible cause of this issue is:
* No module named "Main". The 'main-is' source file should usually have a header indicating that it's a 'Main' module.
I agree that test-0.1.0.0 contains no executables and no library: yet a test-suite is present that should be executed!
Note: by out commenting line 41 '- test' of stack.yaml 'stack build' and 'stack test' works perfectly.
Method of installation
- Official binary, downloaded from stackage.org
Activity
begriffs commentedon Jan 30, 2017
This just happened to me as well. Got the
No module named "Main".error on Stack 1.2.0 for a project which has only a test-suite section, no executable or library. I upgraded to Stack 1.3.2 and get the same error.Only run "cabal copy" if there are exes or lib #2862
mgsloan commentedon Feb 1, 2017
I've pushed a fix! It now skips the
cabal copystep if there's no lib or exes.Add changelog entry for #2862
PierreVDL commentedon Mar 22, 2017
Bug fix confirmed with stack 1.4 !
Thanks for the fix!
PierreVDL commentedon May 2, 2017
Just noticed the problem reappeared in stack 1.4.0
Topsii commentedon May 19, 2017
This happens for me too.
I also have windows:
PierreVDL commentedon May 24, 2017
Can this issue be reopened?
Only plan to build a target if some of its components will built #2862
mgsloan commentedon Aug 7, 2017
@PierreVDL @Topsii I've pushed a fix to master. The solution is to only mark the package as a target if some of its components are targets.