|
| 1 | +/* |
| 2 | +Copyright 2026 The Hyperlight Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +//! Test to verify that tracing features are configured correctly. |
| 18 | +//! |
| 19 | +//! This test ensures that `release_max_level_error` is NOT enabled for the |
| 20 | +//! tracing crate in hyperlight-js-runtime. Having this feature enabled would |
| 21 | +//! suppress all log levels above error in release builds, which prevents |
| 22 | +//! tracing from working correctly. |
| 23 | +//! |
| 24 | +//! See: https://github.com/hyperlight-dev/hyperlight-js/issues/126 |
| 25 | +
|
| 26 | +#![cfg(not(hyperlight))] |
| 27 | + |
| 28 | +/// Verifies that the `release_max_level_error` feature is not enabled for |
| 29 | +/// the tracing crate when building hyperlight-js-runtime. |
| 30 | +/// |
| 31 | +/// This is important because enabling `release_max_level_error` would |
| 32 | +/// cause all trace/debug/info/warn log levels to be compiled out in |
| 33 | +/// release builds, breaking the tracing functionality. |
| 34 | +#[test] |
| 35 | +fn tracing_does_not_have_release_max_level_error() { |
| 36 | + let mut cmd = std::process::Command::new(env!("CARGO")); |
| 37 | + let output = cmd |
| 38 | + .arg("tree") |
| 39 | + .arg("-p") |
| 40 | + .arg("hyperlight-js-runtime") |
| 41 | + .arg("-f") |
| 42 | + .arg("{f}") |
| 43 | + .arg("-i") |
| 44 | + .arg("tracing") |
| 45 | + .arg("--depth") |
| 46 | + .arg("0") |
| 47 | + .env("RUSTFLAGS", "--cfg=hyperlight --check-cfg=cfg(hyperlight)") |
| 48 | + .output() |
| 49 | + .expect("Failed to run cargo hyperlight tree"); |
| 50 | + |
| 51 | + assert!( |
| 52 | + output.status.success(), |
| 53 | + "cargo hyperlight tree failed: {}", |
| 54 | + String::from_utf8_lossy(&output.stderr) |
| 55 | + ); |
| 56 | + |
| 57 | + let stdout = String::from_utf8_lossy(&output.stdout); |
| 58 | + let features: Vec<&str> = stdout.trim().split(',').collect(); |
| 59 | + |
| 60 | + assert!( |
| 61 | + !features.contains(&"release_max_level_error"), |
| 62 | + "tracing crate should NOT have 'release_max_level_error' feature enabled.\n\ |
| 63 | + Enabled features: {stdout}\n\ |
| 64 | + See: https://github.com/hyperlight-dev/hyperlight-js/issues/126" |
| 65 | + ); |
| 66 | + |
| 67 | + // Also verify that the expected features ARE enabled |
| 68 | + assert!( |
| 69 | + features.contains(&"max_level_trace"), |
| 70 | + "tracing crate should have 'max_level_trace' feature enabled.\n\ |
| 71 | + Enabled features: {stdout}" |
| 72 | + ); |
| 73 | +} |
0 commit comments