Skip to content

Commit b23307d

Browse files
committed
tests
Signed-off-by: Pierre Fenoll <[email protected]>
1 parent d3bdf95 commit b23307d

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

.github/workflows/ci_derive.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ jobs:
2727
with:
2828
repo-token: ${{ secrets.GITHUB_TOKEN }}
2929
- run: cargo test --features=derive,tonic
30-
- run: cargo test --features=derive_all,tonic
3130

3231
lints:
3332
name: Lints

prost-validate-tests/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ name = "harness"
1414
harness = false
1515

1616
[features]
17-
default = ["derive", "derive_all", "reflect"]
17+
default = ["derive", "reflect"]
1818
derive = []
19-
derive_all = []
2019
reflect = []
2120

2221
[dependencies]

prost-validate-tests/benches/harness.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,27 @@ fn reflect_validate() {
1616
fn derive_validate() {
1717
for (name, f) in CASES.iter() {
1818
let (message, failures) = f();
19-
match ::prost_validate::Validator::validate(message.as_ref()) {
19+
match prost_validate::Validator::validate(message.as_ref()) {
2020
Ok(_) => assert_eq!(failures, 0, "{name}: unexpected validation success"),
2121
Err(err) => assert!(failures > 0, "{name}: unexpected validation failure: {err}"),
2222
}
2323
}
2424
}
2525

26-
#[cfg(feature = "derive_all")]
26+
#[cfg(feature = "derive")]
2727
fn derive_validate_all() {
2828
for (name, f) in CASES.iter() {
2929
let (message, failures) = f();
30-
let errors = ::prost_validate::Validator::validate_all(message.as_ref());
30+
let errors = prost_validate::Validator::validate_all(message.as_ref());
31+
let res = if errors.is_empty() {
32+
"success"
33+
} else {
34+
"failure"
35+
};
3136
assert_eq!(
3237
failures as usize,
3338
errors.len(),
34-
"{name}: unexpected validation {}: {errors:?}",
35-
if errors.is_empty() {
36-
"success"
37-
} else {
38-
"failure"
39-
}
39+
"{name}: unexpected validation {res}: {errors:?}"
4040
);
4141
}
4242
}
@@ -46,7 +46,7 @@ fn criterion_benchmark(c: &mut Criterion) {
4646
c.bench_function("harness reflect", |b| b.iter(reflect_validate));
4747
#[cfg(feature = "derive")]
4848
c.bench_function("harness derive", |b| b.iter(derive_validate));
49-
#[cfg(feature = "derive_all")]
49+
#[cfg(feature = "derive")]
5050
c.bench_function("harness derive_all", |b| b.iter(derive_validate_all));
5151
}
5252

prost-validate-tests/src/test_pbjson_cases.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ macro_rules! test_cases {
3434
Ok(_) => assert_eq!(failures, 0, "unexpected validation success"),
3535
}
3636
}
37+
38+
#[cfg(feature = "derive")]
39+
#[test]
40+
fn derive_all() {
41+
let (message, failures) = crate::cases_pbjson::CASES.get(stringify!($name)).unwrap()();
42+
let errs = ValidatorDerive::validate_all(message.as_ref());
43+
let res = errs.is_empty().then(|| "success").unwrap_or("failure");
44+
assert_eq!(
45+
failures as usize,
46+
errs.len(),
47+
"{}: unexpected validation {res}: {errs:?}",
48+
stringify!($name),
49+
);
50+
}
3751
}
3852
)*
3953
}

0 commit comments

Comments
 (0)