Skip to content

Commit

Permalink
Add test for extern "C" main function
Browse files Browse the repository at this point in the history
  • Loading branch information
fornwall committed Apr 14, 2023
1 parent 7b92948 commit 907f62f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/data/extern-c-main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! libc = { version = "0.2", default-features = false }
//!
//! [profile.release]
//! strip = true
//! lto = true
//! opt-level = "s" # "z"
//! codegen-units = 1
//! panic = "abort"
//! ```
#![no_std]
#![no_main]

#[panic_handler]
fn my_panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}

#[no_mangle]
pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
unsafe {
libc::printf("--output--\n\0".as_ptr() as *const _);
libc::printf("hello, world\n\0".as_ptr() as *const _);
}
0
}
9 changes: 9 additions & 0 deletions tests/tests/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,12 @@ fn test_same_flags() {
)
.unwrap()
}

#[test]
fn test_extern_c_main() {
let out = rust_script!("tests/data/extern-c-main.rs").unwrap();
scan!(out.stdout_output();
("hello, world") => ()
)
.unwrap()
}

0 comments on commit 907f62f

Please sign in to comment.