Skip to content

Commit 907f62f

Browse files
committed
Add test for extern "C" main function
1 parent 7b92948 commit 907f62f

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/data/extern-c-main.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env rust-script
2+
//! ```cargo
3+
//! [dependencies]
4+
//! libc = { version = "0.2", default-features = false }
5+
//!
6+
//! [profile.release]
7+
//! strip = true
8+
//! lto = true
9+
//! opt-level = "s" # "z"
10+
//! codegen-units = 1
11+
//! panic = "abort"
12+
//! ```
13+
14+
#![no_std]
15+
#![no_main]
16+
17+
#[panic_handler]
18+
fn my_panic(_info: &core::panic::PanicInfo) -> ! {
19+
loop {}
20+
}
21+
22+
#[no_mangle]
23+
pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
24+
unsafe {
25+
libc::printf("--output--\n\0".as_ptr() as *const _);
26+
libc::printf("hello, world\n\0".as_ptr() as *const _);
27+
}
28+
0
29+
}

tests/tests/script.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,3 +260,12 @@ fn test_same_flags() {
260260
)
261261
.unwrap()
262262
}
263+
264+
#[test]
265+
fn test_extern_c_main() {
266+
let out = rust_script!("tests/data/extern-c-main.rs").unwrap();
267+
scan!(out.stdout_output();
268+
("hello, world") => ()
269+
)
270+
.unwrap()
271+
}

0 commit comments

Comments
 (0)