feat(derive): check generated handler params
Emit handle_param facts for handled data-* attributes and reject handlers that omit generated param arguments. Cover the generated param boundary with unit and compile-fail tests. req: derive_handler/001 req: test/003
This commit is contained in:
@@ -111,6 +111,58 @@ fn create() -> impl slhx::IntoEffect {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn handler_requires_generated_param_arguments() {
|
||||
// req: derive_handler/001 req: test/003
|
||||
let fixture = Fixture::new("slhx-derive-param-handler-fail");
|
||||
fixture.write(
|
||||
"Cargo.toml",
|
||||
&format!(
|
||||
r#"[package]
|
||||
name = "slhx-derive-param-handler-fail"
|
||||
version = "0.0.0"
|
||||
edition = "2021"
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
slhx = {{ path = {:?} }}
|
||||
"#,
|
||||
repo_path("slhx")
|
||||
),
|
||||
);
|
||||
fixture.write(
|
||||
"build.rs",
|
||||
r#"fn main() {
|
||||
let out = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
||||
std::fs::write(
|
||||
out.join("slhx.syms"),
|
||||
"slhx-syms-v1\nhandle\ttemplates/app.heml::show\tshow\t1\nhandle_param\tshow\ttodo_id\nhandle_param\tshow\tmode\n",
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
"#,
|
||||
);
|
||||
fixture.write(
|
||||
"src/lib.rs",
|
||||
r#"#[slhx::handler]
|
||||
fn show(todo_id: String) -> impl slhx::IntoEffect {
|
||||
slhx::EffectBatch::default()
|
||||
}
|
||||
"#,
|
||||
);
|
||||
|
||||
let output = check_fixture(&fixture);
|
||||
|
||||
assert!(!output.status.success(), "fixture unexpectedly compiled");
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
assert!(
|
||||
stderr.contains("slhx handler `show` is missing generated param argument(s): mode"),
|
||||
"missing param diagnostic in stderr:\n{stderr}"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn form_handle_requires_form_parameter() {
|
||||
// req: form/004 req: form/006 req: test/003
|
||||
|
||||
Reference in New Issue
Block a user