Giter Site home page Giter Site logo

Comments (12)

la10736 avatar la10736 commented on September 5, 2024 1

I've already started to implement it but I can work on it just 2 hours for week ... and not every week 😢

Is quite simple to implement the base implementation for the following example

#[rstest]
fn test(#[files("glob_path")] path: PathBuf) {
    ... generate a test for each file 
}

Later I'll extend the syntax to handle

  • sequence of glob
  • #[exclude("glob_path_to exclude")]

from rstest.

la10736 avatar la10736 commented on September 5, 2024 1

I already thought about this. My Idea is to try to implement something like this but is not trivial because the deserialization code should be called by procedural macro....

from rstest.

la10736 avatar la10736 commented on September 5, 2024 1

I decided to close this ticket as completed. I'll open a new ones for creating tests from json, csv, yaml and xml (do somebody use it in a nowadays?) files.
@ju1ius I took a look to html5lib-test files and the only Idea that I have is that the map function should be an external script/application that return a serialized list of test (bytes or strings): we can think about something to compile it at compile time but really and I don't love this kind of solutions.

from rstest.

la10736 avatar la10736 commented on September 5, 2024

from rstest.

jpmckinney avatar jpmckinney commented on September 5, 2024

As far as I can tell, test-generator does need a build.rs script (unless it's optional?).

from rstest.

la10736 avatar la10736 commented on September 5, 2024

Unfortunately build script is not optional 😢 . As far as I know it is not possible to access to something else than the annotated block from procedural macro.

from rstest.

GeeWee avatar GeeWee commented on September 5, 2024

Seems like you should be able to access the filesystem? - however getting the path resolution to work might be tricky. I haven't tried this myself though.

from rstest.

ForsakenHarmony avatar ForsakenHarmony commented on September 5, 2024

the crate testing does it without a build script
https://rustdoc.swc.rs/testing/attr.fixture.html

include_dir also does something similar

from rstest.

la10736 avatar la10736 commented on September 5, 2024

Ok, I see the trick

    let base_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").expect(
        "#[fixture] requires CARGO_MANIFEST_DIR because it's relative to cargo manifest directory",
    ));

It seams feasible to use this trick to generate a value list.

Thanks very much to point it.... I don't have too much time to work on it: a PR would be really appreciated 😄

from rstest.

jpmckinney avatar jpmckinney commented on September 5, 2024

Here's the relevant file for the #[fixture("glob")] macro in the testing crate: https://github.com/swc-project/swc/blob/main/crates/testing_macros/src/lib.rs

from rstest.

la10736 avatar la10736 commented on September 5, 2024

Ok, I completed the first implementation sketch
https://github.com/la10736/rstest/tree/values_from_files

In playground crate you'll find an example of how to use it. If somebody can try it would be really appreciated. THX

from rstest.

ju1ius avatar ju1ius commented on September 5, 2024

@la10736 Hi, this is a great step forward ! 👍🏻

However this does not cover the case where there can be several test cases per file.

For example, let's say we're writing an HTML parser and we want to use the official Web Platform Tests repository for that (html5lib-tests, which provides language-agnostic machine-readable test cases).

In this case we'd need an attribute accepting a glob and a mapping function type Mapper<T> = Fn(&Path) -> Vec<T> which would allow calling an #[rstest]-attributed function once per T:

#[rstest]
// The name is probably not right but you get the idea
#[files_mapped_by("tests/**/*.test", map_file)]
fn some_test(case: Testcase) {
  assert_passes!(case)
}

struct TestCase { /* ... */ }

fn map_file(path: &Path) -> Vec<TestCase> {
  todo!()
}

I don't know if it's even possible in current Rust but I'm mentioning it because I've been in this situation a few times and so far I haven't been able to find a library that can handle this.

from rstest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.