mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 06:17:49 +00:00
Add filepath to code blocks in Testing post (#893)
This commit is contained in:
@@ -214,6 +214,8 @@ For specifying the exit status, we create a `QemuExitCode` enum. The idea is to
|
|||||||
We can now update our `test_runner` to exit QEMU after all tests ran:
|
We can now update our `test_runner` to exit QEMU after all tests ran:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
// in src/main.rs
|
||||||
|
|
||||||
fn test_runner(tests: &[&dyn Fn()]) {
|
fn test_runner(tests: &[&dyn Fn()]) {
|
||||||
println!("Running {} tests", tests.len());
|
println!("Running {} tests", tests.len());
|
||||||
for test in tests {
|
for test in tests {
|
||||||
@@ -246,6 +248,8 @@ The problem is that `cargo test` considers all error codes other than `0` as fai
|
|||||||
To work around this, `bootimage` provides a `test-success-exit-code` configuration key that maps a specified exit code to the exit code `0`:
|
To work around this, `bootimage` provides a `test-success-exit-code` configuration key that maps a specified exit code to the exit code `0`:
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
|
# in Cargo.toml
|
||||||
|
|
||||||
[package.metadata.bootimage]
|
[package.metadata.bootimage]
|
||||||
test-args = […]
|
test-args = […]
|
||||||
test-success-exit-code = 33 # (0x10 << 1) | 1
|
test-success-exit-code = 33 # (0x10 << 1) | 1
|
||||||
@@ -315,6 +319,8 @@ Like the `isa-debug-exit` device, the UART is programmed using port I/O. Since t
|
|||||||
To make the serial port easily usable, we add `serial_print!` and `serial_println!` macros:
|
To make the serial port easily usable, we add `serial_print!` and `serial_println!` macros:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
// in src/serial.rs
|
||||||
|
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub fn _print(args: ::core::fmt::Arguments) {
|
pub fn _print(args: ::core::fmt::Arguments) {
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
@@ -406,6 +412,8 @@ To exit QEMU with an error message on a panic, we can use [conditional compilati
|
|||||||
[conditional compilation]: https://doc.rust-lang.org/1.30.0/book/first-edition/conditional-compilation.html
|
[conditional compilation]: https://doc.rust-lang.org/1.30.0/book/first-edition/conditional-compilation.html
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
|
// in src/main.rs
|
||||||
|
|
||||||
// our existing panic handler
|
// our existing panic handler
|
||||||
#[cfg(not(test))] // new attribute
|
#[cfg(not(test))] // new attribute
|
||||||
#[panic_handler]
|
#[panic_handler]
|
||||||
@@ -786,7 +794,7 @@ We make the modules public to make them usable from outside of our library. This
|
|||||||
Now we can update our `main.rs` to use the library:
|
Now we can update our `main.rs` to use the library:
|
||||||
|
|
||||||
```rust
|
```rust
|
||||||
// src/main.rs
|
// in src/main.rs
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
|
|||||||
Reference in New Issue
Block a user