in src/compiler/c.rs [1931:2041]
fn test_process_preprocessor_line_fs_access() {
env_logger::builder()
.is_test(true)
.filter_level(log::LevelFilter::Debug)
.try_init()
.ok();
// Test "too new" include file
let mut include_files = HashMap::new();
let fs_impl = TestFs {
metadata_results: Mutex::new(
[(
PathBuf::from("/usr/include/x86_64-linux-gnu/bits/libc-header-start.h"),
PreprocessorFileMetadata {
is_dir: false,
is_file: true,
modified: Some(Timestamp::new(i64::MAX - 1, 0)),
ctime_or_creation: None,
},
)]
.into_iter()
.collect(),
),
open_results: Mutex::new(VecDeque::new()),
};
assert_eq!(
do_single_preprocessor_line_call(
br#"// # 33 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 3 4"#,
&mut include_files,
&fs_impl,
false,
),
// preprocessor cache mode is disabled
ControlFlow::Break((63, 9, false)),
);
// Test invalid include file is actually a dir
let mut include_files = HashMap::new();
let fs_impl = TestFs {
metadata_results: Mutex::new(
[(
PathBuf::from("/usr/include/x86_64-linux-gnu/bits/libc-header-start.h"),
PreprocessorFileMetadata {
is_dir: true,
is_file: false,
modified: Some(Timestamp::new(12341234, 0)),
ctime_or_creation: None,
},
)]
.into_iter()
.collect(),
),
open_results: Mutex::new(VecDeque::new()),
};
assert_eq!(
do_single_preprocessor_line_call(
br#"// # 33 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 3 4"#,
&mut include_files,
&fs_impl,
false,
),
// preprocessor cache mode is *not* disabled,
ControlFlow::Continue((63, 63)),
);
assert_eq!(include_files.len(), 0);
// Test correct include file
let mut include_files = HashMap::new();
let fs_impl = TestFs {
metadata_results: Mutex::new(
[(
PathBuf::from("/usr/include/x86_64-linux-gnu/bits/libc-header-start.h"),
PreprocessorFileMetadata {
is_dir: false,
is_file: true,
modified: Some(Timestamp::new(12341234, 0)),
ctime_or_creation: None,
},
)]
.into_iter()
.collect(),
),
open_results: Mutex::new(
[(
PathBuf::from("/usr/include/x86_64-linux-gnu/bits/libc-header-start.h"),
Box::new(&b"contents"[..]) as Box<dyn std::io::Read>,
)]
.into_iter()
.collect(),
),
};
assert_eq!(
do_single_preprocessor_line_call(
br#"// # 33 "/usr/include/x86_64-linux-gnu/bits/libc-header-start.h" 3 4"#,
&mut include_files,
&fs_impl,
false,
),
ControlFlow::Continue((63, 63)),
);
assert_eq!(include_files.len(), 1);
assert_eq!(
include_files
.get(Path::new(
"/usr/include/x86_64-linux-gnu/bits/libc-header-start.h",
))
.unwrap(),
// hash of `b"contents"`
"a93900c371d997927c5bc568ea538bed59ae5c960021dcfe7b0b369da5267528",
);
}