Skip to content

Commit 66ec060

Browse files
committed
Add tests for bad format syntax
1 parent 7e0c8dd commit 66ec060

File tree

5 files changed

+30
-0
lines changed

5 files changed

+30
-0
lines changed

tests/fmt_missing_arg.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use fn_error_context::error_context;
2+
3+
#[error_context("{}")]
4+
fn do_stuff() -> anyhow::Result<()> {
5+
anyhow::bail!("error")
6+
}
7+
8+
fn main() {}

tests/fmt_missing_arg.stderr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
error: 1 positional argument in format string, but no arguments were given
2+
--> $DIR/fmt_missing_arg.rs:3:18
3+
|
4+
3 | #[error_context("{}")]
5+
| ^^

tests/fmt_unused_arg.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
use fn_error_context::error_context;
2+
3+
#[error_context("context", 1)]
4+
fn do_stuff() -> anyhow::Result<()> {
5+
anyhow::bail!("error")
6+
}
7+
8+
fn main() {}

tests/fmt_unused_arg.stderr

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error: argument never used
2+
--> $DIR/fmt_unused_arg.rs:3:28
3+
|
4+
3 | #[error_context("context", 1)]
5+
| --------- ^ argument never used
6+
| |
7+
| formatting specifier missing

tests/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@ fn tests() {
1212
tests.pass("tests/non_copy_arg.rs");
1313
tests.pass("tests/non_copy_fmt_arg.rs");
1414
tests.pass("tests/as_ref.rs");
15+
tests.compile_fail("tests/fmt_missing_arg.rs");
16+
tests.compile_fail("tests/fmt_unused_arg.rs");
1517
}

0 commit comments

Comments
 (0)