Skip to content

Commit

Permalink
#111: Error message when type doesn't implement
Browse files Browse the repository at this point in the history
FromStr
  • Loading branch information
la10736 committed Apr 5, 2021
1 parent 666b931 commit 8e3dfe9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
32 changes: 16 additions & 16 deletions tests/resources/rstest/errors.rs
@@ -1,6 +1,8 @@
use rstest::*;
#[fixture]
pub fn fixture() -> u32 { 42 }
pub fn fixture() -> u32 {
42
}

#[rstest(f, case(42))]
fn error_inner(f: i32) {
Expand All @@ -24,8 +26,7 @@ fn error_in_arbitrary_rust_code_cases(condition: bool) {
}

#[rstest(f, case(42), not_a_fixture(24))]
fn error_inject_an_invalid_fixture(f: u32) {
}
fn error_inject_an_invalid_fixture(f: u32) {}

#[fixture]
fn n() -> u32 {
Expand All @@ -34,20 +35,17 @@ fn n() -> u32 {

#[fixture]
fn f(n: u32) -> u32 {
2*n
2 * n
}

#[rstest(f, f(42), case(12))]
fn error_inject_a_fixture_that_is_already_a_case(f: u32) {
}
fn error_inject_a_fixture_that_is_already_a_case(f: u32) {}

#[rstest(f(42), f, case(12))]
fn error_define_case_that_is_already_an_injected_fixture(f: u32) {
}
fn error_define_case_that_is_already_an_injected_fixture(f: u32) {}

#[rstest(v, f(42), f(42), case(12))]
fn error_inject_a_fixture_more_than_once(v: u32, f: u32) {
}
fn error_inject_a_fixture_more_than_once(v: u32, f: u32) {}

#[rstest(f => [42])]
fn error_matrix_wrong_type(f: &str) {}
Expand All @@ -65,12 +63,10 @@ fn error_empty_list(empty: &str) {}
fn error_no_match_args() {}

#[rstest(f => [41, 42], f(42))]
fn error_inject_a_fixture_that_is_already_a_value_list(f: u32) {
}
fn error_inject_a_fixture_that_is_already_a_value_list(f: u32) {}

#[rstest(f(42), f => [41, 42])]
fn error_define_a_value_list_that_is_already_an_injected_fixture(f: u32) {
}
fn error_define_a_value_list_that_is_already_an_injected_fixture(f: u32) {}

#[rstest(a, case(42), a => [42])]
fn error_define_a_value_list_that_is_already_a_case_arg(a: u32) {}
Expand All @@ -79,8 +75,12 @@ fn error_define_a_value_list_that_is_already_a_case_arg(a: u32) {}
fn error_define_a_case_arg_that_is_already_a_value_list(a: u32) {}

#[rstest(a => [42, 24], a => [24, 42])]
fn error_define_a_value_list_that_is_already_a_value_list(f: u32) {
}
fn error_define_a_value_list_that_is_already_a_value_list(f: u32) {}

#[rstest(a, a, case(42))]
fn error_define_a_case_arg_that_is_already_a_case_arg(a: u32) {}

struct S;
#[rstest]
#[case("donald duck")]
fn error_convert_to_type_that_not_implement_from_str(#[case] s: S) {}
19 changes: 19 additions & 0 deletions tests/rstest/mod.rs
Expand Up @@ -1256,4 +1256,23 @@ mod should_show_correct_errors {
.unindent()
);
}

#[test]
fn if_try_to_convert_literal_string_to_a_type_that_not_implement_from_str() {
let (output, name) = execute();

assert_in!(
output.stderr.str(),
format!(
"
--> {}/src/lib.rs:84:1
|
83 | struct S;
| --------- doesn't satisfy `S: FromStr`
",
name
)
.unindent()
);
}
}

0 comments on commit 8e3dfe9

Please sign in to comment.