From ea7267dfc2914cdc340bae1a823c0660daef19e6 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 17 Nov 2023 11:47:55 +0100 Subject: Add UI tests for macros error message --- testing/tests/ui/macro.rs | 27 +++++++++++++++++++++++++++ testing/tests/ui/macro.stderr | 23 +++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 testing/tests/ui/macro.rs create mode 100644 testing/tests/ui/macro.stderr (limited to 'testing') diff --git a/testing/tests/ui/macro.rs b/testing/tests/ui/macro.rs new file mode 100644 index 0000000..01c64bf --- /dev/null +++ b/testing/tests/ui/macro.rs @@ -0,0 +1,27 @@ +use askama::Template; + +#[derive(Template)] +#[template(source = "{%- macro thrice(param) -%} +{{ param }} +{%- endmacro -%} + +{%- call thrice(2, 3) -%}", ext = "html")] +struct InvalidNumberOfArgs; + +#[derive(Template)] +#[template(source = "{%- macro thrice(param, param2) -%} +{{ param }} {{ param2 }} +{%- endmacro -%} + +{%- call thrice() -%}", ext = "html")] +struct InvalidNumberOfArgs2; + +#[derive(Template)] +#[template(source = "{%- macro thrice() -%} +{%- endmacro -%} + +{%- call thrice(1, 2) -%}", ext = "html")] +struct InvalidNumberOfArgs3; + +fn main() { +} diff --git a/testing/tests/ui/macro.stderr b/testing/tests/ui/macro.stderr new file mode 100644 index 0000000..5471c96 --- /dev/null +++ b/testing/tests/ui/macro.stderr @@ -0,0 +1,23 @@ +error: macro "thrice" expected 1 argument, found 2 + --> tests/ui/macro.rs:3:10 + | +3 | #[derive(Template)] + | ^^^^^^^^ + | + = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: macro "thrice" expected 2 arguments, found 0 + --> tests/ui/macro.rs:11:10 + | +11 | #[derive(Template)] + | ^^^^^^^^ + | + = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: macro "thrice" expected 0 arguments, found 2 + --> tests/ui/macro.rs:19:10 + | +19 | #[derive(Template)] + | ^^^^^^^^ + | + = note: this error originates in the derive macro `Template` (in Nightly builds, run with -Z macro-backtrace for more info) -- cgit