use super::{assert_reported, assert_silent_about, codes_in, codes_of};
use crate::DiagnosticCode;
#[test]
fn an_include_that_was_not_found_is_reported() {
let angled = codes_of("#include <vectr>\nint main() { return 0; }\n");
assert_reported(
&angled,
DiagnosticCode::IncludeNotFound,
"`<vectr>` is not a header",
);
let quoted = codes_of("#include \"helpr.h\"\nint main() { return 0; }\n");
assert_reported(
"ed,
DiagnosticCode::IncludeNotFound,
"nothing beside the file is called `helpr.h`",
);
}
#[test]
fn a_quoted_include_that_exists_is_not_reported() {
let codes = codes_in(
&[
("/p/api.h", "int declared_in_the_header();\n"),
("/p/a.cpp", "#include \"api.h\"\nint main() { return 0; }\n"),
],
"/p/a.cpp",
);
assert_silent_about(
&codes,
DiagnosticCode::IncludeNotFound,
"the quoted header is in the file's own directory",
);
}
#[test]
fn an_include_that_names_a_macro_is_not_reported() {
let codes =
codes_of("#define HEADER <boost/version.hpp>\n#include HEADER\nint main() { return 0; }\n");
assert_silent_about(
&codes,
DiagnosticCode::IncludeNotFound,
"the directive's target is a macro, not a literal path",
);
}
#[test]
fn an_unresolved_include_in_another_file_is_not_this_files_finding() {
let codes = codes_in(
&[
(
"/p/broken.h",
"#include <nowhere_at_all>\nint declared_in_the_header();\n",
),
(
"/p/a.cpp",
"#include \"broken.h\"\nint main() { return 0; }\n",
),
],
"/p/a.cpp",
);
assert_silent_about(
&codes,
DiagnosticCode::IncludeNotFound,
"the missing header is written in `broken.h`, not here",
);
}
#[test]
fn an_include_in_a_branch_nobody_takes_is_not_reported() {
let codes = codes_of("#if 0\n#include <vectr>\n#endif\nint main() { return 0; }\n");
assert_silent_about(
&codes,
DiagnosticCode::IncludeNotFound,
"`#if 0` is a branch no compiler reads",
);
}
#[test]
fn an_include_in_a_branch_that_is_taken_is_still_reported() {
let codes = codes_of("#if 1\n#include <vectr>\n#endif\nint main() { return 0; }\n");
assert_reported(
&codes,
DiagnosticCode::IncludeNotFound,
"`#if 1` is compiled",
);
}
#[test]
fn an_include_behind_an_undecided_guard_is_still_reported() {
let codes = codes_of(
"#ifdef NEVER_DEFINED_ANYWHERE\n#include <vectr>\n#endif\nint main() { return 0; }\n",
);
assert_reported(
&codes,
DiagnosticCode::IncludeNotFound,
"nothing defines that macro, but this layer cannot know it",
);
}