-
Notifications
You must be signed in to change notification settings - Fork 248
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
Cli tool tests #977
Cli tool tests #977
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
may this works as well:
let s = r#"struct Foo {
hello: String,
num: i32
}"#;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for taking care of this 💪
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.