assertables

Module assert_fs_read_to_string

Source
Expand description

Assert for comparing file system path contents.

These macros help with file system paths, such as disk files, Path, PathBuf, the trait AsRef<Path>, and anything that is readable via ::std::fs::read_to_string(…). See tutorial below.

Compare a path with another path:

Compare a path with an expression:

Compare a path with its contents:

§Example

use assertables::*;
use std::io::Read;

let a ="alfa.txt";
let b = "alfa.txt";
assert_fs_read_to_string_eq!(&a, &b);

§Tutorial

Rust has a concept of a “file system” and a function “read to string” that makes it easy to read a file to a string:

let path = "alfa.txt";
let string = ::std::fs::read_to_string(path);

Rust can compare a file’s string to another file’s string:

let path1 = "alfa.txt";
let path2 = "bravo.txt";
let a_string = ::std::fs::read_to_string(path1).unwrap();
let b_string = ::std::fs::read_to_string(path2).unwrap();
assert_ne!(a_string, b_string);

The assertables crate provides macros that do the reading for you:

let path1 = "alfa.txt";
let path2 = "bravo.txt";
assert_fs_read_to_string_ne!(path1, path2);

Modules§