Skip to content

Commit adb688f

Browse files
committed
transpile: Add snapshot test for main function
1 parent 4f00c7f commit adb688f

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
int main(int argc, char **argv, char **envp) {
2+
return 0;
3+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
source: c2rust-transpile/tests/snapshots.rs
3+
expression: cat tests/snapshots/main.rs
4+
input_file: c2rust-transpile/tests/snapshots/main.c
5+
---
6+
#![allow(
7+
dead_code,
8+
non_camel_case_types,
9+
non_snake_case,
10+
non_upper_case_globals,
11+
unused_assignments,
12+
unused_mut
13+
)]
14+
unsafe fn main_0(
15+
mut argc: ::core::ffi::c_int,
16+
mut argv: *mut *mut ::core::ffi::c_char,
17+
mut envp: *mut *mut ::core::ffi::c_char,
18+
) -> ::core::ffi::c_int {
19+
return 0 as ::core::ffi::c_int;
20+
}
21+
pub fn main() {
22+
let mut args: Vec<*mut ::core::ffi::c_char> = Vec::new();
23+
for arg in ::std::env::args() {
24+
args.push(
25+
::std::ffi::CString::new(arg)
26+
.expect("Failed to convert argument into CString.")
27+
.into_raw(),
28+
);
29+
}
30+
args.push(::core::ptr::null_mut());
31+
let mut vars: Vec<*mut ::core::ffi::c_char> = Vec::new();
32+
for (var_name, var_value) in ::std::env::vars() {
33+
let var: String = format!("{}={}", var_name, var_value);
34+
vars.push(
35+
::std::ffi::CString::new(var)
36+
.expect("Failed to convert environment variable into CString.")
37+
.into_raw(),
38+
);
39+
}
40+
vars.push(::core::ptr::null_mut());
41+
unsafe {
42+
::std::process::exit(
43+
main_0(
44+
(args.len() - 1) as ::core::ffi::c_int,
45+
args.as_mut_ptr() as *mut *mut ::core::ffi::c_char,
46+
vars.as_mut_ptr() as *mut *mut ::core::ffi::c_char,
47+
) as i32,
48+
)
49+
}
50+
}

0 commit comments

Comments
 (0)