#unit-testing #test-cases #case #unit #directory

nightly macro filetest

Macro that creates test cases for each file in a directory

3 releases

0.1.2 Oct 18, 2023
0.1.1 Sep 26, 2023
0.1.0 Sep 26, 2023

#690 in Testing

Download history 6/week @ 2024-02-19 6/week @ 2024-02-26 56/week @ 2024-04-01

56 downloads per month

MIT/Apache

8KB
120 lines

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:

Name Type Content
path str: AsRef<T>[^path] Absolute path to the file
bytes &[u8] File contents, as seen by include_bytes!()
text &str File contents, as seen by include_str!()

[^path]: This includes str, std::path::Path, and camino::Utf8Path.


lib.rs:

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:

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

[^path]: This includes str, std::path::Path, and camino::Utf8Path.

Dependencies

~0.4–0.9MB
~20K SLoC