use cpp_code_analysis::{
CompilerConfig, MemoryFiles, OpenDocuments, Session, SessionFiles, WatchFilter,
};
#[test]
fn a_fragment_header_reports_its_own_refusal_not_the_cascade() {
let fragment = "\
#ifndef I_AM_A_TABLE
# error \"This is not a public header, do not include it directly\"
#endif
{ 3, \"US-ASCII\" },
{ 3, \"iso-ir-6\" },
{ 3, \"ANSI_X3.4-1968\" },
";
let main = "#include \"data.h\"\nint main() { return 0; }\n";
let files = MemoryFiles::new()
.with_file("/p/data.h", fragment)
.with_file("/p/main.cpp", main);
let providers = SessionFiles::new(OpenDocuments::new(), files);
let mut session = Session::with_config(
"/p",
providers,
WatchFilter::new("/p"),
CompilerConfig::default(),
);
session.add_project_files([std::path::PathBuf::from("/p/main.cpp")]);
session.want_cooked_reading(std::path::Path::new("/p/main.cpp"));
session.want_cooked_reading(std::path::Path::new("/p/data.h"));
session.index_everything();
let found = session
.diagnostics("/p/data.h")
.expect("the fragment has a reading");
println!(
"errors={} first={:?}",
found.errors.len(),
found
.errors
.first()
.map(|error| (&error.message, error.start))
);
assert_eq!(
found.errors.len(),
1,
"one refusal, not the cascade it causes: {:?}",
found
.errors
.iter()
.map(|error| error.message.as_str())
.take(4)
.collect::<Vec<_>>()
);
assert!(
found.errors[0].message.contains("not a public header"),
"{:?}",
found.errors[0].message
);
}