tauri-apps/tauri · error · syn::Error
unexpected value for test
Error message
unexpected value for test
What it means
The test key of #[tauri::generate_context] toggles test mode (for example, skipping asset embedding so `cargo test` stays fast). Its value must be a boolean literal (Expr::Lit with Lit::Bool); the macro explicitly pattern-matches for it. Any other value — a quoted string, an ident, a const, Some(true) — fails with 'unexpected value for test'.
Source
Thrown at crates/tauri-macros/src/context.rs:106
} else {
return Err(syn::Error::new(
input.span(),
"unexpected value for capabilities",
));
}
}
"assets" => {
assets.replace(v.value);
}
"test" => {
if let Expr::Lit(ExprLit {
lit: Lit::Bool(LitBool { value, .. }),
..
}) = v.value
{
test = value;
} else {
return Err(syn::Error::new(input.span(), "unexpected value for test"));
}
}
name => {
return Err(syn::Error::new(
input.span(),
format!("unknown attribute {name}"),
));
}
}
}
Meta::List(_) => {
return Err(syn::Error::new(input.span(), "unexpected list input"));
}
}
let _ = input.parse::<Token![,]>();
}
View on GitHub (pinned to 52e4b6e71d)
Solutions
- Use the literal: #[tauri::generate_context(test = true)] or omit it (defaults to false)
- For test-only behavior, gate tests with #[cfg(test)] instead of the attribute value
- Remember macro attributes are static: build a generated invocation from build.rs if config must vary
Example fix
// before #[tauri::generate_context(test = "true")] // after #[tauri::generate_context(test = true)]
Defensive patterns
Strategy: validation
Prevention
- test takes a literal bool: test = true
- Do not quote booleans out of JSON habit
- Use #[cfg(test)] on the tests themselves instead of conditional attribute values
When it happens
Trigger: #[tauri::generate_context(test = "true")], test = 1, or test = cfg!(test) / is_ci() — every non-literal-bool expression trips the else branch.
Common situations: Quoting true out of JSON habit; trying to enable test mode conditionally per cfg profile; assuming runtime/compile-time expressions are allowed in attribute values.
Related errors
- unexpected expression for capability
- unexpected value for capabilities
- unknown attribute {name}
- unexpected list input
- unexpected list input
AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20).
Data as JSON: /api/errors/0880ffd662fd7f34.
Report an issue: GitHub.