"Could not execute process (never executed)" with [lib] harness = false
Closed this issue · 10 comments
http://doc.crates.io/manifest.html#configuring-a-target suggests that harness = false
can be used in the [lib]
section of Cargo.toml
. Let’s try it:
/tmp% cargo new foo
/tmp% cd foo
/tmp/foo% echo -e '[lib]\nharness=false' >> Cargo.toml
/tmp/foo% cargo test -v
Compiling foo v0.1.0 (file:///tmp/foo)
Running `rustc src/lib.rs --crate-name foo --crate-type lib -g -C metadata=9476bb3dbe366490 -C extra-filename=-9476bb3dbe366490 --out-dir /tmp/foo/target/debug --emit=dep-info,link -L dependency=/tmp/foo/target/debug -L dependency=/tmp/foo/target/debug/deps`
Running `rustc src/lib.rs --crate-name foo --crate-type lib -g --out-dir /tmp/foo/target/debug --emit=dep-info,link -L dependency=/tmp/foo/target/debug -L dependency=/tmp/foo/target/debug/deps`
Running `/tmp/foo/target/debug/foo-9476bb3dbe366490`
Could not execute process `/tmp/foo/target/debug/foo-9476bb3dbe366490` (never executed)
Caused by:
Could not execute process `/tmp/foo/target/debug/foo-9476bb3dbe366490` (never executed)
Caused by:
No such file or directory (os error 2)
--test
is indeed not passed, but --crate-type lib
still is so no executable is created.
Grepping Cargo’s source shows an example in tests/test_cargo_test.rs
where harness = false
is used in [[test]]
, which makes more sense.
So:
- The docs should show
harness = false
in a[[test]]
section, not[lib]
. harness = false
in[lib]
should probably emit a warning and be otherwise ignored, since it doesn’t work. Or make Cargo emit in error and abort.- With
harness = false
in[[bin]]
, there is no way that I can find to tell whether an executable is being built for testing or not. Maybe pass--cfg test
?
Hm yeah I think harness = false
in a library should be ignored unless Cargo passes --cfg test
which I actually wanted to do in the past.
Continuing to pass --crate-type lib
is indeed a bug, however, in any case.
I'm gonna tag this as E-easy
as this is likely a pretty easy-to-approach project for anyone looking to dive into Cargo!
Also worth documenting, as I don’t see it http://doc.crates.io/manifest.html and found out the hard way (ok, it was easily fixed and not that dramatic): when Cargo.toml
doesn’t contain any [[test]]
section, cargo test
will enumerate tests/*.rs
files and build/run an integration test crate for each of them. But as soon as you add one [[test]]
section (say, to add harness = false
to it), Cargo stops doing that enumeration and ignores the rest of the files. One has to list an explicit [[test]]
section for each of them, even if with just a name.
Going to try and tackle this
@alexcrichton Regarding your comment about passing --cfg test
if harness is set to false.
If I understood it correctly the behaviour should be:
harness = true
Default, nothing changes hereharness = false
Ignore it, but still pass--cfg test
Is that correct?
Sounds good to me!
@alexcrichton Thanks
Unfortunately this is blocked on rust-lang/rust#33670
This is unblocked.
I just got the same puzzling error in intellij-rust, and I think it may be related to shutting down an ongoing build. Running cargo run
manually works, but CLion is unable to run it after a build finishes.
In fixed it by deleting target/ and rebuilding from scratch