From 22b871bc0e053f77009a5e737ad594c32e5f7f57 Mon Sep 17 00:00:00 2001 From: Tei Roberts Date: Tue, 10 Oct 2023 23:38:54 +0200 Subject: [PATCH 1/4] fix: color-spantrace test due to misinterpreted relative paths --- color-spantrace/tests/themes.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/color-spantrace/tests/themes.rs b/color-spantrace/tests/themes.rs index 379aa25..c1fdcfb 100644 --- a/color-spantrace/tests/themes.rs +++ b/color-spantrace/tests/themes.rs @@ -52,19 +52,27 @@ fn test_capture(x: u8) -> SpanTrace { #[test] fn test_backwards_compatibility() { std::env::set_var("RUST_LIB_BACKTRACE", "full"); + + // This integration is ran by cargo with cwd="color-spantrace", but the string literals for + // `file!` are relative to the workspace root. This changes the cwd to the workspace root. + // + // The behavior of file! when invoked from a workspace is not document, as non-member path + // dependencies will get an absolute path. + std::env::set_current_dir("..").unwrap(); + Registry::default().with(ErrorLayer::default()).init(); let spantrace = test_capture(42); let colored_spantrace = format!("{}", color_spantrace::colorize(&spantrace)); let control_file_name = "theme_control.txt"; - let control_file_path = ["tests/data/", control_file_name].concat(); + let control_file_path = ["color-spantrace/tests/data/", control_file_name].concat(); // If `control_file_path` is missing, save corresponding file to current working directory, and panic with the request to move these files to `control_file_path`, and to commit them to Git. Being explicit (instead of saving directly to `control_file_path` to make sure `control_file_path` is committed to Git. These files anyway should never be missing. if !Path::new(&control_file_path).is_file() { std::fs::write(control_file_name, &colored_spantrace) - .expect("\n\nError saving `colored_spanntrace` to a file"); + .expect("\n\nError saving `colored_spantrace` to a file"); panic!("Required test data missing! Fix this, by moving '{}' to '{}', and commit it to Git.\n\nNote: '{0}' was just generated in the current working directory.\n\n", control_file_name, control_file_path); } From e54e98f31334c2c0ec5dcd85f1295f2b93c4adc7 Mon Sep 17 00:00:00 2001 From: Tei Roberts Date: Tue, 10 Oct 2023 23:43:32 +0200 Subject: [PATCH 2/4] fix: color-spantrace does not work in miri sandbox --- color-spantrace/tests/themes.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/color-spantrace/tests/themes.rs b/color-spantrace/tests/themes.rs index c1fdcfb..52cb27d 100644 --- a/color-spantrace/tests/themes.rs +++ b/color-spantrace/tests/themes.rs @@ -49,6 +49,7 @@ fn test_capture(x: u8) -> SpanTrace { } } +#[cfg(not(miri))] #[test] fn test_backwards_compatibility() { std::env::set_var("RUST_LIB_BACKTRACE", "full"); From 0ad6355d9f06f50a29030daf4e4aa30c0311a445 Mon Sep 17 00:00:00 2001 From: Tei Roberts Date: Tue, 10 Oct 2023 23:46:25 +0200 Subject: [PATCH 3/4] chore: clarify file! behavior --- color-spantrace/tests/themes.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/color-spantrace/tests/themes.rs b/color-spantrace/tests/themes.rs index 52cb27d..e6fbe53 100644 --- a/color-spantrace/tests/themes.rs +++ b/color-spantrace/tests/themes.rs @@ -57,8 +57,10 @@ fn test_backwards_compatibility() { // This integration is ran by cargo with cwd="color-spantrace", but the string literals for // `file!` are relative to the workspace root. This changes the cwd to the workspace root. // - // The behavior of file! when invoked from a workspace is not document, as non-member path - // dependencies will get an absolute path. + // The behavior of file! when invoked from a workspace is not documented. See: . + // + // Noteworthy: non-member path dependencies will get an absolute path, as will registry and git + // dependencies. std::env::set_current_dir("..").unwrap(); Registry::default().with(ErrorLayer::default()).init(); From 0d7f941eb213e8bb20387947db5c156fbebb1ce7 Mon Sep 17 00:00:00 2001 From: Tei Roberts Date: Tue, 10 Oct 2023 23:51:31 +0200 Subject: [PATCH 4/4] fix: unused imports under miri --- color-spantrace/tests/themes.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/color-spantrace/tests/themes.rs b/color-spantrace/tests/themes.rs index e6fbe53..2f24d63 100644 --- a/color-spantrace/tests/themes.rs +++ b/color-spantrace/tests/themes.rs @@ -32,12 +32,8 @@ */ -use ansi_parser::{AnsiParser, AnsiSequence, Output}; -use std::{fs, path::Path}; use tracing::instrument; -use tracing_error::ErrorLayer; use tracing_error::SpanTrace; -use tracing_subscriber::{prelude::*, registry::Registry}; #[instrument] fn test_capture(x: u8) -> SpanTrace { @@ -52,6 +48,10 @@ fn test_capture(x: u8) -> SpanTrace { #[cfg(not(miri))] #[test] fn test_backwards_compatibility() { + use ansi_parser::{AnsiParser, AnsiSequence, Output}; + use std::{fs, path::Path}; + use tracing_error::ErrorLayer; + use tracing_subscriber::{prelude::*, registry::Registry}; std::env::set_var("RUST_LIB_BACKTRACE", "full"); // This integration is ran by cargo with cwd="color-spantrace", but the string literals for