forge
Explore
Log in

Don't you dare go Hollow

forge

Clone
★ 0

0 watching0 forksRustAGPL-3.07.1 MiB490f099Tahinli7 hours ago322 commits

route_list_tests.rs35 lines, 1.4 KiBHistoryRawDownload
1//! Every route, page, layout and layer that `discover()` finds, against `routes.snap`. Moving code
2//! between crates must not lose one: a crate the binary does not link drops all of its routes.
3//! `FORGE_BLESS=1` rewrites the snapshot.
4
5use topcoat::internal::inventory;
6use topcoat::router::{Layer, Layout, Page, Route};
7
8fn listed() -> String {
9 let mut lines: Vec<String> = Vec::new();
10 for route in inventory::iter::<&'static dyn Route>() {
11 lines.push(format!("route {} {:?}", route.path(), route.methods()));
12 }
13 for page in inventory::iter::<&'static dyn Page>() {
14 lines.push(format!("page {} {:?}", page.path(), page.methods()));
15 }
16 for layout in inventory::iter::<&'static dyn Layout>() {
17 lines.push(format!("layout {}", layout.path()));
18 }
19 for layer in inventory::iter::<&'static dyn Layer>() {
20 lines.push(format!("layer {:?}", layer.path().map(ToString::to_string)));
21 }
22 lines.sort();
23 lines.join("\n") + "\n"
24}
25
26#[test]
27fn discovered_routes_match_the_snapshot() {
28 let path = concat!(env!("CARGO_MANIFEST_DIR"), "/src/routes.snap");
29 let now = listed();
30 if std::env::var_os("FORGE_BLESS").is_some() {
31 std::fs::write(path, &now).unwrap();
32 }
33 let want = std::fs::read_to_string(path).unwrap_or_default();
34 assert!(now == want, "discovered routes differ from src/routes.snap");
35}