Skip to content

Commit b15eced

Browse files
committed
Split off case-by-case to its own crate
Which means the value-source mode is the only mode again; and for that reason the features were removed. The case-by-case mode is published as Yare on crates.io
1 parent c1df5fa commit b15eced

File tree

14 files changed

+95
-384
lines changed

14 files changed

+95
-384
lines changed

Cargo.toml

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,14 @@ authors = ["Martijn Gribnau <[email protected]>"]
55
edition = "2018"
66
license = "MIT OR Apache-2.0"
77
description = "Procedural macro which brings a compact parameterized testing implementation to Rust (inspired by JUnit @ParameterizedTest)"
8-
documentation = "https://docs.rs/parameterized"
8+
documentation = "https://docs.rs/crate/parameterized"
99
repository = "https://github.com/foresterre/parameterized"
1010
readme = "README.md"
1111
keywords = ["parameterized", "parametrized", "test", "unit-test", "junit"]
1212
categories = ["development-tools", "development-tools::testing"]
1313

1414
[dependencies]
15-
parameterized-macro = { path = "parameterized-macro", version = "0.2.0", optional = true }
16-
17-
[features]
18-
default = ["valuesource"]
19-
# default syntax based on ValueSource from JUnit 5
20-
# additional syntax in 'case-by-case' style available through the following feature
21-
valuesource = ["parameterized-macro/valuesource"]
22-
casebycase = ["parameterized-macro/casebycase"]
15+
parameterized-macro = { path = "parameterized-macro", version = "0.2.0" }
2316

2417
[workspace]
2518
members = ["parameterized-macro"]

README.md

Lines changed: 37 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,19 @@
11
# parameterized
22

3-
Procedural macro which allows you to define a test to be run with multiple (optionally different) arguments.
4-
Test cases are defined using the 'parameterized' attribute instead of the 'test' attribute.
3+
Procedural macro based parameterized testing library.
4+
Useful, when you want to run a test case with many different input sets.
5+
6+
When defining a parameterized test case, the `#[parameterized(...)]` attribute should be used instead of `#[test]`.
7+
58
This crate was inspired by JUnit `@ParameterizedTest`.
69

710
### Examples:
811

912
Additional examples can be found at the <a href="https://github.com/foresterre/parameterized-examples">parameterized-examples repository</a>,
10-
the <a href="https://github.com/foresterre/parameterized-example-usage">example-usage</a> crate in this repository and in the <a href="parameterized-macro/tests">tests</a> folder.
13+
and in the <a href="parameterized-macro/tests">tests</a> folder.
1114

1215
<br>
1316

14-
**Example: Add5**
15-
16-
```rust
17-
fn add5<T: Into<u32>>(component: T) -> u32 {
18-
component.into() + 5
19-
}
20-
21-
#[cfg(test)]
22-
mod tests {
23-
use super::*;
24-
use parameterized::parameterized;
25-
26-
ide!();
27-
28-
#[parameterized(input = {
29-
0, 1, 2
30-
}, expected = {
31-
5, 6, 7
32-
})]
33-
fn test_add5(input: u16, expected: u32) {
34-
assert_eq!(add5(input), expected);
35-
}
36-
}
37-
```
38-
3917
**Example: Fruits**
4018

4119
```rust
@@ -73,6 +51,7 @@ impl NameOf for BrambleFruit {
7351

7452
#[cfg(test)]
7553
mod tests {
54+
use super::*;
7655
use parameterized::parameterized;
7756

7857

@@ -89,62 +68,44 @@ mod tests {
8968

9069
<br>
9170

92-
### Imports
71+
**Example: Add5**
9372

94-
If you prefer not to import this library (with `use parameterized::parameterized;`) in every test module, you can put
95-
the following snippet at the top of your crate root:
9673
```rust
97-
#[cfg(test)]
98-
#[macro_use]
99-
extern crate parameterized;
100-
```
101-
102-
### Modes
74+
fn add5<T: Into<u32>>(component: T) -> u32 {
75+
component.into() + 5
76+
}
10377

104-
This library consists of two modes: `valuesource` (the default mode, which is shown above) and `casebycase`.
105-
The primary difference between these two modes is the way in which values are provided to the
106-
`parameterized` macro. In case of `valuesource`, all values of a each parameter are given in as sequence, and each
107-
sequence must have the same length, as each i-th element defines the inputs for a test case. A short example using
108-
the syntax of this mode can be found below. Note here that the name of the formal parameter within the parameterized macro
109-
should be equal to the name of the function it is defined on (`test`).
78+
#[cfg(test)]
79+
mod tests {
80+
use super::*;
81+
use parameterized::parameterized;
11082

111-
```rust
83+
ide!();
11284

113-
// generates the following test cases:
114-
// * `case_1(1, 'a')`
115-
// * `case_2(2, 'b')`
116-
#[parameterized(ints = {1,2}, chars = {'a', 'b'})]
117-
fn test(ints: i32, chars: char) {
118-
assert!(...)
85+
#[parameterized(input = {
86+
0, 1, 2
87+
}, expected = {
88+
5, 6, 7
89+
})]
90+
fn test_add5(input: u16, expected: u32) {
91+
assert_eq!(add5(input), expected);
92+
}
11993
}
12094
```
12195

122-
The second mode, `casebycase` can be used to define test cases as a sequence of input values
123-
for a single test case at a time. The example below is semantically equivalent to the above example.
124-
The syntax however differs; and note that the formal parameters now are no longer required to
125-
be the same within `parameterized` and the function. Instead, the identifiers for a sequence of values (a test case)
126-
within `parameterized` represent the name of the test case. If we would rename `case_1` to `one_and_a` and
127-
`case_2` to `two_and_b`, the identifiers of the generated test cases would change accordingly.
128-
This mode is especially useful with lots of test cases.
129-
130-
```rust
131-
// generates the following test cases:
132-
// * `case_1(1, 'a')`
133-
// * `case_2(2, 'b')`
134-
#[parameterized(case_1 = {1, 'a'}, case_2 = {'2', 'b'})]
135-
fn test(ints: i32, chars: char) {
136-
assert!(...)
137-
}
138-
```
96+
<br>
13997

140-
A mode can be selected by activating their name as a Rust feature. By default, `valuesource` is used. If you want to use
141-
`casebycase` instead, you should set `default-features` to `false` and add the `casebycase` feature. For example:
142-
```toml
143-
[dev-dependencies]
144-
parameterized = { version = "0.3", default-features = false, features = ["casebycase"] }
98+
### Imports
99+
100+
If you prefer not to import this library (with `use parameterized::parameterized;`) in every test module, you can put
101+
the following snippet at the top of your crate root:
102+
```rust
103+
#[cfg(test)]
104+
#[macro_use]
105+
extern crate parameterized;
145106
```
146107

147-
Since Rust features are used, only one mode can be used per crate.
108+
<br>
148109

149110
### IDE 'run test' intent
150111

@@ -191,14 +152,14 @@ the gutter you will find the ▶ icon next to the module. This allows you to run
191152
Note: `intellij-rust` does expand declarative macro's (with the new macro engine which can be
192153
selected in the 'settings' menu), such as this `ide!` macro.
193154

155+
<br>
194156

195157
### License
196158

197159
Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
198160
2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
199161

200-
<br>
201-
162+
<sub>
202163
Unless you explicitly state otherwise, any contribution intentionally submitted
203164
for inclusion in this crate by you, as defined in the Apache-2.0 license, shall
204-
be dual licensed as above, without any additional terms or conditions.
165+
be dual licensed as above, without any additional terms or conditions.</sub>

parameterized-macro/Cargo.toml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,7 @@ path = "tests/cases.rs"
2424
proc-macro2 = "1"
2525
quote = "1"
2626
syn = { version = "1", features = ["full"] }
27-
linked-hash-map = { version = "0.5.3", optional = true }
27+
linked-hash-map = { version = "0.5.3" }
2828

2929
[dev-dependencies]
3030
trybuild = "1.0"
31-
32-
[features]
33-
default = []
34-
valuesource = ["linked-hash-map"]
35-
casebycase = [] # use without default features

parameterized-macro/src/case_by_case/fun.rs

Lines changed: 0 additions & 60 deletions
This file was deleted.

parameterized-macro/src/case_by_case/mod.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

parameterized-macro/src/case_by_case/restructure.rs

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)