Conversation
8dc3421 to
df00dd5
Compare
cli/src/utils.rs
Outdated
| /// Given a type definition, return type ID and registry representing it. | ||
| #[allow(dead_code)] | ||
| pub fn make_type<T: scale_info::TypeInfo + 'static>() -> (u32, scale_info::PortableRegistry) { | ||
| let m = scale_info::MetaType::new::<T>(); | ||
| let mut types = scale_info::Registry::new(); | ||
| let id = types.register_type(&m); | ||
| let portable_registry: scale_info::PortableRegistry = types.into(); | ||
| (id.id, portable_registry) | ||
| } |
There was a problem hiding this comment.
move this to the test mod, or mark as #[cfg(test)] if it's used by other tests, to avoid the #[allow(dead_code)] (and make clear it's only used in testing)
jsdw
left a comment
There was a problem hiding this comment.
Looks good; I'll always suggest preferring unit tests over e2e style ones whenever possible, but good to have the option to test the output too for when it's harder to do that (or there's something we want to ensure we are outputting) :)
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_commands() { |
There was a problem hiding this comment.
I would prefer to split this test into smaller ones because it's much harder to debug if something breaks.
There was a problem hiding this comment.
Sure, I will split it up in another PR today.
| let (foo_type_id, foo_registry) = make_type::<Foo>(); | ||
| let description = print_type_description(&foo_type_id, &foo_registry).unwrap(); | ||
| let mut output = String::new(); | ||
| writeln!(output, "struct Foo {{").unwrap(); |
There was a problem hiding this comment.
may this works as well:
let s = r#"struct Foo {
hello: String,
num: i32
}"#;
partly fixes #946
I added a Writer (
&mut impl std::io::Write) to each cli command such that we can write to it instead ofstdout.This makes it easy to test the expected output of each command.
Added tests for some commands.