Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
using diffy to show diff when showing output (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
amitu authored May 13, 2021
1 parent 9854b12 commit f7ee382
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
36 changes: 36 additions & 0 deletions fbt_lib/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,42 @@ pub fn main() -> Option<i32> {
std::str::from_utf8(&output.stderr).unwrap_or("failed to decode")
);
}
Err(crate::Failure::StdoutMismatch { expected, output }) => {
any_failed = true;
println!(
"{}: {} {} (stdout mismatch)",
case.id.blue(),
"FAILED".red(),
duration,
);
let stdout = std::str::from_utf8(&output.stdout).unwrap_or("failed to decode");
println!("stdout:\n\n{}\n", stdout);
println!(
"diff:\n\n{}\n",
diffy::create_patch(
(expected.to_owned() + "\n").as_str(),
(stdout.to_owned() + "\n").as_str()
)
);
}
Err(crate::Failure::StderrMismatch { expected, output }) => {
any_failed = true;
println!(
"{}: {} {} (stderr mismatch)",
case.id.blue(),
"FAILED".red(),
duration,
);
let stderr = std::str::from_utf8(&output.stderr).unwrap_or("failed to decode");
println!("stderr:\n\n{}\n", stderr);
println!(
"diff:\n\n{}\n",
diffy::create_patch(
(expected.to_owned() + "\n").as_str(),
(stderr.to_owned() + "\n").as_str()
)
);
}
Err(e) => {
any_failed = true;
println!(
Expand Down
29 changes: 28 additions & 1 deletion tests/03_failing_fbt_tests/cmd.p1
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,33 @@ In this test we check for failing conditions.

-- stdout:

01_basic: FAILED (StdoutMismatch { expected: "hello world", output: Output { status: ExitStatus(ExitStatus(0)), stdout: "hello there", stderr: "" } })
01_stdout_mismatch: FAILED (stdout mismatch)
stdout:

hello there

diff:

\--- original
+++ modified
@@ -1 +1 @@
-hello world
+hello there


02_output_mismatch: SKIPPED (output not yet implemented)
03_stderr_mismatch: FAILED (stderr mismatch)
stderr:

hello there

diff:

\--- original
+++ modified
@@ -1 +1 @@
-hello world
+hello there



Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- fbt:
cmd: cat one 1>&2

-- stderr:

hello world
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello there

0 comments on commit f7ee382

Please sign in to comment.