Skip to content
Draft
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
157 changes: 74 additions & 83 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ doctest = false # but no doc tests

[dependencies]
rustc_version = "0.4"
colored = "2"
owo-colors = "3.5"
lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -29,6 +29,8 @@ prettydiff = { version = "0.7", default_features = false }
annotate-snippets = { version = "0.11.2" }
levenshtein = "1.0.5"
spanned = "0.2.1"
supports-color = "3.0"
anstream = { version = "0.6", default-features = false, features = ["auto"]}

[dependencies.regex]
version = "1.5.5"
Expand Down
7 changes: 5 additions & 2 deletions src/diff.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use colored::*;
use anstream::{print, println};
use owo_colors::OwoColorize as _;
use prettydiff::{basic::DiffOp, basic::DiffOp::*, diff_lines, diff_words};

/// How many lines of context are displayed around the actual diffs
Expand Down Expand Up @@ -52,10 +53,12 @@ fn row(row: DiffOp<'_, &str>) {
}

fn print_line_diff(l: &str, r: &str) {
use supports_color::Stream;

let diff = diff_words(l, r);
let diff = diff.diff();
if has_both_insertions_and_deletions(&diff)
|| !colored::control::SHOULD_COLORIZE.should_colorize()
|| !supports_color::on_cached(Stream::Stdout).map_or(false, |support| support.has_basic)
{
// The line both adds and removes chars, print both lines, but highlight their differences instead of
// drawing the entire line in red/green.
Expand Down
27 changes: 15 additions & 12 deletions src/status_emitter.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
//! Variaous schemes for reporting messages during testing or after testing is done.

use annotate_snippets::{Renderer, Snippet};
use anstream::{print, println};
use bstr::ByteSlice;
use colored::Colorize;
use crossbeam_channel::{Sender, TryRecvError};
use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle};
use owo_colors::OwoColorize as _;
use spanned::Span;

use crate::{
Expand Down Expand Up @@ -314,13 +315,12 @@ impl TestStatus for TextTest {
self.text.sender.send(Msg::Inc).unwrap();
self.text.sender.send(Msg::Pop(self.msg(), None)).unwrap();
} else {
let result = match result {
Ok(TestOk::Ok) => "ok".green(),
Err(Errored { .. }) => "FAILED".bright_red().bold(),
Ok(TestOk::Ignored) => "ignored (in-test comment)".yellow(),
};
let old_msg = self.msg();
let msg = format!("... {result}");
let msg = match result {
Ok(TestOk::Ok) => format!("... {}", "ok".green()),
Err(Errored { .. }) => format!("... {}", "FAILED".bright_red().bold()),
Ok(TestOk::Ignored) => format!("... {}", "ignored (in-test comment)".yellow()),
};
if ProgressDrawTarget::stdout().is_hidden() {
println!("{old_msg} {msg}");
std::io::stdout().flush().unwrap();
Expand Down Expand Up @@ -714,6 +714,8 @@ fn create_error(
lines: &[(&[(&str, Option<Span>)], NonZeroUsize)],
file: &Path,
) {
use supports_color::Stream;

let source = std::fs::read_to_string(file).unwrap();
let source: Vec<_> = source.split_inclusive('\n').collect();
let file = file.display().to_string();
Expand Down Expand Up @@ -753,11 +755,12 @@ fn create_error(
}));
msg = msg.snippet(snippet);
}
let renderer = if colored::control::SHOULD_COLORIZE.should_colorize() {
Renderer::styled()
} else {
Renderer::plain()
};
let renderer =
if supports_color::on_cached(Stream::Stdout).map_or(false, |support| support.has_basic) {
Renderer::styled()
} else {
Renderer::plain()
};
println!("{}", renderer.render(msg));
}

Expand Down
Loading