3个版本
| 0.1.2 | 2023年10月18日 |
|---|---|
| 0.1.1 | 2023年9月26日 |
| 0.1.0 | 2023年9月26日 |
#785 在 测试
8KB
120 行
一个进程宏,用于从文件集合中创建测试用例,适用于解析相关测试。
#[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());
}
此crate需要proc_macro_span不稳定特性,以支持相对路径。
参数
传递给函数的参数通过名称识别,而不是通过类型。所有引用都是'static。目前支持以下三个参数
| 名称 | 类型 | 内容 |
|---|---|---|
path |
str: AsRef<T>[^path] |
文件的绝对路径 |
bytes |
&[u8] |
文件内容,由include_bytes!()查看 |
text |
&str |
文件内容,由include_str!()查看 |
[^path]: 这包括str、std::path::Path和camino::Utf8Path。
lib.rs:
一个进程宏,用于从文件集合中创建测试用例,适用于解析相关测试。
#[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());
}
此crate需要proc_macro_span不稳定特性,以支持相对路径。
参数
传递给函数的参数通过名称识别,而不是通过类型。所有引用都是'static。目前支持以下三个参数
| 名称 | 类型 | 内容 |
|---|---|---|
path |
&T where str: AsRef<T>[^path] |
文件的绝对路径 |
bytes |
&[u8] |
文件内容,由include_bytes!()查看 |
text |
&str |
文件内容,由include_str!()查看 |
[^path]: 这包括str、std::path::Path和camino::Utf8Path。
依赖
~0.4–0.8MB
~19K SLoC