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: nextest-rs/datatest-stable
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: datatest-stable-0.3.0
Choose a base ref
...
head repository: nextest-rs/datatest-stable
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref

Commits on Dec 26, 2024

  1. fix include_dir invocations

    Must pass in `$CARGO_MANIFEST_DIR`.
    sunshowers committed Dec 26, 2024
    Copy the full SHA
    6b6229a View commit details
  2. fix README.md

    cargo sync-rdme seems to eat lines that begin with `#` even if they're `cfg()`,
    which seems incorrect. This is a good workaround for now.
    sunshowers committed Dec 26, 2024
    Copy the full SHA
    afe5eb3 View commit details
  3. Copy the full SHA
    4a71a36 View commit details
  4. Copy the full SHA
    7bed1f9 View commit details
  5. Copy the full SHA
    76876cd View commit details

Commits on Dec 27, 2024

  1. Copy the full SHA
    81cac0b View commit details

Commits on Dec 29, 2024

  1. re-allow absolute paths

    Fixes #252.
    sunshowers committed Dec 29, 2024
    Copy the full SHA
    ad12f63 View commit details
  2. Copy the full SHA
    59bb4c5 View commit details
  3. make the pattern arg optional

    Use a tt-muncher to make the "pattern" argument optional.
    
    I tried adding support for reordering arguments, but the macro got pretty
    complicated and I had trouble handling the optional trailing comma. Reordering
    arguments would be much easier with a proc macro.
    sunshowers committed Dec 29, 2024
    Copy the full SHA
    e020341 View commit details
  4. [meta] prepare changelog

    sunshowers committed Dec 29, 2024
    Copy the full SHA
    59e8170 View commit details
  5. Copy the full SHA
    11a6248 View commit details
  6. add link to changelog

    sunshowers committed Dec 29, 2024
    Copy the full SHA
    872aa83 View commit details

Commits on Dec 31, 2024

  1. Copy the full SHA
    18cc5d4 View commit details

Commits on Jan 1, 2025

  1. Copy the full SHA
    37a8ea9 View commit details

Commits on Jan 2, 2025

  1. Copy the full SHA
    06e0a18 View commit details

Commits on Jan 3, 2025

  1. Copy the full SHA
    0fac5c8 View commit details

Commits on Jan 4, 2025

  1. Copy the full SHA
    3ce2730 View commit details

Commits on Jan 8, 2025

  1. Copy the full SHA
    8aa1d9c View commit details

Commits on Feb 11, 2025

  1. fix clippy warnings

    sunshowers committed Feb 11, 2025
    Copy the full SHA
    4cdf79a View commit details
  2. Copy the full SHA
    4814ecd View commit details
  3. Copy the full SHA
    2768f21 View commit details
  4. Copy the full SHA
    3df16f8 View commit details
  5. Copy the full SHA
    68434c9 View commit details
  6. Copy the full SHA
    95555b2 View commit details

Commits on Feb 13, 2025

  1. Copy the full SHA
    3dc6486 View commit details

Commits on Feb 14, 2025

  1. Copy the full SHA
    2904d2b View commit details

Commits on Feb 15, 2025

  1. Copy the full SHA
    06ee8b2 View commit details

Commits on Feb 17, 2025

  1. Copy the full SHA
    f27966b View commit details

Commits on Feb 18, 2025

  1. Copy the full SHA
    14d8085 View commit details

Commits on Feb 19, 2025

  1. Copy the full SHA
    6f333ae View commit details

Commits on Feb 20, 2025

  1. Copy the full SHA
    70504a0 View commit details
  2. Copy the full SHA
    620e0f7 View commit details

Commits on Feb 21, 2025

  1. Copy the full SHA
    98841c7 View commit details
  2. Copy the full SHA
    75309dc View commit details

Commits on Feb 22, 2025

  1. Copy the full SHA
    4550eb8 View commit details

Commits on Feb 23, 2025

  1. Copy the full SHA
    df9f653 View commit details

Commits on Feb 24, 2025

  1. Copy the full SHA
    6a3393f View commit details
  2. Copy the full SHA
    04681a8 View commit details

Commits on Feb 25, 2025

  1. Copy the full SHA
    9f58298 View commit details

Commits on Feb 26, 2025

  1. Copy the full SHA
    0203602 View commit details

Commits on Feb 27, 2025

  1. Copy the full SHA
    304b6de View commit details
  2. Copy the full SHA
    16bb9e1 View commit details

Commits on Mar 1, 2025

  1. Copy the full SHA
    626e2f9 View commit details
  2. Copy the full SHA
    48f3423 View commit details

Commits on Mar 2, 2025

  1. Copy the full SHA
    d48ef87 View commit details

Commits on Mar 4, 2025

  1. Copy the full SHA
    2525c21 View commit details
  2. Copy the full SHA
    3269356 View commit details
  3. Copy the full SHA
    dd748ac View commit details

Commits on Mar 5, 2025

  1. Copy the full SHA
    8c7c6da View commit details

Commits on Mar 7, 2025

  1. Copy the full SHA
    5473374 View commit details
Showing with 515 additions and 90 deletions.
  1. +5 −5 .github/workflows/ci.yml
  2. +2 −2 .github/workflows/coverage.yml
  3. +2 −2 .github/workflows/release.yml
  4. +21 −0 CHANGELOG.md
  5. +3 −3 Cargo.lock
  6. +2 −2 Cargo.toml
  7. +40 −22 README.md
  8. +21 −15 src/data_source.rs
  9. +40 −24 src/lib.rs
  10. +156 −9 src/macros.rs
  11. +3 −0 tests/compile-fail/empty-arg-list.rs
  12. +9 −0 tests/compile-fail/empty-arg-list.stderr
  13. +3 −0 tests/compile-fail/extra-args.rs
  14. +9 −0 tests/compile-fail/extra-args.stderr
  15. +3 −0 tests/compile-fail/incorrect-arg-in-pattern.rs
  16. +9 −0 tests/compile-fail/incorrect-arg-in-pattern.stderr
  17. +6 −0 tests/compile-fail/missing-root-comma.rs
  18. +12 −0 tests/compile-fail/missing-root-comma.stderr
  19. +5 −0 tests/compile-fail/missing-root-no-args.rs
  20. +11 −0 tests/compile-fail/missing-root-no-args.stderr
  21. +3 −0 tests/compile-fail/missing-root-no-comma.rs
  22. +9 −0 tests/compile-fail/missing-root-no-comma.stderr
  23. +6 −0 tests/compile-fail/missing-test-comma.rs
  24. +12 −0 tests/compile-fail/missing-test-comma.stderr
  25. +3 −0 tests/compile-fail/missing-test-no-comma.rs
  26. +9 −0 tests/compile-fail/missing-test-no-comma.stderr
  27. +3 −0 tests/compile-fail/pattern-not-ident.rs
  28. +9 −0 tests/compile-fail/pattern-not-ident.stderr
  29. +3 −0 tests/compile-fail/root-not-ident.rs
  30. +9 −0 tests/compile-fail/root-not-ident.stderr
  31. +3 −0 tests/compile-fail/root-out-of-order.rs
  32. +9 −0 tests/compile-fail/root-out-of-order.stderr
  33. +3 −0 tests/compile-fail/test-not-ident.rs
  34. +9 −0 tests/compile-fail/test-not-ident.stderr
  35. +3 −0 tests/compile-fail/test-out-of-order.rs
  36. +9 −0 tests/compile-fail/test-out-of-order.stderr
  37. +40 −4 tests/example.rs
  38. +1 −0 tests/files/other.json
  39. +10 −2 tests/integration.rs
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -20,13 +20,13 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2
- uses: Swatinem/rust-cache@720f7e45ccee46c12a7b1d7bed2ab733be9be5a1 # v2
- name: Lint (clippy)
run: cargo clippy --all-features --all-targets
- name: Lint (rustfmt)
run: cargo xfmt --check
- name: Install cargo-sync-rdme and just
uses: taiki-e/install-action@8484225d9734e230a8bf38421a4ffec1cc249372 # v2
uses: taiki-e/install-action@63f2419bb6a642b9973690fd13cf07b750f65635 # v2
with:
tool: cargo-sync-rdme,just
- name: Install nightly toolchain for cargo-sync-rdme
@@ -48,7 +48,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2
- uses: Swatinem/rust-cache@720f7e45ccee46c12a7b1d7bed2ab733be9be5a1 # v2
- name: Build rustdoc
run: cargo doc --all-features

@@ -67,11 +67,11 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ matrix.rust-version }}
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2
- uses: Swatinem/rust-cache@720f7e45ccee46c12a7b1d7bed2ab733be9be5a1 # v2
with:
key: ${{ matrix.rust-version }}
- name: Install tools
uses: taiki-e/install-action@8484225d9734e230a8bf38421a4ffec1cc249372 # v2
uses: taiki-e/install-action@63f2419bb6a642b9973690fd13cf07b750f65635 # v2
with:
tool: cargo-hack,just,nextest
- name: Build
4 changes: 2 additions & 2 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -23,10 +23,10 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
with:
components: llvm-tools-preview
- uses: Swatinem/rust-cache@82a92a6e8fbeee089604da2575dc567ae9ddeaab # v2
- uses: Swatinem/rust-cache@720f7e45ccee46c12a7b1d7bed2ab733be9be5a1 # v2

- name: Install tools
uses: taiki-e/install-action@8484225d9734e230a8bf38421a4ffec1cc249372 # v2
uses: taiki-e/install-action@63f2419bb6a642b9973690fd13cf07b750f65635 # v2
with:
tool: cargo-llvm-cov,just,nextest

4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -17,10 +17,10 @@ jobs:
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo release
uses: taiki-e/install-action@8484225d9734e230a8bf38421a4ffec1cc249372 # v2
uses: taiki-e/install-action@63f2419bb6a642b9973690fd13cf07b750f65635 # v2
with:
tool: cargo-release@0.25.0
- uses: taiki-e/create-gh-release-action@72d65cee1f8033ef0c8b5d79eaf0c45c7c578ce3 # v1
- uses: taiki-e/create-gh-release-action@b7abb0cf5e72cb5500307b577f9ca3fd4c5be9d2 # v1
with:
prefix: datatest-stable
changelog: CHANGELOG.md
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## [0.3.2] - 2024-12-28

### Added

- `pattern` is now optional in the `harness!` macro. If not specified, the default pattern is
`r".*"` (match all files).

### Fixed

- Restored the ability to use absolute paths as the `root` argument.

## [0.3.1] - 2024-12-25

### Fixed

Fixed documentation for `include_dir` invocations. They must typically be called
via `include_dir!("$CARGO_MANIFEST_DIR/path/to/data")`.

## [0.3.0] - 2024-12-24

### Added
@@ -62,6 +80,7 @@ Previously, the test functions supported were `fn(&Path) -> Result<()>` and `fn(
- Switched to the `fancy-regex` crate, which allows for matching against regexes with
lookahead/behind and backreferences. Thanks [@webbdays](https://github.com/webbdays) for your
first contribution!

- MSRV updated to Rust 1.66.

## [0.2.6] - 2024-04-09
@@ -143,6 +162,8 @@ There are no functional changes in this release.

(Version 0.1.0 was yanked because of a metadata issue.)

[0.3.2]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.3.2
[0.3.1]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.3.1
[0.3.0]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.3.0
[0.2.10]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.2.10
[0.2.9]: https://github.com/nextest-rs/datatest-stable/releases/tag/datatest-stable-0.2.9
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "datatest-stable"
version = "0.3.0"
version = "0.3.2"
description = "Data-driven tests that work on stable Rust"
repository = "https://github.com/nextest-rs/datatest-stable"
license = "MIT OR Apache-2.0"
@@ -36,7 +36,7 @@ libtest-mimic = "0.8.1"
walkdir = "2.5.0"

[dev-dependencies]
trybuild = "1.0.101"
trybuild = "1.0.104"

[target.'cfg(unix)'.dev-dependencies]
camino-tempfile = "1.1.1"
62 changes: 40 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ harness = false

````rust,ignore
datatest_stable::harness! {
{ test = my_test, root = "path/to/fixtures", pattern = r"^.*/*" },
{ test = my_test, root = "path/to/fixtures", pattern = r".*" },
}
````

@@ -57,9 +57,8 @@ datatest_stable::harness! {
extra `Vec<u8>` parameter is specified, the contents of the file will be loaded and passed
in as a `Vec<u8>` (erroring out if that failed).
* `root` - The path to the root directory where the input files (fixtures)
live. This path is relative to the root of the crate (the directory where
the crate’s `Cargo.toml` is located). Absolute paths are not supported, and
will panic at runtime.
live. Relative paths are resolved relative to the crate root (the directory where the crate’s
`Cargo.toml` is located).

`root` is an arbitrary expression that implements
[`Display`](https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html), such as `&str`, or a function call that
@@ -70,27 +69,34 @@ datatest_stable::harness! {

`pattern` is an arbitrary expression that implements [`Display`](https://doc.rust-lang.org/nightly/core/fmt/trait.Display.html), such as
`&str`, or a function call that returns a `String`.

`pattern` is optional, and defaults to `r".*"` (match all files).

The three parameters can be repeated if you have multiple sets of data-driven tests to be run:

````rust,ignore
datatest_stable::harness! {
{ test = testfn1, root = root1, pattern = pattern1 },
{ test = testfn2, root = root2, pattern = pattern2 },
{ test = testfn2, root = root2 },
}
````

### Relative paths
Trailing commas are optional.

### Relative and absolute paths

The `pattern` argument is tested against the **relative** path of each file,
**excluding** the `root` prefix – not the absolute path.

The `Path` and `Utf8Path` passed into the test functions are **relative** to
the root of the crate, obtained by joining `root` to the relative path of
the file.
The `Path` and `Utf8Path` passed into the test functions are created by
joining `root` to the relative path of the file.

For universality, all relative paths use `/` as the path separator,
including on Windows.
* If `root` is **relative**, the paths passed in are relative to the crate root.
* If `root` is **absolute**, the paths passed in are absolute.

For uniformity, all relative paths use `/` as the path separator,
including on Windows, and all absolute paths use the platform’s native
separator throughout.

### Examples

@@ -113,8 +119,12 @@ fn my_test_utf8(path: &Utf8Path, contents: String) -> datatest_stable::Result<()
}

datatest_stable::harness! {
{ test = my_test, root = "path/to/fixtures", pattern = r"^.*/*" },
{ test = my_test_utf8, root = "path/to/fixtures", pattern = r"^.*/*" },
{ test = my_test, root = "path/to/fixtures" },
{
test = my_test_utf8,
root = "path/to/fixtures",
pattern = r"^.*\.txt$",
},
}
````

@@ -146,7 +156,7 @@ fn my_test(path: &Path, contents: Vec<u8>) -> datatest_stable::Result<()> {
}

datatest_stable::harness! {
{ test = my_test, root = include_dir!("tests/files"), pattern = r"^.*/*" },
{ test = my_test, root = include_dir!("tests/files"), pattern = r"^.*\.json$" },
}
````

@@ -156,7 +166,8 @@ You can also use directories published as `static` items in upstream crates:
use datatest_stable::{include_dir, Utf8Path};

// In the upstream crate:
pub static FIXTURES: include_dir::Dir<'static> = include_dir!("tests/files");
pub static FIXTURES: include_dir::Dir<'static> =
include_dir!("$CARGO_MANIFEST_DIR/tests/files");

// In your test:
fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
@@ -165,13 +176,13 @@ fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
}

datatest_stable::harness! {
{ test = my_test, root = &FIXTURES, pattern = r"^.*/*" },
{ test = my_test, root = &FIXTURES },
}
````

In this case, the passed-in `Path` and `Utf8Path` are **relative** to the
root of the included directory. Like elsewhere in `datatest-stable`, these
relative paths always use forward slashes as separators, including on
In this case, the passed-in `Path` and `Utf8Path` are always **relative** to
the root of the included directory. Like elsewhere in `datatest-stable`,
these relative paths always use forward slashes as separators, including on
Windows.

Because the files don’t exist on disk, the test functions must accept their
@@ -188,17 +199,24 @@ case, you can use:
````rust
use datatest_stable::Utf8Path;

static FIXTURES: &str = "tests/files";
// In the library itself:
pub mod fixtures {
#[cfg(feature = "testing")]
pub static FIXTURES: &str = "tests/files";

static FIXTURES: include_dir::Dir<'static> = datatest_stable::include_dir!("tests/files");
#[cfg(not(feature = "testing"))]
pub static FIXTURES: include_dir::Dir<'static> =
include_dir::include_dir!("$CARGO_MANIFEST_DIR/tests/files");
}

// In the test:
fn my_test(path: &Utf8Path, contents: String) -> datatest_stable::Result<()> {
// ... write test here
Ok(())
}

datatest_stable::harness! {
{ test = my_test, root = &FIXTURES, pattern = r"^.*/*" },
{ test = my_test, root = &fixtures::FIXTURES, pattern = r"^inputs/.*$" },
}
````

36 changes: 21 additions & 15 deletions src/data_source.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ use camino::{Utf8Component, Utf8Path, Utf8PathBuf};
#[derive(Debug)]
#[doc(hidden)]
pub enum DataSource {
// This is relative to the crate root, and stored with forward slashes.
// The path has had normalize_slashes applied to it.
Directory(Utf8PathBuf),
#[cfg(feature = "include-dir")]
IncludeDir(std::borrow::Cow<'static, include_dir::Dir<'static>>),
@@ -40,7 +40,7 @@ impl DataSource {
);
match self {
DataSource::Directory(path) => Some(TestEntry {
source: TestSource::Path(rel_path_to_forward_slashes(&path.join(&rel_path))),
source: TestSource::Path(normalize_slashes(&path.join(&rel_path))),
rel_path,
}),
#[cfg(feature = "include-dir")]
@@ -83,7 +83,7 @@ fn iter_directory(root: &Utf8Path) -> impl Iterator<Item = std::io::Result<TestE
&& entry
.file_name()
.to_str()
.map_or(false, |s| !s.starts_with('.')) // Skip hidden files
.is_some_and(|s| !s.starts_with('.')) // Skip hidden files
})
})
.map(move |res| match res {
@@ -152,7 +152,7 @@ pub(crate) struct TestEntry {

impl TestEntry {
pub(crate) fn from_full_path(root: &Utf8Path, path: Utf8PathBuf) -> Self {
let path = rel_path_to_forward_slashes(&path);
let path = normalize_slashes(&path);
let rel_path =
rel_path_to_forward_slashes(path.strip_prefix(root).unwrap_or_else(|_| {
panic!("failed to strip root '{}' from path '{}'", root, path)
@@ -241,13 +241,29 @@ impl TestEntry {
}
}

#[cfg(windows)]
#[track_caller]
fn normalize_slashes(path: &Utf8Path) -> Utf8PathBuf {
if is_truly_relative(path) {
rel_path_to_forward_slashes(path)
} else {
path.as_str().replace('/', "\\").into()
}
}

#[cfg(windows)]
#[track_caller]
fn rel_path_to_forward_slashes(path: &Utf8Path) -> Utf8PathBuf {
assert!(is_truly_relative(path), "path {path} must be relative");
path.as_str().replace('\\', "/").into()
}

#[cfg(not(windows))]
#[track_caller]
fn normalize_slashes(path: &Utf8Path) -> Utf8PathBuf {
path.to_owned()
}

#[cfg(not(windows))]
#[track_caller]
fn rel_path_to_forward_slashes(path: &Utf8Path) -> Utf8PathBuf {
@@ -309,11 +325,7 @@ pub mod data_source_kinds {
let s = self.to_string();
let path = Utf8Path::new(&s);

if !is_truly_relative(path) {
panic!("data source path must be relative: '{}'", s);
}

DataSource::Directory(rel_path_to_forward_slashes(path))
DataSource::Directory(normalize_slashes(path))
}
}

@@ -347,12 +359,6 @@ pub mod data_source_kinds {
mod tests {
use super::*;

#[test]
#[should_panic = "data source path must be relative: '/absolute/path'"]
fn data_source_absolute_path_panics() {
data_source_kinds::AsDirectory::resolve_data_source("/absolute/path");
}

#[test]
fn missing_test_name() {
assert_eq!(derive_test_path("root".into(), "file", "test_name"), None);
Loading