Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
cargo build --profile=${{ matrix.profile }}
cargo build --all-features --profile=${{ matrix.profile }}
cargo test --profile=${{ matrix.profile }}
cargo test --no-default-features --features trace no_std_required --profile=${{ matrix.profile }}
build-minimum:
name: Build using minimum versions of dependencies
runs-on: ubuntu-latest
Expand Down
12 changes: 9 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,21 @@ tracing infrastructure before running tests.
"""
include = ["src/lib.rs", "LICENSE-*", "README.md", "CHANGELOG.md"]

[[test]]
name = "no_std_test"
path = "tests/no_std_required.rs"
required-features = ["trace"]

[[test]]
name = "default_log_filter"
path = "tests/default_log_filter.rs"
required-features = ["log", "unstable"]

[features]
default = ["log", "color"]
default = ["log", "color", "std"]
std = ["test-log-macros/std"]
trace = ["dep:tracing-subscriber", "test-log-macros/trace"]
log = ["dep:env_logger", "test-log-macros/log", "tracing-subscriber?/tracing-log"]
log = ["dep:env_logger", "test-log-macros/log", "tracing-subscriber?/tracing-log", "std"]
color = ["env_logger?/auto-color", "tracing-subscriber?/ansi"]
# Enable unstable features. These are generally exempt from any semantic
# versioning guarantees.
Expand All @@ -45,7 +51,7 @@ unstable = ["test-log-macros/unstable"]
members = ["macros"]

[dependencies]
test-log-macros = {version = "0.2.15", path = "macros"}
test-log-macros = {version = "0.2.15", default-features = false, path = "macros"}
tracing-subscriber = {version = "0.3.17", default-features = false, optional = true, features = ["env-filter", "fmt"]}
env_logger = {version = "0.11", default-features = false, optional = true}

Expand Down
2 changes: 2 additions & 0 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Supporting procedural macro crate for test-log.
proc-macro = true

[features]
default = ["std"]
std = []
trace = []
log = []
unstable = []
Expand Down
20 changes: 17 additions & 3 deletions macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
// Copyright (C) 2019-2023 Daniel Mueller <deso@posteo.net>
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;
extern crate proc_macro;

use alloc::string::String;
use alloc::vec;
use alloc::vec::Vec;

use proc_macro::TokenStream;
use proc_macro2::TokenStream as Tokens;

Expand Down Expand Up @@ -199,10 +206,17 @@ fn expand_tracing_init(attribute_args: &AttributeArgs) -> Tokens {
let __internal_event_filter = {
use ::test_log::tracing_subscriber::fmt::format::FmtSpan;

match ::std::env::var_os("RUST_LOG_SPAN_EVENTS") {
#[cfg(feature = "std")]
let env_var = match ::std::env::var("RUST_LOG_SPAN_EVENTS") {
Ok(val) => Some(val),
Err(::std::env::VarError::NotPresent) => None,
Err(::std::env::VarError::NotUnicode(os_string)) => panic!("RUST_LOG_SPAN_EVENTS must be unicode compliant, found {os_string:?}"),
};
#[cfg(not(feature = "std"))]
let env_var = ::core::option_env!("RUST_LOG_SPAN_EVENTS");

match env_var {
Some(mut value) => {
value.make_ascii_lowercase();
let value = value.to_str().expect("test-log: RUST_LOG_SPAN_EVENTS must be valid UTF-8");
value
.split(",")
.map(|filter| match filter.trim() {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: (Apache-2.0 OR MIT)

#![deny(missing_docs)]
#![cfg_attr(not(feature = "std"), no_std)]

//! A crate providing a replacement #[[macro@test]] attribute that
//! initializes logging and/or tracing infrastructure before running
Expand Down
10 changes: 10 additions & 0 deletions tests/no_std_required.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![no_std]

use test_log::test;
use tracing::debug;

#[test]
fn no_std_required() {
debug!("It works without std!");
assert_eq!(1 + 1, 2);
}