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

Make tests build #429

Merged
merged 7 commits into from
May 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 23 additions & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ check-rust-stable-no_derive:
script:
- time cargo +stable check --verbose --features bit-vec,bytes,generic-array

check-rust-stable-only_mel:
stage: check
<<: *docker-env
variables:
RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
script:
- time cargo +stable check --verbose --features max-encoded-len

#### stage: test

Expand All @@ -88,6 +95,22 @@ test-rust-stable-no_derive:
script:
- time cargo +stable test --verbose --features bit-vec,bytes,generic-array

test-rust-stable-only_mel:
stage: test
<<: *docker-env
variables:
RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
script:
- time cargo +stable test --verbose --features max-encoded-len

test-rust-stable-only_mel-no_default_std:
stage: test
<<: *docker-env
variables:
RUSTFLAGS: "-Cdebug-assertions=y -Dwarnings"
script:
- time cargo +stable test --verbose --features max-encoded-len,std --no-default-features

bench-rust-nightly:
stage: test
<<: *docker-env
Expand Down Expand Up @@ -137,4 +160,3 @@ build-linux-ubuntu-amd64:
- if: $CI_COMMIT_REF_NAME == "tags"
script:
- cargo build --verbose --release --features bit-vec,bytes,generic-array,derive

21 changes: 6 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,8 @@
//!
//! ### Simple types
//!
//! ```
//! # // Import macros if derive feature is not used.
//! # #[cfg(not(feature="derive"))]
//! # use parity_scale_codec_derive::{Encode, Decode};
//!
#![cfg_attr(feature = "derive", doc = "```rust")]
#![cfg_attr(not(feature = "derive"), doc = "*(Only compiled with feature `derive`)*\n```ignore")]
mrcnski marked this conversation as resolved.
Show resolved Hide resolved
//! use parity_scale_codec::{Encode, Decode};
//!
//! #[derive(Debug, PartialEq, Encode, Decode)]
Expand Down Expand Up @@ -142,11 +139,8 @@
//!
//! ### Compact type with HasCompact
//!
//! ```
//! # // Import macros if derive feature is not used.
//! # #[cfg(not(feature="derive"))]
//! # use parity_scale_codec_derive::{Encode, Decode};
//!
#![cfg_attr(feature = "derive", doc = "```rust")]
#![cfg_attr(not(feature = "derive"), doc = "*(Only compiled with feature `derive`)*\n```ignore")]
//! use parity_scale_codec::{Encode, Decode, Compact, HasCompact};
//!
//! #[derive(Debug, PartialEq, Encode, Decode)]
Expand All @@ -171,11 +165,8 @@
//! ```
//! ### Type with CompactAs
//!
//! ```rust
//! # // Import macros if derive feature is not used.
//! # #[cfg(not(feature="derive"))]
//! # use parity_scale_codec_derive::{Encode, Decode};
//!
#![cfg_attr(feature = "derive", doc = "```rust")]
#![cfg_attr(not(feature = "derive"), doc = "*(Only compiled with feature `derive`)*\n```ignore")]
//! use serde_derive::{Serialize, Deserialize};
//! use parity_scale_codec::{Encode, Decode, Compact, HasCompact, CompactAs, Error};
//!
Expand Down
11 changes: 5 additions & 6 deletions tests/chain-error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,21 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#[cfg(not(feature="derive"))]
use parity_scale_codec_derive::Decode;
use parity_scale_codec_derive::Decode as DeriveDecode;
use parity_scale_codec::Decode;

#[derive(Decode, Debug)]
#[derive(DeriveDecode, Debug)]
struct Wrapper<T>(T);

#[derive(Decode, Debug)]
#[derive(DeriveDecode, Debug)]
struct StructNamed {
_foo: u16
}

#[derive(Decode, Debug)]
#[derive(DeriveDecode, Debug)]
struct StructUnnamed(u16);

#[derive(Decode, Debug)]
#[derive(DeriveDecode, Debug)]
enum E {
VariantNamed { _foo: u16, },
VariantUnnamed(u16),
Expand Down
59 changes: 29 additions & 30 deletions tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,23 @@
use parity_scale_codec::{
Compact, CompactAs, Decode, Encode, EncodeAsRef, Error, HasCompact, Output,
};
#[cfg(not(feature = "derive"))]
use parity_scale_codec_derive::{Decode, Encode};
use parity_scale_codec_derive::{Decode as DeriveDecode, Encode as DeriveEncode};
use serde_derive::{Deserialize, Serialize};

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
ggwpez marked this conversation as resolved.
Show resolved Hide resolved
struct Unit;

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
struct Indexed(u32, u64);

#[derive(Debug, PartialEq, Encode, Decode, Default)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode, Default)]
struct Struct<A, B, C> {
pub a: A,
pub b: B,
pub c: C,
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
struct StructWithPhantom {
pub a: u32,
pub b: u64,
Expand All @@ -47,7 +46,7 @@ impl<A, B, C> Struct<A, B, C> {
}
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
enum EnumType {
#[codec(index = 15)]
A,
Expand All @@ -58,26 +57,26 @@ enum EnumType {
},
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
enum EnumWithDiscriminant {
A = 1,
B = 15,
C = 255,
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
struct TestHasCompact<T: HasCompact> {
#[codec(encoded_as = "<T as HasCompact>::Type")]
bar: T,
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
struct TestCompactHasCompact<T: HasCompact> {
#[codec(compact)]
bar: T,
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
enum TestHasCompactEnum<T: HasCompact> {
Unnamed(#[codec(encoded_as = "<T as HasCompact>::Type")] T),
Named {
Expand All @@ -91,13 +90,13 @@ enum TestHasCompactEnum<T: HasCompact> {
},
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
struct TestCompactAttribute {
#[codec(compact)]
bar: u64,
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
enum TestCompactAttributeEnum {
Unnamed(#[codec(compact)] u64),
Named {
Expand Down Expand Up @@ -330,7 +329,7 @@ fn associated_type_bounds() {
type NonEncodableType;
}

#[derive(Encode, Decode, Debug, PartialEq)]
#[derive(DeriveEncode, DeriveDecode, Debug, PartialEq)]
struct Struct<T: Trait, Type> {
field: (Vec<T::EncodableType>, Type),
}
Expand Down Expand Up @@ -372,7 +371,7 @@ fn generic_bound_encoded_as() {
type RefType = &'a u32;
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
struct TestGeneric<A: From<u32>>
where
u32: for<'a> EncodeAsRef<'a, A>,
Expand Down Expand Up @@ -408,7 +407,7 @@ fn generic_bound_hascompact() {
}
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
enum TestGenericHasCompact<T> {
A {
#[codec(compact)]
Expand All @@ -429,14 +428,14 @@ fn generic_trait() {

struct StructNoCodec;

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
struct StructCodec;

impl TraitNoCodec for StructNoCodec {
type Type = StructCodec;
}

#[derive(Debug, PartialEq, Encode, Decode)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode)]
struct TestGenericTrait<T: TraitNoCodec> {
t: T::Type,
}
Expand All @@ -448,7 +447,7 @@ fn generic_trait() {

#[test]
fn recursive_variant_1_encode_works() {
#[derive(Debug, PartialEq, Encode, Decode, Default)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode, Default)]
struct Recursive<N> {
data: N,
other: Vec<Recursive<N>>,
Expand All @@ -460,7 +459,7 @@ fn recursive_variant_1_encode_works() {

#[test]
fn recursive_variant_2_encode_works() {
#[derive(Debug, PartialEq, Encode, Decode, Default)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode, Default)]
struct Recursive<A, B, N> {
data: N,
other: Vec<Struct<A, B, Recursive<A, B, N>>>,
Expand All @@ -476,10 +475,10 @@ fn private_type_in_where_bound() {
// an error.
#![deny(warnings)]

#[derive(Debug, PartialEq, Encode, Decode, Default)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode, Default)]
struct Private;

#[derive(Debug, PartialEq, Encode, Decode, Default)]
#[derive(Debug, PartialEq, DeriveEncode, DeriveDecode, Default)]
#[codec(dumb_trait_bound)]
pub struct Test<N> {
data: Vec<(N, Private)>,
Expand All @@ -491,7 +490,7 @@ fn private_type_in_where_bound() {

#[test]
fn encode_decode_empty_enum() {
#[derive(Encode, Decode, PartialEq, Debug)]
#[derive(DeriveEncode, DeriveDecode, PartialEq, Debug)]
enum EmptyEnumDerive {}

fn impls_encode_decode<T: Encode + Decode>() {}
Expand All @@ -513,13 +512,13 @@ fn codec_vec_u8() {

#[test]
fn recursive_type() {
#[derive(Encode, Decode)]
#[derive(DeriveEncode, DeriveDecode)]
pub enum Foo {
T(Box<Bar>),
A,
}

#[derive(Encode, Decode)]
#[derive(DeriveEncode, DeriveDecode)]
pub struct Bar {
field: Foo,
}
Expand Down Expand Up @@ -567,7 +566,7 @@ fn weird_derive() {
};
}

make_struct!(#[derive(Encode, Decode)]);
make_struct!(#[derive(DeriveEncode, DeriveDecode)]);
}

#[test]
Expand All @@ -577,15 +576,15 @@ fn output_trait_object() {

#[test]
fn custom_trait_bound() {
#[derive(Encode, Decode)]
#[derive(DeriveEncode, DeriveDecode)]
#[codec(encode_bound(N: Encode, T: Default))]
#[codec(decode_bound(N: Decode, T: Default))]
struct Something<T, N> {
hello: Hello<T>,
val: N,
}

#[derive(Encode, Decode)]
#[derive(DeriveEncode, DeriveDecode)]
#[codec(encode_bound())]
#[codec(decode_bound())]
struct Hello<T> {
Expand Down Expand Up @@ -620,7 +619,7 @@ fn bit_vec_works() {

assert_eq!(original_vec, original_vec_clone);

#[derive(Decode, Encode, PartialEq, Debug)]
#[derive(DeriveDecode, DeriveEncode, PartialEq, Debug)]
struct MyStruct {
v: BitVec<u8, Msb0>,
x: u8,
Expand All @@ -637,7 +636,7 @@ fn bit_vec_works() {

#[test]
fn no_warning_for_deprecated() {
#[derive(Encode, Decode)]
#[derive(DeriveEncode, DeriveDecode)]
pub enum MyEnum {
VariantA,
#[deprecated]
Expand Down
Loading