use std::process::Command;
fn boundary_cmd() -> Command {
Command::new(env!("CARGO_BIN_EXE_boundary"))
}
fn fixture(name: &str) -> String {
format!("{}/tests/fixtures/{name}", env!("CARGO_MANIFEST_DIR"))
}
#[test]
fn custom_rule_matching_produces_custom_violation() {
let output = boundary_cmd()
.args(["analyze", &fixture("fr7-custom-rules")])
.output()
.expect("failed to run boundary analyze");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success(),
"exit code should be 0: stdout={stdout}"
);
assert!(
stdout.contains("custom"),
"output should contain a custom rule violation type: {stdout}"
);
}
#[test]
fn custom_rule_violation_has_configured_severity() {
let output = boundary_cmd()
.args(["analyze", &fixture("fr7-custom-rules")])
.output()
.expect("failed to run boundary analyze");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success(),
"exit code should be 0: stdout={stdout}"
);
assert!(
stdout.to_lowercase().contains("warn"),
"custom violation should have warning severity: {stdout}"
);
}
#[test]
fn custom_rule_violation_message_from_config() {
let output = boundary_cmd()
.args(["analyze", &fixture("fr7-custom-rules")])
.output()
.expect("failed to run boundary analyze");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success(),
"exit code should be 0: stdout={stdout}"
);
assert!(
stdout.contains("Domain must not import external packages"),
"custom violation should include the configured message: {stdout}"
);
}
#[test]
fn non_matching_rule_produces_no_custom_violation() {
let output = boundary_cmd()
.args(["analyze", &fixture("full-ddd-module")])
.output()
.expect("failed to run boundary analyze");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success(),
"exit code should be 0: stdout={stdout}"
);
assert!(
!stdout.contains("custom:"),
"output should not contain custom rule violations when none match: {stdout}"
);
}
#[test]
fn custom_rule_warning_does_not_trigger_check_at_error_threshold() {
let output = boundary_cmd()
.args(["check", &fixture("fr7-custom-rules"), "--fail-on", "error"])
.output()
.expect("failed to run boundary check");
let stdout = String::from_utf8_lossy(&output.stdout);
assert!(
output.status.success(),
"check --fail-on error should exit 0 when only warning-level custom violations present: stdout={stdout}"
);
}