Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions maud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ serde_json = { version = "1", optional = true }

[dev-dependencies]
serde = { version = "1", features = ["derive"] }
rustversion = "1"
trybuild = { version = "1.0.33", features = ["diff"] }

[package.metadata.docs.rs]
Expand Down
15 changes: 15 additions & 0 deletions maud/tests/errors.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
use trybuild::TestCases;

#[test]
#[rustversion::nightly]
fn run_warnings() {
let config = TestCases::new();
config.compile_fail("tests/warnings/*.rs");
}

#[test]
#[rustversion::not(nightly)]
fn run_warnings() {
let config = TestCases::new();

config.compile_fail("tests/warnings/attribute-missing-value.rs");
config.compile_fail("tests/warnings/class-shorthand-missing-value.rs");
config.compile_fail("tests/warnings/dynamic-attribute-names.rs");
config.compile_fail("tests/warnings/elements-in-attributes.rs");
config.compile_fail("tests/warnings/let-without-block.rs");
config.compile_fail("tests/warnings/non-closed-element.rs");
config.compile_fail("tests/warnings-stable/*.rs");
}
11 changes: 11 additions & 0 deletions maud/tests/warnings-stable/keyword-without-at.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use maud::html;

fn main() {
html! {
if {}
else {}
for {}
while {}
match {}
};
}
34 changes: 34 additions & 0 deletions maud/tests/warnings-stable/keyword-without-at.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
error: found keyword `if`
= help: should this be `@if`?
--> tests/warnings-stable/keyword-without-at.rs:5:9
|
5 | if {}
| ^^

error: found keyword `else`
= help: should this be `@else`?
--> tests/warnings-stable/keyword-without-at.rs:6:9
|
6 | else {}
| ^^^^

error: found keyword `for`
= help: should this be `@for`?
--> tests/warnings-stable/keyword-without-at.rs:7:9
|
7 | for {}
| ^^^

error: found keyword `while`
= help: should this be `@while`?
--> tests/warnings-stable/keyword-without-at.rs:8:9
|
8 | while {}
| ^^^^^

error: found keyword `match`
= help: should this be `@match`?
--> tests/warnings-stable/keyword-without-at.rs:9:9
|
9 | match {}
| ^^^^^
16 changes: 16 additions & 0 deletions maud/tests/warnings-stable/non-string-literal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use maud::html;

fn main() {
html! {
42
42usize
42.0
'a'
b"a"
b'a'

// `true` and `false` are only considered literals in attribute values
input disabled=true;
input disabled=false;
};
}
51 changes: 51 additions & 0 deletions maud/tests/warnings-stable/non-string-literal.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
error: literal must be double-quoted: `"42"`
--> tests/warnings-stable/non-string-literal.rs:5:9
|
5 | 42
| ^^

error: literal must be double-quoted: `"42usize"`
--> tests/warnings-stable/non-string-literal.rs:6:9
|
6 | 42usize
| ^^^^^^^

error: literal must be double-quoted: `"42.0"`
--> tests/warnings-stable/non-string-literal.rs:7:9
|
7 | 42.0
| ^^^^

error: literal must be double-quoted: `"a"`
--> tests/warnings-stable/non-string-literal.rs:8:9
|
8 | 'a'
| ^^^

error: expected string
--> tests/warnings-stable/non-string-literal.rs:9:9
|
9 | b"a"
| ^^^^

error: expected string
--> tests/warnings-stable/non-string-literal.rs:10:9
|
10 | b'a'
| ^^^^

error: attribute value must be a string
= help: to declare an empty attribute, omit the equals sign: `disabled`
= help: to toggle the attribute, use square brackets: `disabled[some_boolean_flag]`
--> tests/warnings-stable/non-string-literal.rs:13:15
|
13 | input disabled=true;
| ^^^^^^^^^^^^^

error: attribute value must be a string
= help: to declare an empty attribute, omit the equals sign: `disabled`
= help: to toggle the attribute, use square brackets: `disabled[some_boolean_flag]`
--> tests/warnings-stable/non-string-literal.rs:14:15
|
14 | input disabled=false;
| ^^^^^^^^^^^^^^
9 changes: 9 additions & 0 deletions maud/tests/warnings-stable/void-element-slash.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use maud::html;

fn main() {
html! {
br /
// Make sure we're not stopping on the first error
input type="text" /
};
}
15 changes: 15 additions & 0 deletions maud/tests/warnings-stable/void-element-slash.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error: void elements must use `;`, not `/`
= help: change this to `;`
= help: see https://github.com/lambda-fairy/maud/pull/315 for details
--> tests/warnings-stable/void-element-slash.rs:5:12
|
5 | br /
| ^

error: void elements must use `;`, not `/`
= help: change this to `;`
= help: see https://github.com/lambda-fairy/maud/pull/315 for details
--> tests/warnings-stable/void-element-slash.rs:7:27
|
7 | input type="text" /
| ^
Loading