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
";
const JAVA_MISSING_PACKAGE_WITH_CASCADE: &str = "\
Example.java:1: error: package dev.sample.bindings does not exist
import dev.sample.bindings.*;
^
Example.java:5: error: cannot find symbol
BindingClient client = new BindingClient();
^
symbol: class BindingClient
location: class Example
3 errors
";
fn java_missing_package_mixed_with_a_real_defect() -> String {
format!("{JAVA_MISSING_PACKAGE}{JAVA_MISSING_MEMBER}")
}
#[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 java_missing_package_cascade_is_still_a_missing_dependency() {
assert!(
JavaValidator.is_dependency_error(JAVA_MISSING_PACKAGE_WITH_CASCADE),
"a `cannot find symbol` cascade from an established missing package must reclassify too: \
{JAVA_MISSING_PACKAGE_WITH_CASCADE}"
);
}
#[test]
fn java_missing_package_mixed_with_a_real_member_defect_is_not_a_missing_dependency() {
let output = java_missing_package_mixed_with_a_real_defect();
assert!(
!JavaValidator.is_dependency_error(&output),
"a real member-access defect alongside a root cause must not be relabeled: {output}"
);
}
#[test]
fn java_symbol_cascade_shape_with_no_root_cause_is_not_a_missing_dependency() {
let output = "\
Example.java:5: error: cannot find symbol
BindingClient client = new BindingClient();
^
symbol: class BindingClient
location: class Example
1 error
";
assert!(
!JavaValidator.is_dependency_error(output),
"no root-cause diagnostic is present, so this must not be relabeled: {output}"
);
}
#[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}"
);
}
const GO_MISSING_LINKER_LIBRARY_GNU: &str = "\
# github.com/sample/module
/usr/bin/ld: cannot find -lsample_ffi: No such file or directory
collect2: error: ld returned 1 exit status
";
const GO_MISSING_LINKER_LIBRARY_APPLE: &str = "\
# github.com/sample/module
ld: library not found for -lsample_ffi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
";
const GO_MISSING_LINKER_LIBRARY_LLD: &str = "\
# github.com/sample/module
ld.lld: error: unable to find library -lsample_ffi
clang: error: linker command failed with exit code 1 (use -v to see invocation)
";
const GO_MISSING_LINKER_LIBRARY_APPLE_QUOTED: &str = "\
/opt/homebrew/Cellar/go/1.27.0/libexec/pkg/tool/darwin_arm64/link: running cc failed: exit status 1
ld: warning: search path '/repo/packages/go/.lib/macos-arm64' not found
ld: library 'sample_ffi' not found
clang: error: linker command failed with exit code 1 (use -v to see invocation)
";
const GO_APPLE_QUOTED_WITH_UNDEFINED_SYMBOLS: &str = "\
ld: library 'sample_ffi' not found
Undefined symbols for architecture arm64:
\"_sample_convert_missing_symbol\", referenced from:
clang: error: linker command failed with exit code 1 (use -v to see invocation)
";
const GO_APPLE_FILE_NOT_FOUND: &str = "\
ld: file not found: /repo/packages/go/.lib/macos-arm64/libsample_ffi.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)
";
const GO_LINKER_UNDEFINED_REFERENCE: &str = "\
# github.com/sample/module
/usr/bin/ld: /tmp/go-link/000000.o: in function `main.main`:
main.go:8: undefined reference to `sample_convert_missing_symbol`
collect2: error: ld returned 1 exit status
";
#[test]
fn go_missing_linked_library_gnu_ld_is_a_missing_dependency() {
assert!(
GoValidator.is_dependency_error(GO_MISSING_LINKER_LIBRARY_GNU),
"GNU ld's `cannot find -l<name>` proves compilation succeeded and only the artifact is \
missing: {GO_MISSING_LINKER_LIBRARY_GNU}"
);
}
#[test]
fn go_missing_linked_library_apple_ld_is_a_missing_dependency() {
assert!(
GoValidator.is_dependency_error(GO_MISSING_LINKER_LIBRARY_APPLE),
"Apple ld's `library not found for -l<name>` is the same missing-artifact shape: \
{GO_MISSING_LINKER_LIBRARY_APPLE}"
);
}
#[test]
fn go_missing_linked_library_lld_is_a_missing_dependency() {
assert!(
GoValidator.is_dependency_error(GO_MISSING_LINKER_LIBRARY_LLD),
"LLVM lld's `unable to find library -l<name>` is the same missing-artifact shape: \
{GO_MISSING_LINKER_LIBRARY_LLD}"
);
}
#[test]
fn go_missing_linked_library_apple_quoted_is_a_missing_dependency() {
assert!(
GoValidator.is_dependency_error(GO_MISSING_LINKER_LIBRARY_APPLE_QUOTED),
"Apple's current linker spells a missing library `ld: library '<name>' not found`, with \
no -l anywhere; it is the same missing-artifact shape: \
{GO_MISSING_LINKER_LIBRARY_APPLE_QUOTED}"
);
}
#[test]
fn go_apple_quoted_library_with_undefined_symbols_is_not_a_missing_dependency() {
assert!(
!GoValidator.is_dependency_error(GO_APPLE_QUOTED_WITH_UNDEFINED_SYMBOLS),
"an undefined symbol means the library was found and loaded; that must keep its Fail \
even alongside the quoted missing-library line: {GO_APPLE_QUOTED_WITH_UNDEFINED_SYMBOLS}"
);
}
#[test]
fn go_apple_file_not_found_is_not_a_missing_library() {
assert!(
!GoValidator.is_dependency_error(GO_APPLE_FILE_NOT_FOUND),
"`file not found` is not the missing-library shape and must not be matched by a loose \
`not found`: {GO_APPLE_FILE_NOT_FOUND}"
);
}
#[test]
fn go_linker_undefined_reference_is_not_a_missing_dependency() {
assert!(
!GoValidator.is_dependency_error(GO_LINKER_UNDEFINED_REFERENCE),
"`undefined reference to` means the library loaded and a symbol inside it is wrong -- a \
real defect, not an unbuilt artifact: {GO_LINKER_UNDEFINED_REFERENCE}"
);
}
#[test]
fn go_missing_library_mixed_with_a_real_undefined_reference_is_not_a_missing_dependency() {
let output = format!("{GO_MISSING_LINKER_LIBRARY_GNU}{GO_LINKER_UNDEFINED_REFERENCE}");
assert!(
!GoValidator.is_dependency_error(&output),
"a run mixing a genuine unresolved-symbol defect with a missing-library diagnostic must \
not be relabeled: {output}"
);
}
#[test]
fn go_missing_library_lld_mixed_with_a_real_undefined_reference_is_not_a_missing_dependency() {
let output = format!("{GO_MISSING_LINKER_LIBRARY_LLD}{GO_LINKER_UNDEFINED_REFERENCE}");
assert!(
!GoValidator.is_dependency_error(&output),
"a run mixing a genuine unresolved-symbol defect with a missing-library diagnostic must \
not be relabeled: {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),
),
(
"go",
GoValidator.is_dependency_error(GO_MISSING_LINKER_LIBRARY_GNU),
GoValidator.is_dependency_error(GO_LINKER_UNDEFINED_REFERENCE),
),
];
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");
}
}