From d15497e146d2bd58a8de6bb42584618ca631c262 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 13 Jan 2023 10:30:27 -0800 Subject: [PATCH] Print forma 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 1c2ff857f6..bbb2bbb933 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 1b46dcd78b..2a423d830c 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, }