From 1d02f0ef8078ce8aabac5b53ce1e49fdd1d6d70d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 13 Jan 2023 10:30:27 -0800 Subject: [PATCH] Print format diff to stdout (#1506) --- src/subcommand.rs | 8 ++++---- tests/fmt.rs | 10 +++++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/subcommand.rs b/src/subcommand.rs index 1c2ff85..bbb2bbb 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -383,12 +383,12 @@ impl Subcommand { for op in diff.ops() { for change in diff.iter_changes(op) { let (symbol, color) = match change.tag() { - ChangeTag::Delete => ("-", config.color.stderr().diff_deleted()), - ChangeTag::Equal => (" ", config.color.stderr()), - ChangeTag::Insert => ("+", config.color.stderr().diff_added()), + ChangeTag::Delete => ("-", config.color.stdout().diff_deleted()), + ChangeTag::Equal => (" ", config.color.stdout()), + ChangeTag::Insert => ("+", config.color.stdout().diff_added()), }; - eprint!("{}{symbol}{change}{}", color.prefix(), color.suffix()); + print!("{}{symbol}{change}{}", color.prefix(), color.suffix()); } } } diff --git a/tests/fmt.rs b/tests/fmt.rs index 1b46dcd..2a423d8 100644 --- a/tests/fmt.rs +++ b/tests/fmt.rs @@ -45,9 +45,11 @@ test! { name: check_found_diff, justfile: "x:=``\n", args: ("--unstable", "--fmt", "--check"), - stderr: " + stdout: " -x:=`` +x := `` + ", + stderr: " error: Formatted justfile differs from original. ", status: EXIT_FAILURE, @@ -65,10 +67,12 @@ test! { name: check_diff_color, justfile: "x:=``\n", args: ("--unstable", "--fmt", "--check", "--color", "always"), - stderr: " + stdout: " \u{1b}[31m-x:=`` \u{1b}[0m\u{1b}[32m+x := `` - \u{1b}[0m\u{1b}[1;31merror\u{1b}[0m: \u{1b}[1mFormatted justfile differs from original.\u{1b}[0m + \u{1b}[0m", + stderr: " + \u{1b}[1;31merror\u{1b}[0m: \u{1b}[1mFormatted justfile differs from original.\u{1b}[0m ", status: EXIT_FAILURE, }