Skip to content

Commit 32db0c6

Browse files
authored
Merge pull request #748 from dvermd/fmt_tests_run
Fmt tests run
2 parents f0ab82f + dde77db commit 32db0c6

File tree

6 files changed

+47
-23
lines changed

6 files changed

+47
-23
lines changed

build_system/src/fmt.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::ffi::OsStr;
22
use std::path::Path;
33

4-
use crate::utils::run_command_with_output;
4+
use crate::utils::{run_command_with_output, walk_dir};
55

66
fn show_usage() {
77
println!(
@@ -32,5 +32,31 @@ pub fn run() -> Result<(), String> {
3232
if check { &[&"cargo", &"fmt", &"--check"] } else { &[&"cargo", &"fmt"] };
3333

3434
run_command_with_output(cmd, Some(Path::new(".")))?;
35-
run_command_with_output(cmd, Some(Path::new("build_system")))
35+
run_command_with_output(cmd, Some(Path::new("build_system")))?;
36+
37+
run_rustfmt_recursively("tests/run", check)
38+
}
39+
40+
fn run_rustfmt_recursively<P>(dir: P, check: bool) -> Result<(), String>
41+
where
42+
P: AsRef<Path>,
43+
{
44+
walk_dir(
45+
dir,
46+
&mut |dir| run_rustfmt_recursively(dir, check),
47+
&mut |file_path| {
48+
if file_path.extension().filter(|ext| ext == &OsStr::new("rs")).is_some() {
49+
let rustfmt_cmd: &[&dyn AsRef<OsStr>] = if check {
50+
&[&"rustfmt", &"--check", &file_path]
51+
} else {
52+
&[&"rustfmt", &file_path]
53+
};
54+
55+
run_command_with_output(rustfmt_cmd, Some(Path::new(".")))
56+
} else {
57+
Ok(())
58+
}
59+
},
60+
true,
61+
)
3662
}

tests/run/int.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ fn main() {
77
use std::hint::black_box;
88

99
macro_rules! check {
10-
($ty:ty, $expr:expr) => {
11-
{
12-
const EXPECTED: $ty = $expr;
13-
assert_eq!($expr, EXPECTED);
14-
}
15-
};
10+
($ty:ty, $expr:expr) => {{
11+
const EXPECTED: $ty = $expr;
12+
assert_eq!($expr, EXPECTED);
13+
}};
1614
}
1715

1816
check!(u32, (2220326408_u32 + black_box(1)) >> (32 - 6));

tests/run/int_overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn main() {
1212

1313
let arg_count = std::env::args().count();
1414
let int = isize::MAX;
15-
let _int = int + arg_count as isize; // overflow
15+
let _int = int + arg_count as isize; // overflow
1616

1717
// If overflow checking is disabled, we should reach here.
1818
#[cfg(not(debug_assertions))]

tests/run/structs.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,8 @@ fn one() -> isize {
2727

2828
#[no_mangle]
2929
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
30-
let test = Test {
31-
field: one(),
32-
};
33-
let two = Two {
34-
two: 2,
35-
};
30+
let test = Test { field: one() };
31+
let two = Two { two: 2 };
3632
unsafe {
3733
libc::printf(b"%ld\n\0" as *const u8 as *const i8, test.field);
3834
libc::printf(b"%ld\n\0" as *const u8 as *const i8, two.two);

tests/run/volatile.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,11 @@ struct Struct {
1212
func: unsafe fn(*const ()),
1313
}
1414

15-
fn func(_ptr: *const ()) {
16-
}
15+
fn func(_ptr: *const ()) {}
1716

1817
fn main() {
1918
let mut x = MaybeUninit::<&Struct>::uninit();
20-
x.write(&Struct {
21-
pointer: std::ptr::null(),
22-
func,
23-
});
19+
x.write(&Struct { pointer: std::ptr::null(), func });
2420
let x = unsafe { x.assume_init() };
2521
let value = unsafe { (x as *const Struct).read_volatile() };
2622
println!("{:?}", value);

tests/run/volatile2.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,14 @@ mod libc {
77
#[link(name = "c")]
88
extern "C" {
99
pub fn sigaction(signum: i32, act: *const sigaction, oldact: *mut sigaction) -> i32;
10-
pub fn mmap(addr: *mut (), len: usize, prot: i32, flags: i32, fd: i32, offset: i64) -> *mut ();
10+
pub fn mmap(
11+
addr: *mut (),
12+
len: usize,
13+
prot: i32,
14+
flags: i32,
15+
fd: i32,
16+
offset: i64,
17+
) -> *mut ();
1118
pub fn mprotect(addr: *mut (), len: usize, prot: i32) -> i32;
1219
}
1320

@@ -54,7 +61,8 @@ fn main() {
5461
libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
5562
-1,
5663
0,
57-
).cast();
64+
)
65+
.cast();
5866
if STORAGE == libc::MAP_FAILED {
5967
panic!("error: mmap failed");
6068
}

0 commit comments

Comments
 (0)