use scythe_codegen::validation::{ValidationOutcome, validate_generated_code};
#[test]
fn no_validator_for_the_backends_language_reports_unsupported() {
let outcome = validate_generated_code("public class Foo {}", "csharp-npgsql");
assert_eq!(outcome, ValidationOutcome::Unsupported);
assert!(
!outcome.is_failure(),
"a language with no validator must not block a build -- see ValidationOutcome::is_failure"
);
}
#[test]
fn a_backend_with_a_validator_reports_passed_for_clean_input() {
let clean_code = "from dataclasses import dataclass\n\n\n@dataclass\nclass Row:\n id: int\n";
let outcome = validate_generated_code(clean_code, "python-psycopg3");
match outcome {
ValidationOutcome::Passed { tools_run, .. } => {
if !tools_run.is_empty() {
assert!(
tools_run.contains(&"poly"),
"python-psycopg3 must be checked by poly, got: {tools_run:?}"
);
}
}
other => panic!("expected Passed for clean python-psycopg3 code, got {other:?}"),
}
}
#[test]
fn a_backend_with_a_validator_reports_failed_for_broken_input() {
let broken_code = "def broken(:\n this is not python\n";
let outcome = validate_generated_code(broken_code, "python-psycopg3");
match outcome {
ValidationOutcome::Failed { tools_run, errors, .. } => {
assert!(
!tools_run.is_empty(),
"a Failed outcome must name at least one checker that actually ran"
);
assert!(!errors.is_empty(), "a Failed outcome must carry at least one finding");
}
ValidationOutcome::Passed { tools_run, .. } => {
assert!(
tools_run.is_empty(),
"broken Python passed even though a checker ran against it: {tools_run:?}"
);
}
ValidationOutcome::Unsupported => {
panic!("python-psycopg3 has a real validator and must not report Unsupported")
}
}
}