Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
llvm-version: 22

- name: Setup Python
run: pip install ruff
run: pip install ruff==0.15.22

- name: Configure
run: cmake -GNinja -B build -S .
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ On Ubuntu, install the required dependencies with:

```bash
sudo apt install libclang-22-dev clang++-22 ninja-build cmake
curl -LsSf https://astral.sh/ruff/install.sh | sh
pip install ruff==0.15.22
```


Expand Down
8 changes: 6 additions & 2 deletions tests/lit/lit/formats/Cpp2RustTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,18 @@ def build_rust(self):
def run_cpp(self):
if self.skip_run:
return None
self.cpp_result = RunResult(*lit.util.executeCommand(str(self.cpp_bin)))
self.cpp_result = RunResult(
*lit.util.executeCommand(str(self.cpp_bin), str(self.tmp_dir))
)
return None

def run_rust(self):
exp = self.expectations
if self.skip_run:
return None
self.rust_result = RunResult(*lit.util.executeCommand(str(self.rust_bin)))
self.rust_result = RunResult(
*lit.util.executeCommand(str(self.rust_bin), str(self.tmp_dir))
)

if exp.should_panic_ub:
err = str(self.rust_result.stderr)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/fd_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <unistd.h>

int main(void) {
const char *path = "/tmp/cpp2rust_fd_io_test.tmp";
const char *path = "cpp2rust_fd_io_test.tmp";
int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, 0644);
assert(fd >= 0);
assert(write(fd, "hello world", 11) == 11);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/fstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <unistd.h>

int main(void) {
const char *path = "/tmp/cpp2rust_fstat_test.tmp";
const char *path = "cpp2rust_fstat_test.tmp";
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
assert(fd >= 0);
assert(write(fd, "hello", 5) == 5);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/isatty.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <unistd.h>

int main(void) {
const char *path = "/tmp/cpp2rust_isatty_test.tmp";
const char *path = "cpp2rust_isatty_test.tmp";
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
assert(fd >= 0);
assert(isatty(fd) == 0);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/lseek_ftruncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <unistd.h>

int main(void) {
const char *path = "/tmp/cpp2rust_lseek_ftruncate_test.tmp";
const char *path = "cpp2rust_lseek_ftruncate_test.tmp";
int fd = open(path, O_RDWR | O_CREAT | O_TRUNC, 0644);
assert(fd >= 0);
assert(write(fd, "hello world", 11) == 11);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/fd_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn main() {
}
fn main_0() -> i32 {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_fd_io_test.tmp",
b"cpp2rust_fd_io_test.tmp",
)));
let fd: Value<i32> = Rc::new(RefCell::new({
let __mode = match &[(420).into()].first() {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/fstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn main() {
}
fn main_0() -> i32 {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_fstat_test.tmp",
b"cpp2rust_fstat_test.tmp",
)));
let fd: Value<i32> = Rc::new(RefCell::new({
let __mode = match &[(420).into()].first() {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/isatty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn main() {
}
fn main_0() -> i32 {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_isatty_test.tmp",
b"cpp2rust_isatty_test.tmp",
)));
let fd: Value<i32> = Rc::new(RefCell::new({
let __mode = match &[(420).into()].first() {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/lseek_ftruncate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn main() {
}
fn main_0() -> i32 {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_lseek_ftruncate_test.tmp",
b"cpp2rust_lseek_ftruncate_test.tmp",
)));
let fd: Value<i32> = Rc::new(RefCell::new({
let __mode = match &[(420).into()].first() {
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/out/refcount/stdio_nofd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::os::fd::AsFd;
use std::rc::{Rc, Weak};
pub fn test_fputc_fputs_0() {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_stdio_nofd_puts.tmp",
b"cpp2rust_stdio_nofd_puts.tmp",
)));
let fp: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
match Ptr::from_string_literal(b"wb").to_rust_string() {
Expand Down Expand Up @@ -154,7 +154,7 @@ pub fn test_puts_1() {
}
pub fn test_fgets_getc_2() {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_stdio_nofd_gets.tmp",
b"cpp2rust_stdio_nofd_gets.tmp",
)));
let fp: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
match Ptr::from_string_literal(b"wb").to_rust_string() {
Expand Down Expand Up @@ -464,7 +464,7 @@ pub fn test_fgets_getc_2() {
}
pub fn test_freopen_3() {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_stdio_nofd_reopen.tmp",
b"cpp2rust_stdio_nofd_reopen.tmp",
)));
let fp: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
match Ptr::from_string_literal(b"wb").to_rust_string() {
Expand Down Expand Up @@ -571,7 +571,7 @@ pub fn test_freopen_3() {
}
pub fn test_fseeko_4() {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_stdio_nofd_seek.tmp",
b"cpp2rust_stdio_nofd_seek.tmp",
)));
let fp: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
match Ptr::from_string_literal(b"wb").to_rust_string() {
Expand Down Expand Up @@ -758,10 +758,10 @@ pub fn test_fseeko_4() {
}
pub fn test_rename_5() {
let from: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_stdio_nofd_from.tmp",
b"cpp2rust_stdio_nofd_from.tmp",
)));
let to: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_stdio_nofd_to.tmp",
b"cpp2rust_stdio_nofd_to.tmp",
)));
let fp: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
match Ptr::from_string_literal(b"wb").to_rust_string() {
Expand Down Expand Up @@ -884,7 +884,7 @@ pub fn test_rename_5() {
}
pub fn test_setvbuf_6() {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_stdio_nofd_vbuf.tmp",
b"cpp2rust_stdio_nofd_vbuf.tmp",
)));
let fp: Value<Ptr<::std::fs::File>> = Rc::new(RefCell::new(
match Ptr::from_string_literal(b"wb").to_rust_string() {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/refcount/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn main() {
}
fn main_0() -> i32 {
let path: Value<Ptr<u8>> = Rc::new(RefCell::new(Ptr::from_string_literal(
b"/tmp/cpp2rust_termios_test.tmp",
b"cpp2rust_termios_test.tmp",
)));
let fd: Value<i32> = Rc::new(RefCell::new({
let __mode = match &[(420).into()].first() {
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/unsafe/fd_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn main() {
}
unsafe fn main_0() -> i32 {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_fd_io_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_fd_io_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fd: i32 = (unsafe {
libc::open(
path as *const i8,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/unsafe/fstat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn main() {
}
unsafe fn main_0() -> i32 {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_fstat_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_fstat_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fd: i32 = (unsafe {
libc::open(
path as *const i8,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/unsafe/isatty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn main() {
}
unsafe fn main_0() -> i32 {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_isatty_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_isatty_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fd: i32 = (unsafe {
libc::open(
path as *const i8,
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/out/unsafe/lseek_ftruncate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ pub fn main() {
}
}
unsafe fn main_0() -> i32 {
let mut path: *const libc::c_char = (c"/tmp/cpp2rust_lseek_ftruncate_test.tmp"
.as_ptr()
.cast_mut())
.cast_const();
let mut path: *const libc::c_char =
(c"cpp2rust_lseek_ftruncate_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fd: i32 = (unsafe {
libc::open(
path as *const i8,
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/unsafe/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub unsafe fn test_fileno_3() {
assert!(((((libc::fileno(libcc2rs::stdout_unsafe())) == (1)) as i32) != 0));
assert!(((((libc::fileno(libcc2rs::stderr_unsafe())) == (2)) as i32) != 0));
let mut file: *const libc::c_char =
(c"/tmp/cpp2rust_fileno_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_fileno_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(file, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
assert!(((((libc::fileno(fp)) > (2)) as i32) != 0));
Expand Down
14 changes: 7 additions & 7 deletions tests/unit/out/unsafe/stdio_nofd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
pub unsafe fn test_fputc_fputs_0() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_stdio_nofd_puts.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_stdio_nofd_puts.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
assert!(((((libc::fputc(('A' as i32), fp)) == ('A' as i32)) as i32) != 0));
Expand Down Expand Up @@ -78,7 +78,7 @@ pub unsafe fn test_puts_1() {
}
pub unsafe fn test_fgets_getc_2() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_stdio_nofd_gets.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_stdio_nofd_gets.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
assert!(
Expand Down Expand Up @@ -166,7 +166,7 @@ pub unsafe fn test_fgets_getc_2() {
}
pub unsafe fn test_freopen_3() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_stdio_nofd_reopen.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_stdio_nofd_reopen.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
assert!(
Expand Down Expand Up @@ -221,7 +221,7 @@ pub unsafe fn test_freopen_3() {
}
pub unsafe fn test_fseeko_4() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_stdio_nofd_seek.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_stdio_nofd_seek.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
assert!(
Expand Down Expand Up @@ -282,9 +282,9 @@ pub unsafe fn test_fseeko_4() {
}
pub unsafe fn test_rename_5() {
let mut from: *const libc::c_char =
(c"/tmp/cpp2rust_stdio_nofd_from.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_stdio_nofd_from.tmp".as_ptr().cast_mut()).cast_const();
let mut to: *const libc::c_char =
(c"/tmp/cpp2rust_stdio_nofd_to.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_stdio_nofd_to.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(from, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
assert!(((((libc::fputs((c"data".as_ptr().cast_mut()).cast_const(), fp)) >= (0)) as i32) != 0));
Expand All @@ -301,7 +301,7 @@ pub unsafe fn test_rename_5() {
}
pub unsafe fn test_setvbuf_6() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_stdio_nofd_vbuf.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_stdio_nofd_vbuf.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
assert!(((((libc::setvbuf(fp, std::ptr::null_mut(), 2, 0_usize)) == (0)) as i32) != 0));
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/out/unsafe/sys_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd};
use std::rc::Rc;
pub unsafe fn test_stat_0() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_stat_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_stat_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
libc::fputs((c"hello".as_ptr().cast_mut()).cast_const(), fp);
Expand All @@ -21,7 +21,7 @@ pub unsafe fn test_stat_0() {
}
pub unsafe fn test_fstat_1() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_fstat_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_fstat_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
libc::fputs((c"hello world".as_ptr().cast_mut()).cast_const(), fp);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/out/unsafe/termios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub fn main() {
}
unsafe fn main_0() -> i32 {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_termios_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_termios_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fd: i32 = (unsafe {
libc::open(
path as *const i8,
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/out/unsafe/unistd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub unsafe fn test_close_0() {
}
pub unsafe fn test_lseek_1() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_lseek_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_lseek_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
libc::fputs((c"hello world".as_ptr().cast_mut()).cast_const(), fp);
Expand Down Expand Up @@ -78,7 +78,7 @@ pub unsafe fn test_lseek_1() {
}
pub unsafe fn test_read_2() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_read_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_read_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
libc::fputs((c"hello world".as_ptr().cast_mut()).cast_const(), fp);
Expand Down Expand Up @@ -139,7 +139,7 @@ pub unsafe fn test_read_2() {
}
pub unsafe fn test_unlink_3() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_unlink_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_unlink_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
assert!(((((libc::fclose(fp)) == (0)) as i32) != 0));
Expand Down Expand Up @@ -210,7 +210,7 @@ pub unsafe fn test_pipe_4() {
}
pub unsafe fn test_ftruncate_5() {
let mut path: *const libc::c_char =
(c"/tmp/cpp2rust_ftruncate_test.tmp".as_ptr().cast_mut()).cast_const();
(c"cpp2rust_ftruncate_test.tmp".as_ptr().cast_mut()).cast_const();
let mut fp: *mut ::libc::FILE = libc::fopen(path, (c"wb".as_ptr().cast_mut()).cast_const());
assert!((((!((fp).is_null())) as i32) != 0));
libc::fputs((c"hello world".as_ptr().cast_mut()).cast_const(), fp);
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static void test_fileno(void) {
assert(fileno(stdin) == 0);
assert(fileno(stdout) == 1);
assert(fileno(stderr) == 2);
const char *file = "/tmp/cpp2rust_fileno_test.tmp";
const char *file = "cpp2rust_fileno_test.tmp";
FILE *fp = fopen(file, "wb");
assert(fp != NULL);
assert(fileno(fp) > 2);
Expand Down
Loading
Loading