Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test to assert macro hygiene for Encode and Decode derives #293

Merged
merged 6 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion derive/src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ pub fn quote(
.map_err(|e| e.chain(#read_byte_err_msg))?
{
#( #recurse )*
_ => ::core::result::Result::Err(#invalid_variant_err_msg.into()),
_ => ::core::result::Result::Err(
<_ as ::core::convert::Into<_>>::into(#invalid_variant_err_msg)
),
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/max_encoded_len.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// limitations under the License.

//! Tests for MaxEncodedLen derive macro
#![cfg(feature = "derive")]
#![cfg(all(feature = "derive", feature = "max-encoded-len"))]

use parity_scale_codec::{MaxEncodedLen, Compact, Encode};

Expand Down
25 changes: 25 additions & 0 deletions tests/scale_codec_ui.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#[test]
#[cfg(feature = "derive")]
fn scale_codec_ui_tests() {
// As trybuild is using `cargo check`, we don't need the real WASM binaries.
std::env::set_var("SKIP_WASM_BUILD", "1");

Robbepop marked this conversation as resolved.
Show resolved Hide resolved
let t = trybuild::TestCases::new();
t.compile_fail("tests/scale_codec_ui/*.rs");
t.pass("tests/scale_codec_ui/pass/*.rs");
}
23 changes: 23 additions & 0 deletions tests/scale_codec_ui/pass/decode-no-implicit-prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![no_implicit_prelude]

#[derive(::parity_scale_codec::Decode)]
pub struct Struct {
field_1: i8,
field_2: i16,
field_3: i32,
field_4: i64,
}

#[derive(::parity_scale_codec::Decode)]
pub enum Enum {
Variant1,
Variant2(i8, i16, i32, i64),
Variant3 {
field_1: i8,
field_2: i16,
field_3: i32,
field_4: i64,
}
}

fn main() {}
23 changes: 23 additions & 0 deletions tests/scale_codec_ui/pass/encode-no-implicit-prelude.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![no_implicit_prelude]

#[derive(::parity_scale_codec::Encode)]
pub struct Struct {
field_1: i8,
field_2: i16,
field_3: i32,
field_4: i64,
}

#[derive(::parity_scale_codec::Encode)]
pub enum Enum {
Variant1,
Variant2(i8, i16, i32, i64),
Variant3 {
field_1: i8,
field_2: i16,
field_3: i32,
field_4: i64,
}
}

fn main() {}