mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-27 08:07:58 +00:00
Replace compile_fail doc tests with trybuild (#2588)
* WIP: use trybuild for compile tests * declaring_old_block * declaring_own_block_with_different_name * adding_self_parameter * adding_at_parameter * invalid_api_version * invalid_api_version2 & invalid_api_version3 * missing_block_generic_parameter * Restore main functions * missing_path_for_trait * empty_impl_runtime_apis_call * empty_impl_runtime_apis_call * type_reference_in_impl_runtime_apis_call * impl_incorrect_method_signature * impl_two_traits_with_same_name * changed_at_unknown_version * changed_at > changed_in * fix test
This commit is contained in:
committed by
Bastian Köcher
parent
aa2c496a65
commit
b2ea94d73d
@@ -0,0 +1,9 @@
|
||||
use client::decl_runtime_apis;
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(at: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: `decl_runtime_apis!` adds automatically a parameter `at: &BlockId<Block>`. Please rename/remove your parameter.
|
||||
--> $DIR/adding_at_parameter.rs:5:11
|
||||
|
|
||||
5 | fn test(at: u64);
|
||||
| ^^
|
||||
@@ -0,0 +1,9 @@
|
||||
use client::decl_runtime_apis;
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(&self);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: Self values are not supported.
|
||||
--> $DIR/adding_self_parameter.rs:5:11
|
||||
|
|
||||
5 | fn test(&self);
|
||||
| ^
|
||||
@@ -0,0 +1,20 @@
|
||||
use runtime_primitives::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
use client::decl_runtime_apis;
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
#[changed_in(2)]
|
||||
fn test(data: u64);
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: `changed_in` version can not be greater than the `api_version`
|
||||
--> $DIR/changed_in_unknown_version.rs:15:3
|
||||
|
|
||||
15 | fn test(data: u64);
|
||||
| ^^
|
||||
@@ -0,0 +1,10 @@
|
||||
use runtime_primitives::traits::Block as BlockT;
|
||||
use client::decl_runtime_apis;
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api<Block: BlockT> {
|
||||
fn test();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,19 @@
|
||||
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro!
|
||||
--> $DIR/declaring_old_block.rs:5:16
|
||||
|
|
||||
5 | pub trait Api<Block: BlockT> {
|
||||
| ^^^^^
|
||||
|
||||
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally.
|
||||
--> $DIR/declaring_old_block.rs:5:23
|
||||
|
|
||||
5 | pub trait Api<Block: BlockT> {
|
||||
| ^^^^^^
|
||||
|
||||
warning: unused import: `runtime_primitives::traits::Block as BlockT`
|
||||
--> $DIR/declaring_old_block.rs:1:5
|
||||
|
|
||||
1 | use runtime_primitives::traits::Block as BlockT;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: #[warn(unused_imports)] on by default
|
||||
@@ -0,0 +1,10 @@
|
||||
use runtime_primitives::traits::Block as BlockT;
|
||||
use client::decl_runtime_apis;
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api<B: BlockT> {
|
||||
fn test();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,13 @@
|
||||
error: `Block: BlockT` generic parameter will be added automatically by the `decl_runtime_apis!` macro! If you try to use a different trait than the substrate `Block` trait, please rename it locally.
|
||||
--> $DIR/declaring_own_block_with_different_name.rs:5:19
|
||||
|
|
||||
5 | pub trait Api<B: BlockT> {
|
||||
| ^^^^^^
|
||||
|
||||
warning: unused import: `runtime_primitives::traits::Block as BlockT`
|
||||
--> $DIR/declaring_own_block_with_different_name.rs:1:5
|
||||
|
|
||||
1 | use runtime_primitives::traits::Block as BlockT;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: #[warn(unused_imports)] on by default
|
||||
@@ -0,0 +1,20 @@
|
||||
use runtime_primitives::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
use client::{decl_runtime_apis, impl_runtime_apis};
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
impl_runtime_apis! {}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: No api implementation given!
|
||||
--> $DIR/empty_impl_runtime_apis_call.rs:18:1
|
||||
|
|
||||
18 | impl_runtime_apis! {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
@@ -0,0 +1,24 @@
|
||||
use runtime_primitives::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
use client::{decl_runtime_apis, impl_runtime_apis};
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
impl_runtime_apis! {
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test(data: String) {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,13 @@
|
||||
error[E0053]: method `test` has an incompatible type for trait
|
||||
--> $DIR/impl_incorrect_method_signature.rs:20:17
|
||||
|
|
||||
14 | fn test(data: u64);
|
||||
| --- type in trait
|
||||
...
|
||||
20 | fn test(data: String) {}
|
||||
| ^^^^^^ expected u64, found struct `std::string::String`
|
||||
|
|
||||
= note: expected type `fn(u64)`
|
||||
found type `fn(std::string::String)`
|
||||
|
||||
For more information about this error, try `rustc --explain E0053`.
|
||||
@@ -0,0 +1,36 @@
|
||||
use runtime_primitives::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
use client::{decl_runtime_apis, impl_runtime_apis};
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
mod second {
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test2(data: u64);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_runtime_apis! {
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test(data: u64) {}
|
||||
}
|
||||
|
||||
impl second::Api<Block> for Runtime {
|
||||
fn test2(data: u64) {}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,25 @@
|
||||
error: Two traits with the same name detected! The trait name is used to generate its ID. Please rename one trait at the declaration!
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:31:15
|
||||
|
|
||||
31 | impl second::Api<Block> for Runtime {
|
||||
| ^^^
|
||||
|
||||
error: cannot find macro `decl_runtime_apis!` in this scope
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:19:2
|
||||
|
|
||||
19 | decl_runtime_apis! {
|
||||
| ^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0433]: failed to resolve: could not find `runtime_decl_for_Api` in `second`
|
||||
--> $DIR/impl_two_traits_with_same_name.rs:26:1
|
||||
|
|
||||
26 | / impl_runtime_apis! {
|
||||
27 | | impl self::Api<Block> for Runtime {
|
||||
28 | | fn test(data: u64) {}
|
||||
29 | | }
|
||||
... |
|
||||
33 | | }
|
||||
34 | | }
|
||||
| |_^ could not find `runtime_decl_for_Api` in `second`
|
||||
|
||||
For more information about this error, try `rustc --explain E0433`.
|
||||
@@ -0,0 +1,10 @@
|
||||
use client::decl_runtime_apis;
|
||||
|
||||
decl_runtime_apis! {
|
||||
#[api_version]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,29 @@
|
||||
error: can't qualify macro invocation with `pub`
|
||||
--> $DIR/invalid_api_version.rs:3:1
|
||||
|
|
||||
3 | / decl_runtime_apis! {
|
||||
4 | | #[api_version]
|
||||
5 | | pub trait Api {
|
||||
6 | | fn test(data: u64);
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_^
|
||||
|
|
||||
= help: try adjusting the macro to put `pub` inside the invocation
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version.rs:3:1
|
||||
|
|
||||
3 | / decl_runtime_apis! {
|
||||
4 | | #[api_version]
|
||||
5 | | pub trait Api {
|
||||
6 | | fn test(data: u64);
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_^
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version.rs:4:4
|
||||
|
|
||||
4 | #[api_version]
|
||||
| ^^^^^^^^^^^
|
||||
@@ -0,0 +1,11 @@
|
||||
use client::decl_runtime_apis;
|
||||
|
||||
decl_runtime_apis! {
|
||||
#[api_version("1")]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
error: can't qualify macro invocation with `pub`
|
||||
--> $DIR/invalid_api_version_2.rs:3:1
|
||||
|
|
||||
3 | / decl_runtime_apis! {
|
||||
4 | | #[api_version("1")]
|
||||
5 | | pub trait Api {
|
||||
6 | | fn test(data: u64);
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_^
|
||||
|
|
||||
= help: try adjusting the macro to put `pub` inside the invocation
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version_2.rs:3:1
|
||||
|
|
||||
3 | / decl_runtime_apis! {
|
||||
4 | | #[api_version("1")]
|
||||
5 | | pub trait Api {
|
||||
6 | | fn test(data: u64);
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_^
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version_2.rs:4:4
|
||||
|
|
||||
4 | #[api_version("1")]
|
||||
| ^^^^^^^^^^^
|
||||
@@ -0,0 +1,10 @@
|
||||
use client::decl_runtime_apis;
|
||||
|
||||
decl_runtime_apis! {
|
||||
#[api_version()]
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,29 @@
|
||||
error: can't qualify macro invocation with `pub`
|
||||
--> $DIR/invalid_api_version_3.rs:3:1
|
||||
|
|
||||
3 | / decl_runtime_apis! {
|
||||
4 | | #[api_version()]
|
||||
5 | | pub trait Api {
|
||||
6 | | fn test(data: u64);
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_^
|
||||
|
|
||||
= help: try adjusting the macro to put `pub` inside the invocation
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version_3.rs:3:1
|
||||
|
|
||||
3 | / decl_runtime_apis! {
|
||||
4 | | #[api_version()]
|
||||
5 | | pub trait Api {
|
||||
6 | | fn test(data: u64);
|
||||
7 | | }
|
||||
8 | | }
|
||||
| |_^
|
||||
|
||||
error: Unexpected `api_version` attribute. The supported format is `api_version(1)`
|
||||
--> $DIR/invalid_api_version_3.rs:4:4
|
||||
|
|
||||
4 | #[api_version()]
|
||||
| ^^^^^^^^^^^
|
||||
@@ -0,0 +1,26 @@
|
||||
use runtime_primitives::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
use client::{decl_runtime_apis, impl_runtime_apis};
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
impl_runtime_apis! {
|
||||
impl self::Api for Runtime {
|
||||
fn test(data: u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,13 @@
|
||||
error: Missing `Block` generic parameter.
|
||||
--> $DIR/missing_block_generic_parameter.rs:19:13
|
||||
|
|
||||
19 | impl self::Api for Runtime {
|
||||
| ^^^
|
||||
|
||||
error[E0107]: wrong number of type arguments: expected 1, found 0
|
||||
--> $DIR/missing_block_generic_parameter.rs:19:7
|
||||
|
|
||||
19 | impl self::Api for Runtime {
|
||||
| ^^^^^^^^^ expected 1 type argument
|
||||
|
||||
For more information about this error, try `rustc --explain E0107`.
|
||||
@@ -0,0 +1,26 @@
|
||||
use runtime_primitives::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
use client::{decl_runtime_apis, impl_runtime_apis};
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
impl_runtime_apis! {
|
||||
impl Api<Block> for Runtime {
|
||||
fn test(data: u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,5 @@
|
||||
error: The implemented trait has to be referenced with a path, e.g. `impl client::Core for Runtime`.
|
||||
--> $DIR/missing_path_for_trait.rs:19:7
|
||||
|
|
||||
19 | impl Api<Block> for Runtime {
|
||||
| ^^^
|
||||
@@ -0,0 +1,26 @@
|
||||
use runtime_primitives::traits::GetNodeBlockType;
|
||||
use test_client::runtime::Block;
|
||||
use client::{decl_runtime_apis, impl_runtime_apis};
|
||||
|
||||
/// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType`
|
||||
/// trait are done by the `construct_runtime!` macro in a real runtime.
|
||||
struct Runtime {}
|
||||
impl GetNodeBlockType for Runtime {
|
||||
type NodeBlock = Block;
|
||||
}
|
||||
|
||||
decl_runtime_apis! {
|
||||
pub trait Api {
|
||||
fn test(data: u64);
|
||||
}
|
||||
}
|
||||
|
||||
impl_runtime_apis! {
|
||||
impl self::Api<Block> for Runtime {
|
||||
fn test(data: &u64) {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
@@ -0,0 +1,13 @@
|
||||
error[E0053]: method `test` has an incompatible type for trait
|
||||
--> $DIR/type_reference_in_impl_runtime_apis_call.rs:20:17
|
||||
|
|
||||
14 | fn test(data: u64);
|
||||
| --- type in trait
|
||||
...
|
||||
20 | fn test(data: &u64) {
|
||||
| ^^^^ expected u64, found &u64
|
||||
|
|
||||
= note: expected type `fn(u64)`
|
||||
found type `fn(&u64)`
|
||||
|
||||
For more information about this error, try `rustc --explain E0053`.
|
||||
Reference in New Issue
Block a user