[][src]Struct cli_test_dir::TestDir

pub struct TestDir { /* fields omitted */ }

This code is inspired by the WorkDir pattern that BurntSushi uses to test CLI tools like ripgrep and xsv.

Methods

impl TestDir[src]

pub fn new(bin_name: &str, test_name: &str) -> TestDir[src]

Create a new TestDir for the current test. You must specify bin_name (the name of a binary built by the current crate) and test_name (a unique name for the current test).

If our output directory exists from a previous test run, it will be deleted.

pub fn cmd(&self) -> Command[src]

Return a std::process::Command object that can be used to execute the binary.

pub fn path<P: AsRef<Path>>(&self, path: P) -> PathBuf[src]

Construct a path relative to our test directory.

let testdir = TestDir::new("touch", "path_builds_paths");
let mut cmd = testdir.cmd();
cmd
  .arg("example.txt")
  .expect_success();
assert!(testdir.path("example.txt").exists());

pub fn src_path<P: AsRef<Path>>(&self, path: P) -> PathBuf[src]

Return a path relative to the source directory of the current crate. Useful for finding fixtures.

pub fn create_file<P, S>(&self, path: P, contents: S) where
    P: AsRef<Path>,
    S: AsRef<[u8]>, 
[src]

Create a file in our test directory with the specified contents.

pub fn expect_path<P: AsRef<Path>>(&self, path: P)[src]

If path does not point to valid path, fail the current test.

pub fn expect_no_such_path<P: AsRef<Path>>(&self, path: P)[src]

If path does not point to valid path, fail the current test.

pub fn expect_file_contents<P, S>(&self, path: P, expected: S) where
    P: AsRef<Path>,
    S: AsRef<[u8]>, 
[src]

Verify that the file contains the specified data.

pub fn expect_contains<P>(&self, path: P, pattern: &str) where
    P: AsRef<Path>, 
[src]

Verify that the contents of the file match the specified pattern. Someday this should support std::str::pattern::Pattern so that we can support both strings and regular expressions, but that hasn't been stabilized yet.

pub fn expect_does_not_contain<P>(&self, path: P, pattern: &str) where
    P: AsRef<Path>, 
[src]

Verify that the contents of the file do not match the specified pattern. Someday this should support std::str::pattern::Pattern so that we can support both strings and regular expressions, but that hasn't been stabilized yet.

Auto Trait Implementations

impl Send for TestDir

impl Sync for TestDir

Blanket Implementations

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.