grrs-tutorial 0.1.0

Basic implementation of this tutorial: https://rust-cli.github.io/book/
Documentation
use assert_cmd::cargo::*;
use predicates::prelude::*;
use assert_fs::fixture::FileWriteStr;


#[test]
fn find_a_match() {
    let mut result = Vec::new();
    // Don't mess with this string in  ANY way (except for replacing the
    // \n with an actual newline, but no adding spaces to make 'em line up)
    grrs_tutorial::find_matches("lorem ipsum\ndolor sit amet",
        "lorem",
        &mut result);
    assert_eq!(result, b"lorem ipsum\n");
}

// Again, we must return this 'cause one intermediate thing, 
// SOMEWHERE in here, (o wait the '?') causes the fn to return.
#[test] fn file_doesnt_exist() -> Result<(), Box<dyn std::error::Error>> {
    let mut cmd = cargo_bin_cmd!("grrs-tutorial");
    // Now don't ever *add* this file, OK!
    cmd.arg("foobar").arg("test/file/doesnt/exist");
    cmd.assert()
        .failure()
        // This is coupled to our error message, which could change...
        .stderr(predicate::str::contains("could not read file"));

    Ok(())
}

#[test]
fn find_content_in_file() -> Result<(), Box<dyn std::error::Error>> {
    // This'll be in the env's temp_dir; which I think is high-level, like /usr
    let file = assert_fs::NamedTempFile::new("sample.txt")?;
    file.write_str("A test\nActual content\nMore content\nAnother test")?;

    let mut cmd = cargo_bin_cmd!("grrs-tutorial");
    cmd.arg("test").arg(file.path());
    cmd.assert()
        .success()
        .stdout(predicate::str::contains("A test\nAnother test"));

    Ok(())
}