mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 22:37:49 +00:00
Allow unused imports for cargo test
This commit is contained in:
@@ -113,10 +113,10 @@ The test framework seems to work as intended. We don't have any tests yet, but w
|
|||||||
We get a few warnings about unused items, because we no longer compile our `_start` function. To silence such unused code warnings, we can add the following to the top of our `main.rs`:
|
We get a few warnings about unused items, because we no longer compile our `_start` function. To silence such unused code warnings, we can add the following to the top of our `main.rs`:
|
||||||
|
|
||||||
```
|
```
|
||||||
#![cfg_attr(test, allow(dead_code, unused_macros))]
|
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
|
||||||
```
|
```
|
||||||
|
|
||||||
Like before, the `cfg_attr` attribute sets the passed attribute if the passed condition holds. Here, we set the `allow(…)` attribute when compiling in test mode. We use the `allow` attribute to disable warnings for the `dead_code` and `unused_macro` _lints_.
|
Like before, the `cfg_attr` attribute sets the passed attribute if the passed condition holds. Here, we set the `allow(…)` attribute when compiling in test mode. We use the `allow` attribute to disable warnings for the `dead_code`, `unused_macro`, and `unused_import` _lints_.
|
||||||
|
|
||||||
Lints are classes of warnings, for example `dead_code` for unused code or `missing-docs` for missing documentation. Lints can be set to four different states:
|
Lints are classes of warnings, for example `dead_code` for unused code or `missing-docs` for missing documentation. Lints can be set to four different states:
|
||||||
|
|
||||||
|
|||||||
@@ -331,8 +331,8 @@ Cargo allows to add [additional executables] to a project by putting them inside
|
|||||||
#![feature(panic_implementation)]
|
#![feature(panic_implementation)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![cfg_attr(not(test), no_main)]
|
#![cfg_attr(not(test), no_main)]
|
||||||
|
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
|
||||||
|
|
||||||
#[cfg(not(test))]
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
@@ -404,13 +404,12 @@ pub unsafe fn exit_qemu() {
|
|||||||
#![feature(panic_implementation)] // required for defining the panic handler
|
#![feature(panic_implementation)] // required for defining the panic handler
|
||||||
#![no_std] // don't link the Rust standard library
|
#![no_std] // don't link the Rust standard library
|
||||||
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
|
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
|
||||||
#![cfg_attr(test, allow(dead_code, unused_macros))] // allow unused code in test mode
|
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
|
||||||
|
|
||||||
// NEW: Add the library as dependency (same crate name as executable)
|
// NEW: Add the library as dependency (same crate name as executable)
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
/// This function is the entry point, since the linker looks for a function
|
/// This function is the entry point, since the linker looks for a function
|
||||||
@@ -468,12 +467,12 @@ We are finally able to create our first integration test executable. We start si
|
|||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
#![no_std] // don't link the Rust standard library
|
#![no_std] // don't link the Rust standard library
|
||||||
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
|
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
|
||||||
|
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
|
||||||
|
|
||||||
// add the library as dependency (same crate name as executable)
|
// add the library as dependency (same crate name as executable)
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use blog_os::exit_qemu;
|
use blog_os::exit_qemu;
|
||||||
|
|
||||||
@@ -536,11 +535,11 @@ To test that our panic handler is really invoked on a panic, we create a `test-p
|
|||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![cfg_attr(not(test), no_main)]
|
#![cfg_attr(not(test), no_main)]
|
||||||
|
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use blog_os::exit_qemu;
|
use blog_os::exit_qemu;
|
||||||
|
|
||||||
|
|||||||
@@ -2,13 +2,13 @@
|
|||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
#![no_std] // don't link the Rust standard library
|
#![no_std] // don't link the Rust standard library
|
||||||
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
|
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
|
||||||
|
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
|
||||||
|
|
||||||
// add the library as dependency (same crate name as executable)
|
// add the library as dependency (same crate name as executable)
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
use blog_os::exit_qemu;
|
use blog_os::exit_qemu;
|
||||||
#[cfg(not(test))]
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
/// This function is the entry point, since the linker looks for a function
|
/// This function is the entry point, since the linker looks for a function
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
#![feature(const_fn)]
|
#![feature(const_fn)]
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![cfg_attr(not(test), no_main)]
|
#![cfg_attr(not(test), no_main)]
|
||||||
|
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
use blog_os::exit_qemu;
|
use blog_os::exit_qemu;
|
||||||
#[cfg(not(test))]
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
#[cfg(not(test))]
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
#![feature(panic_implementation)] // required for defining the panic handler
|
#![feature(panic_implementation)] // required for defining the panic handler
|
||||||
#![no_std] // don't link the Rust standard library
|
#![no_std] // don't link the Rust standard library
|
||||||
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
|
#![cfg_attr(not(test), no_main)] // disable all Rust-level entry points
|
||||||
#![cfg_attr(test, allow(dead_code, unused_macros))] // allow unused code in test mode
|
#![cfg_attr(test, allow(dead_code, unused_macros, unused_imports))]
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate blog_os;
|
extern crate blog_os;
|
||||||
|
|
||||||
#[cfg(not(test))]
|
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
|
|
||||||
/// This function is the entry point, since the linker looks for a function
|
/// This function is the entry point, since the linker looks for a function
|
||||||
|
|||||||
Reference in New Issue
Block a user