in the section Testing in Rust, the post talks about the following code, but does not make it clear that the first 2 lines (or entire code snippet) need to be placed before mod vga_buffer;
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#[cfg(test)]
pub fn test_runner(tests: &[&dyn Fn()]) {
println!("Running {} tests", tests.len());
for test in tests {
test();
}
}
a person following this guide might place it anywhere in the file but making it clear that the following 2 options are of the few valid placements
- Placing it all at the start resulting in this as the first lines of code
#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
#[cfg(test)]
pub fn test_runner(tests: &[&dyn Fn()]) {
println!("Running {} tests", tests.len());
for test in tests {
test();
}
}
mod vga_buffer;
...
- or placing the 2 attributes near the top of the file at the latest following the no_std and no_main attributes like this while placing the function elsewhere like this
#![no_std]
#![no_main]
#![feature(custom_test_frameworks)]
#![test_runner(crate::test_runner)]
mod vga_buffer;
...
#[cfg(test)]
pub fn test_runner(tests: &[&dyn Fn()]) {
println!("Running {} tests", tests.len());
for test in tests {
test();
}
}
in the section Testing in Rust, the post talks about the following code, but does not make it clear that the first 2 lines (or entire code snippet) need to be placed before
mod vga_buffer;a person following this guide might place it anywhere in the file but making it clear that the following 2 options are of the few valid placements