Skip to content

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

Closed
@SimonSapin

Description

@SimonSapin

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    E-easyExperience: Easy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions