Skip to content

Commit

Permalink
Allow cargo test to complete under any set of features.
Browse files Browse the repository at this point in the history
Previously, tests, examples, and benches would fail to compile under
`cargo test --no-default-features`. Now they are all skipped if they
would not compile.

This does not affect behavior *with* default features — test coverage
is not reduced.
  • Loading branch information
kpreid committed Sep 16, 2023
1 parent 2ee1a00 commit 04451fb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ rust-version = "1.48.0"
[[bench]]
name = "benchmarks"
harness = false
required-features = ["std"]

[[example]]
name = "base64"
required-features = ["std"]

[[test]]
name = "tests"
required-features = ["alloc"]

[[test]]
name = "encode"
required-features = ["alloc"]

[package.metadata.docs.rs]
rustdoc-args = ["--generate-link-to-definition"]
Expand Down
3 changes: 2 additions & 1 deletion src/engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ pub trait Engine: Send + Sync {
///
/// # Example
///
/// ```rust
#[cfg_attr(feature = "alloc", doc = "```")]
#[cfg_attr(not(feature = "alloc"), doc = "```ignore")]
/// use base64::{Engine as _, engine::general_purpose};
/// let s = b"hello internet!";
/// let mut buf = Vec::new();
Expand Down
6 changes: 4 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
//!
//! ## Using predefined engines
//!
//! ```
#![cfg_attr(feature = "alloc", doc = "```")]
#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
//! use base64::{Engine as _, engine::general_purpose};
//!
//! let orig = b"data";
Expand All @@ -95,7 +96,8 @@
//!
//! ## Custom alphabet, config, and engine
//!
//! ```
#![cfg_attr(feature = "alloc", doc = "```")]
#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
//! use base64::{engine, alphabet, Engine as _};
//!
//! // bizarro-world base64: +/ as the first symbols instead of the last
Expand Down
3 changes: 2 additions & 1 deletion src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
//!
//! # Examples
//!
//! ```
#![cfg_attr(feature = "alloc", doc = "```")]
#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
//! use base64::prelude::{Engine as _, BASE64_STANDARD_NO_PAD};
//!
//! assert_eq!("c29tZSBieXRlcw", &BASE64_STANDARD_NO_PAD.encode(b"some bytes"));
Expand Down

0 comments on commit 04451fb

Please sign in to comment.