post-04 - Conditional compilation does not seem to work
AlexandreMarcq opened this issue · comments
Alexandre commented
Hello,
I'm following along the Testing part of the blog.
Unfortunately, cargo run
and cargo test
yield the same result in QEMU.
I have added a #[cfg(test)]
before a println!
and it does not appear on the screen.
Here is the code I have :
#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#![reexport_test_harness_main = "test_main"]
use core::panic::PanicInfo;
mod vga_buffer;
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
println!("{}", info);
loop {}
}
#[no_mangle]
pub extern "C" fn _start() -> ! {
#[cfg(test)]
println!("Hello world{}", "!");
#[cfg(test)]
test_main();
loop {}
}
#[cfg(test)]
fn test_runner(tests: &[&dyn Fn()]) {
println!("Running {} tests", tests.len());
}
Is there something I'm missing ?
Philipp Oppermann commented
I don't see any issues with your code. Do you have your full code online somewhere so that I can take a look?
Could you try cloning the post-04
branch of this repo? When I put the code you posted above into the src/main.rs
I get different output for cargo test --bin blog_os
and cargo run
: