#![forbid(unsafe_code)]
pub mod errors;
pub mod exit;
pub mod warnings;
#[derive(Debug, serde::Serialize)]
pub struct CodeMeta {
pub name: &'static str,
pub category: &'static str,
pub description: &'static str,
pub exit_code: Option<i32>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn every_error_const_value_matches_its_name() {
for meta in errors::ALL {
assert!(
meta.name.starts_with("ERR_AUBE_"),
"error codes must use the ERR_AUBE_ prefix: {}",
meta.name
);
assert!(
!meta.description.is_empty(),
"error code {} is missing a description",
meta.name
);
assert!(
!meta.category.is_empty(),
"error code {} is missing a category",
meta.name
);
}
}
#[test]
fn every_warning_const_value_matches_its_name() {
for meta in warnings::ALL {
assert!(
meta.name.starts_with("WARN_AUBE_"),
"warning codes must use the WARN_AUBE_ prefix: {}",
meta.name
);
assert!(
!meta.description.is_empty(),
"warning code {} is missing a description",
meta.name
);
assert!(
!meta.category.is_empty(),
"warning code {} is missing a category",
meta.name
);
assert!(
meta.exit_code.is_none(),
"warning {} has an exit_code; warnings don't change exit status",
meta.name
);
}
}
#[test]
fn no_duplicate_codes() {
use std::collections::HashSet;
let all: Vec<&str> = errors::ALL
.iter()
.chain(warnings::ALL.iter())
.map(|m| m.name)
.collect();
let unique: HashSet<&str> = all.iter().copied().collect();
assert_eq!(
all.len(),
unique.len(),
"duplicate code identifier across errors/warnings"
);
}
}