Skip to content

Fmt tests run #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions build_system/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::ffi::OsStr;
use std::path::Path;

use crate::utils::run_command_with_output;
use crate::utils::{run_command_with_output, walk_dir};

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

run_command_with_output(cmd, Some(Path::new(".")))?;
run_command_with_output(cmd, Some(Path::new("build_system")))
run_command_with_output(cmd, Some(Path::new("build_system")))?;

run_rustfmt_recursively("tests/run", check)
}

fn run_rustfmt_recursively<P>(dir: P, check: bool) -> Result<(), String>
where
P: AsRef<Path>,
{
walk_dir(
dir,
&mut |dir| run_rustfmt_recursively(dir, check),
&mut |file_path| {
if file_path.extension().filter(|ext| ext == &OsStr::new("rs")).is_some() {
let rustfmt_cmd: &[&dyn AsRef<OsStr>] = if check {
&[&"rustfmt", &"--check", &file_path]
} else {
&[&"rustfmt", &file_path]
};

run_command_with_output(rustfmt_cmd, Some(Path::new(".")))
} else {
Ok(())
}
},
true,
)
}
10 changes: 4 additions & 6 deletions tests/run/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@ fn main() {
use std::hint::black_box;

macro_rules! check {
($ty:ty, $expr:expr) => {
{
const EXPECTED: $ty = $expr;
assert_eq!($expr, EXPECTED);
}
};
($ty:ty, $expr:expr) => {{
const EXPECTED: $ty = $expr;
assert_eq!($expr, EXPECTED);
}};
}

check!(u32, (2220326408_u32 + black_box(1)) >> (32 - 6));
Expand Down
2 changes: 1 addition & 1 deletion tests/run/int_overflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn main() {

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

// If overflow checking is disabled, we should reach here.
#[cfg(not(debug_assertions))]
Expand Down
8 changes: 2 additions & 6 deletions tests/run/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ fn one() -> isize {

#[no_mangle]
extern "C" fn main(argc: i32, _argv: *const *const u8) -> i32 {
let test = Test {
field: one(),
};
let two = Two {
two: 2,
};
let test = Test { field: one() };
let two = Two { two: 2 };
unsafe {
libc::printf(b"%ld\n\0" as *const u8 as *const i8, test.field);
libc::printf(b"%ld\n\0" as *const u8 as *const i8, two.two);
Expand Down
8 changes: 2 additions & 6 deletions tests/run/volatile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@ struct Struct {
func: unsafe fn(*const ()),
}

fn func(_ptr: *const ()) {
}
fn func(_ptr: *const ()) {}

fn main() {
let mut x = MaybeUninit::<&Struct>::uninit();
x.write(&Struct {
pointer: std::ptr::null(),
func,
});
x.write(&Struct { pointer: std::ptr::null(), func });
let x = unsafe { x.assume_init() };
let value = unsafe { (x as *const Struct).read_volatile() };
println!("{:?}", value);
Expand Down
12 changes: 10 additions & 2 deletions tests/run/volatile2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@ mod libc {
#[link(name = "c")]
extern "C" {
pub fn sigaction(signum: i32, act: *const sigaction, oldact: *mut sigaction) -> i32;
pub fn mmap(addr: *mut (), len: usize, prot: i32, flags: i32, fd: i32, offset: i64) -> *mut ();
pub fn mmap(
addr: *mut (),
len: usize,
prot: i32,
flags: i32,
fd: i32,
offset: i64,
) -> *mut ();
pub fn mprotect(addr: *mut (), len: usize, prot: i32) -> i32;
}

Expand Down Expand Up @@ -54,7 +61,8 @@ fn main() {
libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
-1,
0,
).cast();
)
.cast();
if STORAGE == libc::MAP_FAILED {
panic!("error: mmap failed");
}
Expand Down