]>
git.proxmox.com Git - rustc.git/blob - vendor/sysinfo/tests/code_checkers/utils.rs
1 // Take a look at the license at the top of the repository in the LICENSE file.
3 use std
::fs
::{self, File}
;
7 pub struct TestResult
{
12 impl std
::ops
::AddAssign
for TestResult
{
13 fn add_assign(&mut self, other
: Self) {
14 self.nb_tests
+= other
.nb_tests
;
15 self.nb_errors
+= other
.nb_errors
;
19 pub fn read_dirs
<P
: AsRef
<Path
>, F
: FnMut(&Path
, &str)>(dirs
: &[P
], callback
: &mut F
) {
21 read_dir(dir
, callback
);
25 fn read_dir
<P
: AsRef
<Path
>, F
: FnMut(&Path
, &str)>(dir
: P
, callback
: &mut F
) {
26 for entry
in fs
::read_dir(dir
).expect("read_dir failed") {
27 let entry
= entry
.expect("entry failed");
28 let path
= entry
.path();
30 read_dir(path
, callback
);
32 let content
= read_file(&path
);
33 callback(&path
, &content
);
38 fn read_file
<P
: AsRef
<Path
>>(p
: P
) -> String
{
39 let mut f
= File
::open(p
).expect("read_file::open failed");
41 String
::with_capacity(f
.metadata().map(|m
| m
.len() as usize + 1).unwrap_or(0));
42 f
.read_to_string(&mut content
)
43 .expect("read_file::read_to_end failed");
47 pub fn show_error(p
: &Path
, err
: &str) {
48 eprintln
!("=> [{}]: {}", p
.display(), err
);