Crate filetest

source ·
Expand description

A proc macro for making test cases from a corpus of files, intended for parsing-related tests.

#[filetest::filetest("../examples/files/*")]
fn test_file(path: &std::path::Path, bytes: &[u8], text: &str) {
    assert_eq!(std::fs::read(path).unwrap(), bytes);
    assert_eq!(bytes, text.as_bytes());
}

This crate requires the proc_macro_span unstable feature, in order to support relative paths.

Arguments

Arguments passed to the function are identified by name, not by type. All references are 'static. Currently, the following three arguments are supported:

NameTypeContent
path&T where str: AsRef<T>1Absolute path to the file
bytes&[u8]File contents, as seen by include_bytes!()
text&strFile contents, as seen by include_str!()

  1. This includes str, std::path::Path, and camino::Utf8Path

Attribute Macros