use crate::{
CompilerConfig, DiagnosticCode, MemoryFiles, OpenDocuments, Session, SessionFiles, WatchFilter,
};
pub(super) fn codes_of(source: &str) -> Vec<DiagnosticCode> {
codes_in(&[("/p/a.cpp", source)], "/p/a.cpp")
}
pub(super) fn codes_in(files: &[(&str, &str)], asking: &str) -> Vec<DiagnosticCode> {
session_with(files, asking)
.diagnostics(std::path::Path::new(asking))
.map(|found| {
found
.checks
.iter()
.map(|finding| finding.code)
.chain(found.errors.iter().map(|error| error.code))
.collect()
})
.unwrap_or_default()
}
pub(super) fn named_findings_in(
files: &[(&str, &str)],
asking: &str,
) -> Vec<(DiagnosticCode, String)> {
session_with(files, asking)
.diagnostics(std::path::Path::new(asking))
.map(|found| {
found
.checks
.iter()
.map(|finding| (finding.code, finding.name.clone()))
.chain(found.errors.iter().map(|error| (error.code, String::new())))
.collect()
})
.unwrap_or_default()
}
pub(super) fn assert_silent_about(codes: &[DiagnosticCode], code: DiagnosticCode, why: &str) {
assert!(
!codes.contains(&code),
"{why} (the file produced {codes:?})"
);
}
pub(super) fn assert_reported(codes: &[DiagnosticCode], code: DiagnosticCode, why: &str) {
assert!(codes.contains(&code), "{why} (the file produced {codes:?})");
}
fn session_with(files: &[(&str, &str)], asking: &str) -> Session<MemoryFiles> {
let mut memory = MemoryFiles::new();
for (path, text) in files {
memory = memory.with_file(*path, *text);
}
let providers = SessionFiles::new(OpenDocuments::new(), memory);
let mut session = Session::with_config(
"/p",
providers,
WatchFilter::new("/p"),
CompilerConfig::default(),
);
session.add_project_files(
files
.iter()
.map(|(path, _)| std::path::PathBuf::from(*path)),
);
session.want_cooked_reading(std::path::Path::new(asking));
session.index_everything();
session
}
mod abstract_class_instantiated;
mod access_invisible;
mod argument_count;
mod assignment_in_condition;
mod braces_around_statements;
mod concept_not_satisfied;
mod contract_placement;
mod cstyle_cast;
mod dangling_field;
mod dangling_return;
mod else_after_return;
mod final_hierarchy;
mod final_misplaced;
mod implicit_bool_conversion;
mod include_not_found;
mod macro_parentheses;
mod macro_redefined;
mod missing_include;
mod missing_return;
mod override_nonexistent;
mod pure_virtual_not_overridden;
mod redefinition;
mod return_type_mismatch;
mod simplify_boolean_expr;
mod syntax_error;
mod undefined_field;
mod undefined_name;
mod unnecessary_branch;
mod unused;
mod use_after_free;
mod use_auto;
mod use_nullptr;
mod use_override;