Skip to content

Commit 334b006

Browse files
Merge pull request #408 from Vlad-Shcherbina/tests
Fix broken tests (#306)
2 parents f98b232 + b6a3b08 commit 334b006

File tree

3 files changed

+25
-21
lines changed

3 files changed

+25
-21
lines changed

tests/tests/bigints.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,9 @@ pub enum EnumWithInlineStructWithBigInt {
6060

6161
#[test]
6262
fn test_bigint_types() {
63-
// TODO: Fix errors
64-
for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::<T>(&Typescript::default()).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())));
65-
for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::<T>(&Typescript::new()).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())));
66-
for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::<T>(&Typescript::new().bigint(BigIntExportBehavior::Fail)).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())));
63+
for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::<T>(&Typescript::default()).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())));
64+
for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::<T>(&Typescript::new()).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())));
65+
for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::<T>(&Typescript::new().bigint(BigIntExportBehavior::Fail)).map_err(|e| e.to_string()), Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())));
6766

6867
for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::<T>(&Typescript::new().bigint(BigIntExportBehavior::String)).map_err(|e| e.to_string()), Ok("string".into())));
6968
for_bigint_types!(T -> |name| assert_eq!(crate::ts::inline::<T>(&Typescript::new().bigint(BigIntExportBehavior::Number)).map_err(|e| e.to_string()), Ok("number".into())));
@@ -72,22 +71,22 @@ fn test_bigint_types() {
7271
// // // Check error messages are working correctly -> These tests second for `ExportPath` which is why they are so comprehensive
7372
assert_eq!(
7473
crate::ts::inline::<StructWithBigInt>(&Typescript::default()).map_err(|e| e.to_string()),
75-
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())
74+
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())
7675
);
7776
assert_eq!(
7877
crate::ts::inline::<StructWithStructWithBigInt>(&Typescript::default())
7978
.map_err(|e| e.to_string()),
80-
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())
79+
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())
8180
);
8281
assert_eq!(
8382
crate::ts::inline::<StructWithStructWithStructWithBigInt>(&Typescript::default())
8483
.map_err(|e| e.to_string()),
85-
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())
84+
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())
8685
);
8786
assert_eq!(
8887
crate::ts::inline::<EnumWithStructWithStructWithBigInt>(&Typescript::default())
8988
.map_err(|e| e.to_string()),
90-
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())
89+
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())
9190
);
9291
// TODO: This required `inline` to work better on `Option<T>`
9392
// assert_eq!(
@@ -99,11 +98,11 @@ fn test_bigint_types() {
9998
assert_eq!(
10099
crate::ts::inline::<EnumWithStructWithStructWithBigInt>(&Typescript::default())
101100
.map_err(|e| e.to_string()),
102-
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())
101+
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())
103102
);
104103
assert_eq!(
105104
crate::ts::inline::<EnumWithInlineStructWithBigInt>(&Typescript::default())
106105
.map_err(|e| e.to_string()),
107-
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. You can change this behavior by editing your `ExportConfiguration`!\n".into())
106+
Err("Attempted to export \"\" but Specta configuration forbids exporting BigInt types (i64, u64, i128, u128) because we don't know if your se/deserializer supports it. If your using a serializer/deserializer that natively has support for BigInt types you can disable this warning by editing your `ExportConfiguration`!\n".into())
108107
);
109108
}

tests/tests/macro/compile_error.stderr

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,11 @@ error[E0432]: unresolved import `specta::specta`
5555
note: found an item that was configured out
5656
--> $WORKSPACE/specta/src/lib.rs
5757
|
58+
| #[cfg(all(feature = "derive", feature = "function"))]
59+
| -------------------- the item is gated behind the `function` feature
60+
| #[cfg_attr(docsrs, doc(cfg(all(feature = "derive", feature = "function"))))]
5861
| pub use specta_macros::specta;
5962
| ^^^^^^
60-
note: the item is gated here
61-
--> $WORKSPACE/specta/src/lib.rs
62-
|
63-
| #[cfg(all(feature = "derive", feature = "function"))]
64-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6563

6664
error[E0601]: `main` function not found in crate `$CRATE`
6765
--> tests/macro/compile_error.rs:110:20

tests/tests/ts.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,6 @@ fn typescript_types() {
407407

408408
// https://github.com/specta-rs/specta/issues/374
409409
assert_ts!(Issue374, "{ foo?: boolean; bar?: boolean }");
410-
411-
// https://github.com/specta-rs/specta/issues/386
412-
assert_ts!(Type, "never");
413410
}
414411

415412
#[derive(Type)]
@@ -780,6 +777,16 @@ struct Issue374 {
780777
bar: bool,
781778
}
782779

783-
/// https://github.com/specta-rs/specta/issues/386
784-
#[derive(specta::Type)]
785-
enum Type {}
780+
781+
// https://github.com/specta-rs/specta/issues/386
782+
// We put this test in a separate module because the parent module has `use specta::Type`,
783+
// so it clashes with our user-defined `Type`.
784+
mod type_type {
785+
#[derive(specta::Type)]
786+
enum Type {}
787+
788+
#[test]
789+
fn typescript_types() {
790+
assert_ts!(Type, "never");
791+
}
792+
}

0 commit comments

Comments
 (0)