Crate bintest

source ·
Expand description

Testing the executables build by a bin crate.


‘cargo’ tests by default have no support for running tests on a build executable. This crate solves this.

How It Works

There are some problems to overcome the cargo limitations.

  1. Running cargo tests does not depend on the executables build, by default they are not compiled at test time.
  2. There are no standard facilities to locate and execute them in a test.

BinTest solve these problems by running ‘cargo build’ at test time, parsing its output for identifying and locating the build executables. On request it creates a std::process::Command for the executable which can be used for any further testing.

BinTest will panic on any error and not offer any error handling. This is deliberate to make things simple.


fn test() {
  // BinTest::new() will run 'cargo build' and registers all build executables
  let executables = BinTest::new();

  // List the executables build
  for (k,v) in executables.list_executables() {
    println!("{} @ {}", k, v);

  // BinTest::command() looks up executable by its name and creates a process::Command from it
  let command = executables.command("name");

  // this command can then be used for testing


See Also

The testcall crate uses this to build tests and assertions on top of the commands created by bintest.


Access to binaries build by ‘cargo build’
A process builder, providing fine-grained control over how a new process should be spawned.
Describes what to do with a standard I/O stream for a child process when passed to the stdin, stdout, and stderr methods of Command.
An owned, mutable UTF-8 path (akin to String).