3 stable releases

1.1.1 Feb 8, 2025
1.1.0 Jan 21, 2025
1.0.0 Jan 19, 2025

#2730 in Procedural macros

Download history 4/week @ 2025-02-18 9/week @ 2025-02-25 3/week @ 2025-03-04 97/week @ 2025-03-11 144/week @ 2025-03-18 348/week @ 2025-03-25 63/week @ 2025-04-01 85/week @ 2025-04-08 376/week @ 2025-04-15 277/week @ 2025-04-22 196/week @ 2025-04-29 19/week @ 2025-05-06 68/week @ 2025-05-13 62/week @ 2025-05-20 28/week @ 2025-05-27 65/week @ 2025-06-03

227 downloads per month
Used in rfs_tester

MIT/Apache

8KB
62 lines

rfs_test_macro

Crates.io License

rfs_test_macro is a attribute macro designed to simplify the configuration of test units for the rfs_tester crate since v0.3.1. It provides an easy-to-use interface for setting up and managing filesystem tests.

Overview

The rfs_tester crate creates a temporary directory for running filesystem tests and automatically cleans it up after the tests are completed. The rfs_test_macro crate provides a macro that simplifies the process of configuring and running these tests.

Usage

Add rfs_test_macro to your Cargo.toml:

[dependencies]
rfs_test_macro = "1.1.1"

Then, use the macro in your test files:

const CONFIG: &str = r#"---
    - !directory
        name: test
            content:
                - !link
                    name: file_link.txt
                    target: LICENSE-MIT
"#;

#[rfs_test(config = CONFIG, start_point = ".")]
fn link_creation_test(dirname: &str) -> std::io::Result<()> {
    let link_path = format!("{dirname}/file_link.txt");
    let meta = fs::metadata(link_path)?;
    assert!(meta.is_symlink());
    Ok(())
}

You can specify config inline:

#[rfs_test(
    config = r#"---
    - !directory
        name: test
        content:
          - !file
              name: test.txt
              content:
                !inline_text "Hello, world!"
    "#,
    start_point = "."
)]
fn file_creation_test_with_macro(dirname: &str) -> std::io::Result<()> {
    let file_path = format!("{}/test.txt", dirname);
    let content = std::fs::read_to_string(file_path)?;
    assert_eq!(content, "Hello, world!");
    Ok(())
}

The macro will handle the setup and teardown of the temporary directory, allowing you to focus on writing your test logic.

Features

  • Easy Configuration: Simplifies the setup of filesystem tests.

  • Automatic Cleanup: Ensures that temporary directories are removed after tests complete.

  • Seamless Integration: Works seamlessly with the rfs_tester crate.

License

This project is licensed under either of the following licenses:

  • MIT License (LICENSE-MIT)

  • Apache License, Version 2.0 (LICENSE-APACHE)

at your option.

Contributing

Contributions are welcome! If you'd like to contribute, please open an issue or submit a pull request.

Dependencies

~190–620KB
~15K SLoC