Skip to content

Commit ac98f0f

Browse files
authored
test(recursive_oneof): Move tests to separate module (#1225)
- Move related tests to separate module - Make config dependency explicit in `build.rs`
1 parent a8208f6 commit ac98f0f

File tree

3 files changed

+41
-40
lines changed

3 files changed

+41
-40
lines changed

tests/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn main() {
5151
.compile_protos(&[src.join("nesting.proto")], includes)
5252
.unwrap();
5353

54-
config
54+
prost_build::Config::new()
5555
.compile_protos(&[src.join("recursive_oneof.proto")], includes)
5656
.unwrap();
5757

tests/src/lib.rs

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ mod default_enum_value;
7272
#[cfg(test)]
7373
mod nesting;
7474

75+
#[cfg(test)]
76+
mod recursive_oneof;
77+
7578
mod test_enum_named_option_value {
7679
include!(concat!(env!("OUT_DIR"), "/myenum.optionn.rs"));
7780
}
@@ -94,10 +97,6 @@ pub mod foo {
9497
}
9598
}
9699

97-
pub mod recursive_oneof {
98-
include!(concat!(env!("OUT_DIR"), "/recursive_oneof.rs"));
99-
}
100-
101100
/// Also for testing custom attributes, but on oneofs.
102101
///
103102
/// Unfortunately, an OneOf field generates a companion module in the .rs file. There's no
@@ -388,29 +387,6 @@ mod tests {
388387
set2.insert(msg2.field);
389388
}
390389

391-
#[test]
392-
fn test_deep_nesting_oneof() {
393-
fn build_and_roundtrip(depth: usize) -> Result<(), prost::DecodeError> {
394-
use crate::recursive_oneof::{a, A, C};
395-
396-
let mut a = Box::new(A {
397-
kind: Some(a::Kind::C(C {})),
398-
});
399-
for _ in 0..depth {
400-
a = Box::new(A {
401-
kind: Some(a::Kind::A(a)),
402-
});
403-
}
404-
405-
let mut buf = Vec::new();
406-
a.encode(&mut buf).unwrap();
407-
A::decode(buf.as_slice()).map(|_| ())
408-
}
409-
410-
assert!(build_and_roundtrip(99).is_ok());
411-
assert!(build_and_roundtrip(100).is_err());
412-
}
413-
414390
#[test]
415391
fn test_deep_nesting_group() {
416392
fn build_and_roundtrip(depth: usize) -> Result<(), prost::DecodeError> {
@@ -434,18 +410,6 @@ mod tests {
434410
assert!(build_and_roundtrip(51).is_err());
435411
}
436412

437-
#[test]
438-
fn test_recursive_oneof() {
439-
use crate::recursive_oneof::{a, A, B, C};
440-
let _ = A {
441-
kind: Some(a::Kind::B(Box::new(B {
442-
a: Some(Box::new(A {
443-
kind: Some(a::Kind::C(C {})),
444-
})),
445-
}))),
446-
};
447-
}
448-
449413
#[test]
450414
fn test_267_regression() {
451415
// Checks that skip_field will error appropriately when given a big stack of StartGroup

tests/src/recursive_oneof.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
use alloc::boxed::Box;
2+
use alloc::vec::Vec;
3+
use prost::Message;
4+
5+
include!(concat!(env!("OUT_DIR"), "/recursive_oneof.rs"));
6+
7+
#[test]
8+
fn test_recursive_oneof() {
9+
let _ = A {
10+
kind: Some(a::Kind::B(Box::new(B {
11+
a: Some(Box::new(A {
12+
kind: Some(a::Kind::C(C {})),
13+
})),
14+
}))),
15+
};
16+
}
17+
18+
#[test]
19+
fn test_deep_nesting_oneof() {
20+
fn build_and_roundtrip(depth: usize) -> Result<(), prost::DecodeError> {
21+
let mut a = Box::new(A {
22+
kind: Some(a::Kind::C(C {})),
23+
});
24+
for _ in 0..depth {
25+
a = Box::new(A {
26+
kind: Some(a::Kind::A(a)),
27+
});
28+
}
29+
30+
let mut buf = Vec::new();
31+
a.encode(&mut buf).unwrap();
32+
A::decode(buf.as_slice()).map(|_| ())
33+
}
34+
35+
assert!(build_and_roundtrip(99).is_ok());
36+
assert!(build_and_roundtrip(100).is_err());
37+
}

0 commit comments

Comments
 (0)