Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

post-04 - Conditional compilation does not seem to work #1229

Open
AlexandreMarcq opened this issue Jun 23, 2023 · 2 comments
Open

post-04 - Conditional compilation does not seem to work #1229

AlexandreMarcq opened this issue Jun 23, 2023 · 2 comments

Comments

@AlexandreMarcq
Copy link
Contributor

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());
}

And here is the output :
image

Is there something I'm missing ?

@phil-opp
Copy link
Owner

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:

  • cargo test --bin blog_os
    image
  • No output for cargo run

@AlexandreMarcq
Copy link
Contributor Author

I've uploaded my code in my repo.
I tried with the post-04 branch. I got the expected output with cargo run but cargo test seems to hang :
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants