Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: la10736/rstest
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.24.0
Choose a base ref
...
head repository: la10736/rstest
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.25.0
Choose a head ref
  • 6 commits
  • 14 files changed
  • 3 contributors

Commits on Jan 1, 2025

  1. Prepare develop

    la10736 committed Jan 1, 2025
    Copy the full SHA
    154d0b0 View commit details

Commits on Jan 17, 2025

  1. Append generated test macro so next test macros are aware of it

    This way test macros following `#[rstest]` can decide whether or not to
    generate test macro to avoid duplicate test runs.
    
    It is an attempt to improve capabilities among test macros. Currently,
    following test from [googletest](https://github.com/google/googletest-rust/blob/21f2948684847922a416252b8118e3eada8e29d6/integration_tests/src/google_test_with_rstest.rs#L52-L57)(`main` branch at 2025-01-16) will run twice.
    
    ```rust
    #[rstest]
    #[case(1)]
    #[gtest]
    fn paramterised_test_should_work_with_rstest_first(#[case] value: u32) -> Result<()> {
        verify_that!(value, eq(value))
    }
    ```
    
    See: tokio-rs/tokio#6497, d-e-s-o/test-log#46, frondeus/test-case#143, kezhuw/stuck#53.
    Refs: rust-lang/rust#67839, rust-lang/rust#82419.
    kezhuw authored and la10736 committed Jan 17, 2025
    Copy the full SHA
    e0b735e View commit details

Commits on Mar 2, 2025

  1. feat: add include_str and include_bytes file input behaviour

    Adds the ability to set the file input format using the
    `#[file_mode = "..."]` attribute. The attribute accepts `path`,
    `include_str`, and `include_bytes`. `path` is the default behaviour,
    `include_str` and `include_bytes` pass the file contents instead of the
    path of the file.
    
    Closes #295.
    lucascool12 authored and la10736 committed Mar 2, 2025
    Copy the full SHA
    8551eb8 View commit details
  2. Avoid concurrent manifest changes in integration tests

    la10736 committed Mar 2, 2025
    Copy the full SHA
    f570b06 View commit details
  3. Make clippy happy

    la10736 committed Mar 2, 2025
    Copy the full SHA
    eb1f228 View commit details
  4. Prepare release

    la10736 committed Mar 2, 2025
    Copy the full SHA
    8d80cea View commit details
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog

## [0.25.0] 2025/3/2

### Changed

- Append generated test macro so next test macros are aware of it
(see [#291](https://github.com/la10736/rstest/pull/291) thanks to @kezhuw).

### Add

- Added a `#[mode = ...]` attribute to be used with the `#[files(...)]` attribute to change the way
the files get passed to the test.
(see [#295](https://github.com/la10736/rstest/issues/295) thanks to @lucascool12)

## [0.24.0] 2025/1/1

### Changed
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ following lines to your `Cargo.toml` file:

```toml
[dev-dependencies]
rstest = "0.24.0"
rstest = "0.25.0"
```

### Features
1 change: 0 additions & 1 deletion checkoutlist.md
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@
- [ ] Check README
- [ ] **Commit**
- [ ] Create tag (Use github release)
- [ ] prepare deploy `cargo publish --dry-run`
- [ ] deploy:
- [ ] `cargo publish -p rstest_macros --dry-run`
- [ ] `cargo publish -p rstest_macros`
2 changes: 1 addition & 1 deletion playground/Cargo.toml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ lazy_static = "1.4.0"

[dependencies.rstest]
path = "../rstest"
version = "0.24.0"
version = "0.25.0"

[dependencies.rstest_reuse]
path = "../rstest_reuse"
6 changes: 3 additions & 3 deletions rstest/Cargo.toml
Original file line number Diff line number Diff line change
@@ -13,7 +13,7 @@ name = "rstest"
readme = "README.md"
repository = "https://github.com/la10736/rstest"
rust-version = "1.70.0"
version = "0.24.0"
version = "0.25.0"

[features]
async-timeout = [
@@ -29,13 +29,13 @@ default = ["async-timeout", "crate-name"]
[dependencies]
futures-timer = { version = "3.0.3", optional = true }
futures-util = { version = "0.3.30", optional = true }
rstest_macros = { version = "0.24.0", path = "../rstest_macros", default-features = false }
rstest_macros = { version = "0.25.0", path = "../rstest_macros", default-features = false }

[dev-dependencies]
actix-rt = "2.9.0"
async-std = { version = "1.13.0", features = ["attributes"] }
lazy_static = "1.5.0"
mytest = { package = "rstest", version = "0.23.0", default-features = false }
mytest = { package = "rstest", version = "0.24.0", default-features = false }
pretty_assertions = "1.4.1"
rstest_reuse = { path = "../rstest_reuse" }
rstest_test = { path = "../rstest_test" }
39 changes: 38 additions & 1 deletion rstest/src/lib.rs
Original file line number Diff line number Diff line change
@@ -617,7 +617,7 @@ pub use rstest_macros::fixture;
/// - Arguments Attributes:
/// - [`#[case]`](#test-parametrized-cases) define an argument parametrized by test cases
/// - [`#[values(...)]`](#values-lists) define an argument that can be a list of values
/// - [`#[files(...)]`-`#[exclude(...)]`-`#[base_dir = ... ]`](#files-path-as-input-arguments)
/// - [`#[files(...)]`-`#[exclude(...)]`-`#[base_dir = ... ]`-`#[mode = ...]`](#files-path-as-input-arguments)
/// define an argument that can be a list of path based on a glob pattern
/// - [`#[from(...)]`-`#[with(...)]`](#injecting-fixtures) handling injected fixture
/// - [`#[future]`](#async) implement future boilerplate argument
@@ -1032,6 +1032,43 @@ pub use rstest_macros::fixture;
/// }
/// ```
///
/// ### `#[mode = ...]`
///
/// Using the `#[mode = ...]` attribute on an argument tagged with
/// `#[files(...)]` and friends will set the way the file is passed as an argument.
/// It accepts the following arguments with the following behaviour:
///
/// - `path`: the default behaviour, passes each file path as a [PathBuf][std::path::PathBuf].
/// - `str`: passes the contents of each file as a [&str][str] using [include_str].
/// - `bytes`: passes the contents of each files as a `&[u8]` using [include_bytes].
///
/// Trying to pass directories as arguments will cause a compile error when using `str` and
/// `bytes`.
///
/// ```
/// # use rstest::rstest;
/// #[rstest]
/// fn for_each_path(
/// #[files("src/**/*.rs")] #[exclude("test")] #[mode = path] path: PathBuf
/// ) {
/// assert!(contents.len() >= 0)
/// }
///
/// #[rstest]
/// fn for_each_txt_file(
/// #[files("src/**/*.rs")] #[exclude("test")] #[mode = str] contents: &str
/// ) {
/// assert!(contents.len() >= 0)
/// }
///
/// #[rstest]
/// fn for_each_bin_file(
/// #[files("src/**/*.rs")] #[exclude("test")] #[mode = bytes] contents: &[u8]
/// ) {
/// assert!(contents.len() >= 0)
/// }
/// ```
///
/// ## Use Parametrize definition in more tests
///
/// If you need to use a test list for more than one test you can use
38 changes: 38 additions & 0 deletions rstest/tests/resources/rstest/files.rs
Original file line number Diff line number Diff line change
@@ -18,6 +18,22 @@ fn start_with_name(
assert!(contents.starts_with(name.to_str().unwrap()))
}

#[rstest]
fn start_with_name_file_mode(
#[files("files/**/*.txt")]
#[exclude("exclude")]
#[files("../files_test_sub_folder/**/*.txt")]
#[mode = path]
path: PathBuf,
) {
let name = path.file_name().unwrap();
let mut f = File::open(&path).unwrap();
let mut contents = String::new();
f.read_to_string(&mut contents).unwrap();

assert!(contents.starts_with(name.to_str().unwrap()))
}

#[rstest]
fn start_with_name_with_include(
#[files("files/**/*.txt")]
@@ -91,6 +107,28 @@ fn env_vars_base_dir(
assert!(contents.starts_with(name.to_str().unwrap()))
}

#[rstest]
fn include_str(
#[files("files/**/*.txt")]
#[exclude("exclude")]
#[files("../files_test_sub_folder/**/*.txt")]
#[mode = str]
contents: &str,
) {
assert!(contents.len() != 0)
}

#[rstest]
fn include_bytes(
#[files("files/**/*.txt")]
#[exclude("exclude")]
#[files("../files_test_sub_folder/**/*.txt")]
#[mode = bytes]
contents: &[u8],
) {
assert!(contents.len() != 0)
}

mod module {
#[rstest::rstest]
fn pathbuf_need_not_be_in_scope(
18 changes: 18 additions & 0 deletions rstest/tests/rstest/mod.rs
Original file line number Diff line number Diff line change
@@ -84,6 +84,18 @@ fn files() {
.ok("ignore_missing_env_vars::path_3_files_element_2_txt")
.ok("ignore_missing_env_vars::path_4_files_element_3_txt")
.ok("ignore_missing_env_vars::path_5_files_sub_sub_dir_file_txt")
.ok("include_bytes::contents_1__UP_files_test_sub_folder_from_parent_folder_txt")
.ok("include_bytes::contents_2_files_element_0_txt")
.ok("include_bytes::contents_3_files_element_1_txt")
.ok("include_bytes::contents_4_files_element_2_txt")
.ok("include_bytes::contents_5_files_element_3_txt")
.ok("include_bytes::contents_6_files_sub_sub_dir_file_txt")
.ok("include_str::contents_1__UP_files_test_sub_folder_from_parent_folder_txt")
.ok("include_str::contents_2_files_element_0_txt")
.ok("include_str::contents_3_files_element_1_txt")
.ok("include_str::contents_4_files_element_2_txt")
.ok("include_str::contents_5_files_element_3_txt")
.ok("include_str::contents_6_files_sub_sub_dir_file_txt")
.ok("module::pathbuf_need_not_be_in_scope::path_1_files__ignore_me_txt")
.ok("module::pathbuf_need_not_be_in_scope::path_2_files_element_0_txt")
.ok("module::pathbuf_need_not_be_in_scope::path_3_files_element_1_txt")
@@ -96,6 +108,12 @@ fn files() {
.ok("start_with_name::path_4_files_element_2_txt")
.ok("start_with_name::path_5_files_element_3_txt")
.ok("start_with_name::path_6_files_sub_sub_dir_file_txt")
.ok("start_with_name_file_mode::path_1__UP_files_test_sub_folder_from_parent_folder_txt")
.ok("start_with_name_file_mode::path_2_files_element_0_txt")
.ok("start_with_name_file_mode::path_3_files_element_1_txt")
.ok("start_with_name_file_mode::path_4_files_element_2_txt")
.ok("start_with_name_file_mode::path_5_files_element_3_txt")
.ok("start_with_name_file_mode::path_6_files_sub_sub_dir_file_txt")
.ok("start_with_name_with_include::path_1_files__ignore_me_txt")
.ok("start_with_name_with_include::path_2_files_element_0_txt")
.ok("start_with_name_with_include::path_3_files_element_1_txt")
4 changes: 2 additions & 2 deletions rstest_macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"
name = "rstest_macros"
repository = "https://github.com/la10736/rstest"
rust-version = "1.70.0"
version = "0.24.0"
version = "0.25.0"

[lib]
proc-macro = true
@@ -44,7 +44,7 @@ actix-rt = "2.9.0"
async-std = { version = "1.13.0", features = ["attributes"] }
maplit = "1.0.2"
pretty_assertions = "1.4.1"
rstest = { version = "0.23.0", default-features = false }
rstest = { version = "0.24.0", default-features = false }
rstest_reuse = { path = "../rstest_reuse" }
rstest_test = { path = "../rstest_test" }

Loading