Skip to content

Commit

Permalink
Add tests for uniqueness of route macros
Browse files Browse the repository at this point in the history
  • Loading branch information
cormacrelf committed May 28, 2024
1 parent 8a1bb81 commit e50346e
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/codegen/tests/ui-pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[test]
fn ui() {
let t = trybuild::TestCases::new();
t.pass(format!("tests/ui-pass/*.rs"));
}
27 changes: 27 additions & 0 deletions core/codegen/tests/ui-pass/route-uniqueness-generated.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#[macro_use] extern crate rocket;

// Makes sure that the hashing of the proc macro's call site span
// is enough, even if we're inside a declarative macro
macro_rules! gen_routes {
() => {
#[get("/")]
fn index() -> &'static str {
"GET"
}

mod two {
#[get("/")]
fn index() -> &'static str {
"GET"
}
}
}
}

gen_routes!();

mod module {
gen_routes!();
}

fn main() {}
18 changes: 18 additions & 0 deletions core/codegen/tests/ui-pass/route-uniqueness.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#[macro_use] extern crate rocket;

#[get("/")]
fn index() -> &'static str {
"GET"
}

mod module {
// This one has all the same macro inputs, and we need it to
// generate a crate-wide unique identifier for the macro it
// defines.
#[get("/")]
pub fn index() -> &'static str {
"whatever"
}
}

fn main() {}

0 comments on commit e50346e

Please sign in to comment.