Crate bintest[][src]

Expand description

Testing the binaries build by a bin crate.

Description

‘cargo’ tests by default have no support for running tests on a build binary. 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 binary build, by default they are not compiled at test time.
  2. There are no standard facilities to locate and execute the build binaries in a test.

BinTest solve these problems by running ‘cargo build’ at test time, parsing its output for identifying and locating the build binaries. On request it creates a std::process::Command for the binary 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.

Example

#[test]
fn test() {
  // BinTest::new() will run 'cargo build' and registers all build binaries
  let bintest = BinTest::new();

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

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

  // this command can then be used for testing
  command.arg("help").spawn();

}

Structs

BinTest

Access to binaries build by ‘cargo build’

Command

re-exported for convinience

Stdio

re-exported for convinience