openlang

How can integration tests execute a different workspace crate's binary?

Within a multi-crate workspace, how can a crate's integration tests require and run another crate's exectuable target, rather than its library target?

Here's the workspace structure:

workspace/
├── rillmere_probe/
│   └── tests/check.rs
└── rillmere_exec/
    ├── src/lib.rs
    └── src/main.rs

The rillmere_probe crate lists rillmere_exec as a dev-dependency. Its tests also need to launch rillmere_exec's binary. Previously this worked fine. However, the build-layout-v2 change in rust-nightly rearranged things, leaving assert_cmd-2.1.3 unable to locate rillmere_exec's executable target. The diagnostic from assert_cmd-2.2.2 is clearer: CARGO_BIN_EXE_rillmere_exec is unset. Reading that makes me wonder whether assert_cmd supports this situation at all. I can't imagine nobody else has run into it. Has anyone found a solution?

The conversation continues 4

Follow the reasoning
  1. Permalink

    I'm afraid the choices are limited to these

    -

    Shift as much as you can from main.rs into lib.rs (afaik that's already typical in serious projects). Let main.rs merely invoke it. You could even leave main.rs calling a single line :v, making the code easier for another project to use

    -

    Test it manually by compiling the executable, starting it and inspecting errors through std::command

  2. Permalink

    Oh, excellent! That's precisely the feature I'm looking for. Requiring nightly for this specific integration test is fine with me. I'd still like stable Rust to compile everything else in the crate, though. That leaves working out how to omit this test with a stable compiler. Perhaps the whole test will need a crate of its own. Less than ideal, but workable. I'd rather do that than relocate everything from my binary into the library.

  3. Permalink

    Requiring nightly for this specific integration test is fine with me

    artifact dependencies are unstable functionality in cargo, rather than in the rustc compiler.

    sadly, cargo manifests have no equivelent of a conditional compilation flag, so enabling that unstable functionality just for an individual integration test while leaving the package's remaining crates usable by stable cargo isn't possible, since stable cargo cannot even read that manifest.

    using artifact dependencies therefore means putting the integration-test crate in a seperate package (actually, a separate workspace), giving it a Cargo.toml distinct from those belonging to the remaining packages.

Other sides of the same question

  1. Reducing docker-compose console noise

    Several of my containers produce hundreds upon hundreds of output lines when docker-compose up starts all the services in my…

    Replies 3Latest activity bash
  2. Could D produce Python extension modules rather than using C?

    Apparently D can link against C. I want to write a Python extension module using D. Is there a reason this approach could nev…

    Replies 2Latest activity d
  3. Micro plugins declared through Nix?🤔

    With python we can write this: Python.withPackages (q: with q; [ fastapi ]) Is an equivalent mechanism available for the Micr…

    Replies 3Latest activity nix