Skip to content

Commit ca465f8

Browse files
tests: Make format args in macros more strict
No need to accept any expr, it should always be a literal.
1 parent ac386fc commit ca465f8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tests/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ unsafe extern "C" fn rust_fmt(str: *const c_char, mut args: ...) -> Box<(c_int,
2929
}
3030

3131
macro_rules! c_fmt {
32-
($format:expr $(, $p:expr)*) => {{
32+
($format:literal $(, $p:expr)*) => {{
3333
let mut ptr = null_mut();
34-
let bytes_written = asprintf(&mut ptr, $format $(, $p)*);
34+
let bytes_written = asprintf(&mut ptr, $format.as_ptr() $(, $p)*);
3535
assert!(bytes_written >= 0);
3636
let s: String = CStr::from_ptr(ptr).to_string_lossy().into();
3737
free(ptr.cast());
@@ -40,9 +40,9 @@ macro_rules! c_fmt {
4040
}
4141

4242
macro_rules! assert_eq_fmt {
43-
($format:expr $(, $p:expr)*) => {
43+
($format:literal $(, $p:expr)*) => {
4444
assert_eq!(
45-
c_fmt!($format.as_ptr().cast() $(, $p)*),
45+
c_fmt!($format $(, $p)*),
4646
*rust_fmt($format.as_ptr().cast(), $($p),*)
4747
);
4848
};

0 commit comments

Comments
 (0)