Comments (12)
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.
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.
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.
from rstest.
As far as I can tell, test-generator does need a build.rs script (unless it's optional?).
from rstest.
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.
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.
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.
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.
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.
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.
@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)
- `#[once]` fixtures are unsound for types that are not `Sync` HOT 4
- clippy::duplicated_attributes warning with rust 1.79.0-nightly HOT 3
- By-reference fixtures HOT 12
- Update `rstest_reuse` docs and release new version
- `#[from(source)]` should accept path also and not just idents
- rstest_reuse: "the `async` keyword is missing from the function declaration" HOT 1
- replace return <expr>; with <expr> [needless_return] HOT 3
- Support dynamic `#[values]` HOT 1
- Feature: Optional label in the `#[case...]` HOT 1
- Dynamically set #[values(..)] HOT 1
- New test files are only recognized after `cargo clean` HOT 4
- feat: provide a cargo feature to disable the proc macro inference in #221 HOT 2
- consider adding a `wasm-bindgen` feature HOT 2
- Recommendation on choosing between different sets of `#[values(...)]`?
- Mixing `#[rstest]` and `#[serial]` breaks VS Code's IntelliSense with rust-analyzer HOT 3
- Possibility of resolving a fixture only once per test?
- Automatically test all variants of an enum HOT 1
- unused warning for case variables used by fixture #[with(var)] HOT 1
- Can #[files] use relative paths HOT 3
- destructure fixture type in template HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rstest.