Skip to content
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

"Could not execute process (never executed)" with [lib] harness = false #2305

Closed
SimonSapin opened this issue Jan 22, 2016 · 10 comments · Fixed by #2795
Closed

"Could not execute process (never executed)" with [lib] harness = false #2305

SimonSapin opened this issue Jan 22, 2016 · 10 comments · Fixed by #2795
Labels
E-easy Experience: Easy

Comments

@SimonSapin
Copy link
Contributor

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?
@alexcrichton
Copy link
Member

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.

@alexcrichton alexcrichton added the E-easy Experience: Easy label Jan 23, 2016
@alexcrichton
Copy link
Member

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!

@SimonSapin
Copy link
Contributor Author

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.

@TheNeikos
Copy link
Contributor

Going to try and tackle this

@TheNeikos
Copy link
Contributor

@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 here
  • harness = false Ignore it, but still pass --cfg test

Is that correct?

@alexcrichton
Copy link
Member

Sounds good to me!

@TheNeikos
Copy link
Contributor

@alexcrichton Thanks

@alexcrichton
Copy link
Member

Unfortunately this is blocked on rust-lang/rust#33670

@sanxiyn
Copy link
Member

sanxiyn commented Jun 20, 2016

This is unblocked.

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Jun 20, 2016
Now that this is fixed upstream, we can actually add a test for this!

Closes rust-lang#2305
bors added a commit that referenced this issue Jun 21, 2016
Fix `harness = false` on `[lib]` sections

Now that this is fixed upstream, we can actually add a test for this!

Closes #2305
alexcrichton added a commit to alexcrichton/cargo that referenced this issue Jun 21, 2016
Now that this is fixed upstream, we can actually add a test for this!

Closes rust-lang#2305
bors added a commit that referenced this issue Jun 21, 2016
Fix `harness = false` on `[lib]` sections

Now that this is fixed upstream, we can actually add a test for this!

Closes #2305
@MightyPork
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Experience: Easy
Projects
None yet
5 participants