use super::SnippetValidator;
use super::csharp::CsharpValidator;
use super::go::GoValidator;
use super::java::JavaValidator;
use super::rust::RustValidator;
use super::swift::SwiftValidator;
const RUST_UNBOUND_RESULT: &str = "\
error[E0425]: cannot find value `result` in this scope
--> src/main.rs:5:22
|
5 | println!(\"{:?}\", result.content);
| ^^^^^^ not found in this scope
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0425`.
error: could not compile `snippet` (bin \"snippet\") due to 1 previous error
";
const RUST_MISSING_CRATE: &str = "\
error[E0432]: unresolved import `sample_bindings`
--> src/main.rs:1:5
|
1 | use sample_bindings::convert;
| ^^^^^^^^^^^^^^^^ use of unresolved module or unlinked crate `sample_bindings`
error: aborting due to 1 previous error
error: could not compile `snippet` (bin \"snippet\") due to 1 previous error
";
const JAVA_MISSING_MEMBER: &str = "\
Example.java:12: error: cannot find symbol
System.out.println(result.error().statusCode());
^
symbol: method error()
location: variable result of type BatchObject
1 error
";
const JAVA_MISSING_PACKAGE: &str = "\
Example.java:1: error: package dev.sample.bindings does not exist
import dev.sample.bindings.*;
^
1 error
";
#[test]
fn rust_unbound_result_is_a_compile_error_not_a_missing_dependency() {
assert!(
!RustValidator.is_dependency_error(RUST_UNBOUND_RESULT),
"E0425 on a name the snippet itself was supposed to bind is a codegen defect, not an \
unbuilt artifact: {RUST_UNBOUND_RESULT}"
);
}
#[test]
fn rust_unresolved_crate_import_is_still_a_missing_dependency() {
assert!(
RustValidator.is_dependency_error(RUST_MISSING_CRATE),
"E0432 against the binding crate is the genuine `alef build` case: {RUST_MISSING_CRATE}"
);
}
#[test]
fn rust_type_mismatch_is_not_a_missing_dependency() {
let output = "\
error[E0308]: mismatched types
--> src/main.rs:3:26
|
3 | let value: String = 1;
| ------ ^ expected `String`, found integer
error: aborting due to 1 previous error
";
assert!(
!RustValidator.is_dependency_error(output),
"E0308 is a type error, not a missing dependency: {output}"
);
}
#[test]
fn rust_mixed_output_is_not_a_missing_dependency() {
let output = format!("{RUST_MISSING_CRATE}{RUST_UNBOUND_RESULT}");
assert!(
!RustValidator.is_dependency_error(&output),
"a run mixing a genuine defect with an unresolved import must not be relabeled: {output}"
);
}
#[test]
fn java_missing_member_is_a_compile_error_not_a_missing_dependency() {
assert!(
!JavaValidator.is_dependency_error(JAVA_MISSING_MEMBER),
"`cannot find symbol` for a method on a type that resolved is a codegen defect: {JAVA_MISSING_MEMBER}"
);
}
#[test]
fn java_missing_package_is_still_a_missing_dependency() {
assert!(
JavaValidator.is_dependency_error(JAVA_MISSING_PACKAGE),
"`package ... does not exist` is the genuine unbuilt-artifact shape: {JAVA_MISSING_PACKAGE}"
);
}
#[test]
fn go_undefined_local_is_not_a_missing_dependency() {
let output = "./main.go:9:14: undefined: result\n";
assert!(
!GoValidator.is_dependency_error(output),
"`undefined:` alone cannot distinguish a defect from an unbuilt package: {output}"
);
}
#[test]
fn go_missing_module_is_still_a_missing_dependency() {
let output = "main.go:4:2: no required module provides package example.com/binding; to add it:\n";
assert!(
GoValidator.is_dependency_error(output),
"an unprovided module is the genuine dependency shape: {output}"
);
}
#[test]
fn swift_unresolved_name_is_not_a_missing_dependency() {
let output = "snippet.swift:7:13: error: cannot find 'result' in scope\n";
assert!(
!SwiftValidator::default().is_dependency_error(output),
"`cannot find ... in scope` is ambiguous and must not be relabeled: {output}"
);
}
#[test]
fn swift_missing_module_is_still_a_missing_dependency() {
let output = "snippet.swift:1:8: error: no such module 'SampleBindings'\n";
assert!(
SwiftValidator::default().is_dependency_error(output),
"`no such module` is the genuine unbuilt-artifact shape: {output}"
);
}
#[test]
fn csharp_unresolved_name_is_not_a_missing_dependency() {
let output = "Program.cs(9,13): error CS0103: The name 'result' does not exist in the current context\n";
assert!(
!CsharpValidator.is_dependency_error(output),
"CS0103 is ambiguous and must not be relabeled: {output}"
);
}
#[test]
fn csharp_missing_namespace_is_still_a_missing_dependency() {
let output = "Program.cs(1,7): error CS0246: The type or namespace name 'SampleBindings' could not be found\n";
assert!(
CsharpValidator.is_dependency_error(output),
"CS0246 is the genuine unbuilt-package shape: {output}"
);
}
#[test]
fn every_validator_answers_both_directions() {
let cases: Vec<(&str, bool, bool)> = vec![
(
"rust",
RustValidator.is_dependency_error(RUST_MISSING_CRATE),
RustValidator.is_dependency_error(RUST_UNBOUND_RESULT),
),
(
"java",
JavaValidator.is_dependency_error(JAVA_MISSING_PACKAGE),
JavaValidator.is_dependency_error(JAVA_MISSING_MEMBER),
),
];
for (language, positive, negative) in cases {
assert!(positive, "{language}: the genuine dependency shape must classify");
assert!(!negative, "{language}: the compile-error shape must not classify");
}
}