Commit Graph

414 Commits

Author SHA1 Message Date
Mingun
e0fc46783d Add test with generic deserialize_with function 2021-06-12 18:47:08 +05:00
David Tolnay
1094e2d334
Update ui test suite to nightly-2021-05-14 2021-05-13 19:16:07 -07:00
hyd-dev
dd29825217
Allow only unused_extern_crates instead of the whole rust_2018_idioms lint group in serde_derive-generated code 2021-05-12 18:29:45 +08:00
David Tolnay
2ebc771b88
Remove non_ascii_idents feature gate from test suite
error: the feature `non_ascii_idents` has been stable since 1.53.0 and no longer requires an attribute to enable
     --> test_suite/tests/test_gen.rs:6:43
      |
    6 | #![cfg_attr(feature = "unstable", feature(non_ascii_idents))]
      |                                           ^^^^^^^^^^^^^^^^
      |
    note: the lint level is defined here
     --> test_suite/tests/test_gen.rs:5:9
      |
    5 | #![deny(warnings)]
      |         ^^^^^^^^
      = note: `#[deny(stable_features)]` implied by `#[deny(warnings)]`
2021-04-19 19:55:12 -07:00
David Tolnay
b53ebef438
Resolve safe_packed_borrows lint renamed to unaligned_references
warning: lint `safe_packed_borrows` has been renamed to `unaligned_references`
        --> test_suite/tests/test_macros.rs:1926:8
         |
    1926 | #[deny(safe_packed_borrows)]
         |        ^^^^^^^^^^^^^^^^^^^ help: use the new name: `unaligned_references`
         |
         = note: `#[warn(renamed_and_removed_lints)]` on by default
2021-04-08 20:08:42 -07:00
David Tolnay
697b082e90
Touch up PR 1997 2021-03-05 19:48:40 -08:00
Cary Yang
4118cec731 Prevent various panics when deserializing malformed SystemTime 2021-03-05 17:52:51 -08:00
Mingun
b60c03ec3f Extend test_internally_tagged_newtype_variant_containing_unit_struct to cover structs and seqs 2021-02-02 09:00:04 +05:00
Mingun
3257851192 Extend test_internally_tagged_struct_variant_containing_unit_variant to cover maps and seqs 2021-02-02 08:59:59 +05:00
David Tolnay
6699b0bc40
Add regression test for issue 1969 2021-01-25 13:34:08 -08:00
David Tolnay
6c5bf701be
Merge pull request 1830 from taiki-e/self 2021-01-24 23:05:51 -08:00
David Tolnay
aeee73fe92
Merge pull request #1831 from taiki-e/borrow-macro
Collect lifetimes inside macro invocations
2021-01-24 19:08:20 -08:00
Taiki Endo
c67017d466 Fix handling of Self keyword in type definition 2021-01-24 15:23:51 +09:00
David Tolnay
5aa163f27e
Revert "Regenerate macrotest outputs for PR #1917"
This reverts commit 999b94d6ae.
2021-01-23 20:36:26 -08:00
David Tolnay
e6b6602a42
Merge pull request 1914 from Mingun/seq-other 2021-01-23 19:50:39 -08:00
David Tolnay
999b94d6ae
Regenerate macrotest outputs for PR #1917 2021-01-23 19:43:02 -08:00
David Tolnay
4e002ece07
Provide list of recognized rename rules on parse error 2021-01-23 14:38:20 -08:00
David Tolnay
88ee470a1c
Format PR #1916 with rustfmt 1.4.32 2021-01-23 13:39:12 -08:00
David Tolnay
a5ecbdb4f4
Merge pull request 1916 from Mingun/expecting-customize 2021-01-23 13:38:45 -08:00
David Tolnay
60e08f9545
Format PR #1917 with rustfmt 1.4.32 2021-01-23 12:39:59 -08:00
David Tolnay
ba46f45dc5
Merge pull request 1917 from Mingun/borrow-identifier 2021-01-23 12:39:28 -08:00
Jonas Bushart
b276849ce1 Prevent panic when deserializing malformed Duration
std::time::Duration::new can panic. There is no alternative non-panicing constructor.
Check the panic condition beforehand and return an error instead of panicing.

Fixes #1933
2021-01-20 20:41:45 +01:00
David Tolnay
dd1f4b483e
Make it clearer that the private implementation details are private
Both of these modules are doc(hidden) and commented "Not public API",
but incorrect downstream code sometimes still references them. Naming
the module __private will make it more likely to be noticed in code
review.
2021-01-08 19:55:31 -08:00
David Tolnay
91bfa8f947
Refresh expandtest files with most recent rustfmt 2021-01-08 19:54:21 -08:00
David Tolnay
8847800ce2
Ignore from_over_into clippy lint in test suite 2021-01-03 19:05:43 -08:00
Taiki Endo
a227a87865 Collect lifetimes inside macro invocations 2020-10-24 05:29:47 +09:00
Mingun
7a7a182ab6 Allow borrow for field identifiers 2020-10-23 19:03:18 +05:00
Mingun
104ad9a7dd Allow to define custom expectation message for type with #[serde(expecting = "...")]
Closes #1883
2020-10-23 01:23:01 +05:00
Mingun
e80571751d Allow borrowed and owned strings and bytes and u8, u16, u64 for variant keys in serde_test 2020-10-22 20:43:14 +05:00
Mingun
0737474640 Allow field identifiers be any numbers if #[serde(other)] is used
Thus behavior synchronized between string/bytes identifiers and numeric identifiers
2020-10-22 16:35:28 +05:00
Mingun
f6eb34a830 Assert that numeric field identifiers correctly deserialized (now failing) 2020-10-22 16:35:28 +05:00
David Tolnay
8084258a3e
Update ui tests to nightly-2020-10-20 2020-10-20 19:17:50 -07:00
David Tolnay
26186bddd1
Add test for flattened unit 2020-08-10 15:06:34 -07:00
David Tolnay
29c5a50935
Suppress unused_attributes warning in test suite
This test has multiple #[ignore] attributes in some configurations.

    $ cargo +beta check --test expandtest
    warning: unused attribute
     --> test_suite/tests/expandtest.rs:2:29
      |
    2 | #[cfg_attr(not(expandtest), ignore)]
      |                             ^^^^^^
      |
      = note: `#[warn(unused_attributes)]` on by default
2020-06-26 21:37:30 -07:00
David Tolnay
c619b2a7c4
Suppress unknown_lints warning in test suite
When building with beta and older rustc:

    error: unknown lint: `mixed_script_confusables`
     --> test_suite/tests/test_gen.rs:7:10
      |
    7 | #![allow(mixed_script_confusables, clippy::trivially_copy_pass_by_ref)]
      |          ^^^^^^^^^^^^^^^^^^^^^^^^
      |
    note: the lint level is defined here
     --> test_suite/tests/test_gen.rs:5:9
      |
    5 | #![deny(warnings)]
      |         ^^^^^^^^
      = note: `#[deny(unknown_lints)]` implied by `#[deny(warnings)]`
2020-06-26 21:37:26 -07:00
David Tolnay
764ebd9b17
Suppress mixed_script_confusables in test suite
error: The usage of Script Group `Greek` in this crate consists solely of mixed script confusables
       --> test_suite/tests/test_gen.rs:269:9
        |
    269 |         σ: f64,
        |         ^
        |
    note: the lint level is defined here
       --> test_suite/tests/test_gen.rs:5:9
        |
    5   | #![deny(warnings)]
        |         ^^^^^^^^
        = note: `#[deny(mixed_script_confusables)]` implied by `#[deny(warnings)]`
        = note: The usage includes 'σ' (U+03C3).
        = note: Please recheck to make sure their usages are indeed what you want.
2020-06-26 19:06:13 -07:00
Tanner Rogalsky
7e5701ad2b add alignment specific packed repr tests 2020-06-21 16:46:27 -07:00
Tanner Rogalsky
d5e6436b28 Add tests validating Serialize derivation for packed structs. 2020-06-21 16:46:27 -07:00
Taiki Endo
a50e1c20e9 Use underscore consts on Rust 1.37+ 2020-06-19 15:55:43 +09:00
David Tolnay
f7d06cae4c
Add failing test involving macro_rules metavariable 2020-05-29 17:58:10 -07:00
David Tolnay
c2114491ca
Add test of Serialize impl for packed struct 2020-05-09 22:52:49 -07:00
asdsad
172edc4cf4
Allow optional content field for adjacently tagged newtype variants
* Deserialize adjacently tagged newtype variants with optional content as None instead of erroring when content field is missing

* refactor to remove duplicate code and remove panic
2020-05-09 20:58:28 -07:00
David Tolnay
f44402e224
Add regression test for issue 1804 2020-05-08 15:38:44 -07:00
David Tolnay
23db3a41e7
Run expansion tests only if rustfmt is present 2020-05-05 21:50:14 -07:00
David Tolnay
19a11237b8
Regenerate macrotest *.expanded.rs files
This picks up changes from a135199ab1 and 1b35c9e27e.
2020-05-05 17:23:30 -07:00
David Tolnay
03addbae55
Format with rustfmt 2020-03-11 2020-04-19 17:32:11 -07:00
David Tolnay
a61cd0f236
Update ui tests to nightly-2020-02-08 2020-02-08 00:10:00 -08:00
David Tolnay
895eb2ba6c
Update ui tests to nightly-2019-12-19 2019-12-18 23:46:29 -08:00
David Tolnay
cd365de70c
Update ui tests to nightly-2019-12-18 2019-12-17 23:47:40 -08:00
David Tolnay
b9909cef3d
Revert "Remove never_type feature gate"
This reverts commit 533fb9cc44.
2019-12-15 19:52:59 -08:00
David Tolnay
d540e72fc7
Format with rustfmt 2019-10-07 2019-11-26 00:02:11 -08:00
David Tolnay
13d0899776
Add missing import in de_enum expand test 2019-11-26 00:00:05 -08:00
David Tolnay
4fefa7a01d
Format imports in expandtest inputs 2019-11-25 23:57:34 -08:00
David Tolnay
90486607a1
Update test suite to nightly-2019-11-26 2019-11-25 23:51:43 -08:00
David Tolnay
0b303c766c
Mark tests ignored on emscripten rather than omitting
This way they still appear in `cargo test`'s output.
2019-11-24 17:27:30 -08:00
David Tolnay
c371563bfc
Reduce nesting of macrotest test cases 2019-11-24 17:25:44 -08:00
David Tolnay
bcaebdb2b7
Merge pull request #1662 from eupn/use-macrotest
Implement expansion tests
2019-11-24 17:14:35 -08:00
David Tolnay
ff70409215
Merge pull request #1669 from H2CO3/master
Allow untagged unit variants to deserialize from `Visitor::visit_none()`
2019-11-24 16:13:37 -08:00
David Tolnay
97a98a7031
Test only deser for untagged unit visit_none 2019-11-24 15:59:08 -08:00
David Tolnay
533fb9cc44
Remove never_type feature gate
The stabilization for this feature has landed in nightly.
2019-11-23 19:30:39 -08:00
Árpád Goretity
59b99d2d60 Move test for untagged-variant-from-unit where it belongs 2019-11-07 21:18:12 +01:00
Árpád Goretity
c796daed7c Fix test for untagged unit variant 2019-11-07 12:58:09 +01:00
Árpád Goretity
6e2c385fa5 Allow untagged unit variants to deserialize from Visitor::visit_none() 2019-11-06 17:31:27 +01:00
Evgenii P
9a0e4e0176 Ignore expansion test if cargo-expand subcommand isn't present 2019-11-03 20:31:08 +08:00
Evgenii P
640f8e0e82 Remove stdlib derives and fix expanded files to have newlines at the end 2019-11-03 20:08:39 +08:00
Evgenii P
4dda90502a Add *.expanded.rs files 2019-11-01 02:32:34 +08:00
Evgenii P
dc6dbba47c Implement derive macros expansion tests using macrotest 2019-11-01 02:32:06 +08:00
Jan Alexander Steffens (heftig)
b8772a1e40
Deserialize Box<Path> through PathBuf::into_boxed_path
Including Rc<Path> et al.

Fixes https://github.com/serde-rs/serde/issues/1633
2019-10-22 22:31:51 +02:00
Jan Alexander Steffens (heftig)
42990d8264
Deserialize PathBuf from bytes
&Path already allows this. Also complete the tests for Path/PathBuf.
2019-10-22 22:30:53 +02:00
David Tolnay
bda561df4e
Update test suite to nightly-2019-10-04 2019-10-03 21:45:09 -04:00
David Tolnay
8955420baf
Update test suite to nightly-2019-10-02 2019-10-02 09:45:00 -04:00
David Tolnay
21ee256911
Update test suite to nightly-2019-09-30 2019-09-30 15:56:04 -04:00
David Tolnay
e46463e69f
Add tests for attribute parse errors 2019-09-07 22:57:27 -07:00
David Tolnay
187a0a3ec0
Format with rustfmt 2019-08-19 2019-09-07 22:16:49 -07:00
Jake Kiesel
acc8640c1e Fix (de)serialization of new types where the internal type is skipped 2019-09-07 03:20:43 -06:00
David Tolnay
273ecdb786
Update ui tests on nightly-2019-08-16 2019-08-16 11:30:49 -07:00
David Tolnay
d0fb958e99
Remove unneeded explicit type parameters in test_from_into_traits 2019-07-17 12:32:34 -07:00
David Tolnay
b941c63a53
More typical TryFrom usage for test 2019-07-17 12:31:41 -07:00
David Tolnay
cf70c3fb05
Format with rustfmt 2019-06-09 2019-07-17 12:27:26 -07:00
David Tolnay
92e0b62c6b
Merge pull request 1526 from fanzeyi/try_from 2019-07-17 12:16:31 -07:00
David Tolnay
7b0e06c825
Provide 32 bit atomic impls for emscripten 2019-07-17 11:44:24 -07:00
David Tolnay
f3e2bb5104
Disable 64 bit atomic tests on emscripten 2019-07-16 10:00:44 -07:00
David Tolnay
e89feb9635
Test atomics without needing a macro
As a secondary benefit, this avoids a congnitive_complexity lint from
Clippy.
2019-07-16 09:17:36 -07:00
David Tolnay
5f72766c27
Ignore unreadable_literal lint in test code 2019-07-16 09:04:43 -07:00
David Tolnay
102a332616
Format with rustfmt 2019-06-09 2019-07-16 07:32:13 -07:00
James Brown
4e5f63ff45 gate atomic serde on rust 1.34 or higher 2019-07-12 13:44:42 -07:00
James Brown
de709e72a8 implement deserialization for atomic integer types 2019-07-11 18:18:54 -07:00
James Brown
56d3c8f071 implement serialization for atomic integer types 2019-07-11 17:34:53 -07:00
David Tolnay
bc7a85063d
Switch to rustversion 2019-07-07 21:14:11 -07:00
David Tolnay
1c97a7ecb3
Add comprehensive test for deserializing IgnoredAny from enum 2019-06-27 10:23:39 -07:00
David Tolnay
fccd3e9fba
Add deserialization tests for IgnoredAny 2019-06-27 10:07:06 -07:00
David Tolnay
afb1754528
Allow integer key in untagged flattened map 2019-06-23 12:09:15 -07:00
David Tolnay
9c756f1ec0
Disable ui tests on emscripten
These hit a strange error in our Emscripten builder in Travis as well as
locally through cargo web:

    ERROR: failed to execute cargo: Resource temporarily unavailable (os error 11)
2019-05-12 00:28:22 -07:00
Zeyi Fan
4c29eea790 add attribute try_from 2019-05-11 23:31:24 -07:00
David Tolnay
0a9d24a218
Support deserializing enum out of MapAccessDeserializer 2019-05-06 16:11:28 -07:00
David Tolnay
140f9beee7
Switch ui tests to trybuild 2019-05-06 10:25:47 -07:00
David Tolnay
ce1686379d
Update test suite to nightly-2019-04-20 2019-04-19 22:54:59 -07:00
David Tolnay
82bde8d166
Format with rustfmt 2019-03-27 2019-04-03 09:40:12 -07:00
Sean Griffin
b4d8a55b2a Change serde_path to crate
Also changed the generated code to have at least one thing refer to the
path directly, rather than via `use` -- This shows that the impl *can*
work without `use`, but doesn't actually do all the work to remove the
`use` lines unless we decide we need this feature to work on the 2015
edition
2019-03-28 11:42:50 -06:00
Sean Griffin
a295c38ba3 Allow #[serde(serde_path = "...")] to override extern crate serde
This is intended to be used by other crates which provide their own proc
macros and use serde internally. Today there's no consistent way to put
`#[derive(Deserialize)]` on a struct that consistently works, since
crates may be using either `features = ["derive"]` or relying on
`serde_derive` separately.

Even if we assume that everyone is using `features = ["derive"]`,
without this commit, any crate which generates
`#[derive(serde::Deserialize)]` forces its consumers to put `serde` in
their `Cargo.toml`, even if they aren't otherwise using serde for
anything.

Examples of crates which suffer from this in the real world are
tower-web and swirl.

With this feature, it's expected that these crates would have `pub
extern crate serde;` in some accessible path, and add
`#[serde(serde_path = "that_crate::wherever::serde")]` anywhere they
place serde's derives. Those crates would also have to derive
`that_crate::whatever::serde::Deserialize`, or `use` the macros
explicitly beforehand.

The test for this is a little funky, as it's testing this in a way that
is not the intended use case, or even one we want to support. It has its
own module which re-exports all of serde, but defines its own
`Serialize` and `Deserialize` traits. We then test that we generated
impls for those traits, instead of serde's. The only other way to test
this would be to create a new test crate which does not depend on serde,
but instead depends on `serde_derive` and a third crate which publicly
re-exports serde. This feels like way too much overhead for a single
test case, hence the funky test given.

I didn't see anywhere in this repo to document this attribute, so I
assume the docs will have to be done as a separate PR to a separate
repo.

Fixes #1487
2019-03-18 15:20:19 -06:00