Comments (4)
I think this interaction is going to be problematic. It's not entirely clear to me in which order the proc macros are applied.
For this to work without special provisions in generic_tests
, the test_case
macro has to do its thing first and the expanded token stream should look like plain old test case functions with no arguments. But apparently the generic_tests
macro is invoked at the topmost level and receives the code with test_case
unexpanded.
I'll look into whether the macro can just instantiate the function's arguments, but I think this will require some sanitization or limitations: what to do if the argument types entangle generic parameters?
Edit: none of the above is actually a problem, read the comment below.
from generic-tests.
There would be a way to make it work with already implemented macro parameters, but it does not work as intended:
#[generic_tests::define(attrs(test_case))]
mod tests {
use super::*;
use test_case::test_case;
#[test_case(1 ; "one")]
#[test_case(2 ; "two")]
#[test_case(3 ; "three")]
fn test_blubbi<T>(x: u32) {
// test logic that uses x: {1,2,3} * T: {Foo, Bar} thus 6 test cases in total
}
// ...
}
The problem is, the test_case::test_case
import only exists on the tests
module level. In the instantiation modules, there is a use super::*;
import expanded by the macro, but the test_case
attribute name is then ambiguous between this import and the language prelude (i.e. built-in macros that can't be turned off) that also has test_case
.
I've worked around this by importing the macro as an alias name that does not collide with a built-in macro, but ran into some other problems. Bear with me, I need to debug this.
from generic-tests.
It seems test_case
exploits an undocumented and likely unstable detail of the built-in test framework. I can't import the macro under an alias and make it work, even in code that does not invoke generic-tests
.
This looks hackish to the extent I'm not sure the generic_tests
macro should do something special to accommodate it.
One thing I can think of is to allow pre-populated content in the instantiation modules, so that test_case::test_case
can be imported in each module. This somewhat defeats the idea of writing test code once and have the generic substitutions generated with minimal boilerplate, though.
from generic-tests.
Thanks for looking into this. For now I made it work using test-case
alone, which also supports generics out of the box which is good enough for my testcase
from generic-tests.
Related Issues (6)
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 generic-tests.