use crate::snippets::types::{Language, ValidationLevel};
pub(crate) const NO_SESSION_CONFIGURED_PHRASE: &str = "no snippet validation session is configured for";
pub(crate) fn unresolved_dependency_message(
no_session_configured: bool,
language: Language,
effective_level: ValidationLevel,
raw_output: &str,
) -> String {
if no_session_configured {
format!(
"could not validate at {effective_level}: {NO_SESSION_CONFIGURED_PHRASE} {language} snippets, so \
this one ran in an isolated scratch directory with no access to the crate's built package -- \
running `alef build` cannot fix this; add a `[workspace.docs.snippets.sessions.<target>]` entry \
for {language} in alef.toml so validation can see the built artifact: {raw_output}"
)
} else {
format!(
"could not validate at {effective_level}: {language} toolchain ran but reported a missing \
dependency or build artifact -- run `alef build` first if this crate validates snippets against \
built artifacts: {raw_output}"
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn no_session_configured_message_never_points_at_alef_build() {
let message =
unresolved_dependency_message(true, Language::Go, ValidationLevel::Compile, "cannot find package");
assert!(message.contains(NO_SESSION_CONFIGURED_PHRASE), "{message}");
assert!(
!message.contains("run `alef build`"),
"no-session message must not tell the reader to rebuild: {message}"
);
assert!(
message.contains("cannot find package"),
"raw validator output must survive: {message}"
);
}
#[test]
fn ordering_message_still_points_at_alef_build() {
let message =
unresolved_dependency_message(false, Language::Go, ValidationLevel::Compile, "cannot find package");
assert!(message.contains("run `alef build` first"), "{message}");
assert!(!message.contains(NO_SESSION_CONFIGURED_PHRASE), "{message}");
assert!(
message.contains("cannot find package"),
"raw validator output must survive: {message}"
);
}
}