Skip to content

Commit

Permalink
Improve assertions in src/tests.rs (#10449)
Browse files Browse the repository at this point in the history
# Description
Mention the expected substring in:
- `fn run_test_contains()`
- `fn test_ide_contains()`
- `fn fail_test()`


# Developer-Facing Changes
You can read the test failure to figure out what is going on, don't
necessarily have to look up the test

New look of failure
```
failures:

---- tests::test_math::broken_math stdout ----
stdout:
stderr: Error: nu::parser::incomplete_math_expression

  × Incomplete math expression.
   ╭─[/tmp/.tmpz0V8nC:1:1]
 1 │ 3 +
   ·   ┬
   ·   ╰── incomplete math expression
   ╰────


Expected error to contain: Incomplete universe
thread 'tests::test_math::broken_math' panicked at 'assertion failed: !stderr.is_empty() && stderr.contains(expected)', src/tests.rs:181:5
```
  • Loading branch information
sholderbach committed Sep 21, 2023
1 parent 4aa9102 commit 1072bd0
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ pub fn run_test_contains(input: &str, expected: &str) -> TestResult {
println!("stdout: {stdout}");
println!("stderr: {stderr}");

println!("Expected output to contain: {expected}");
assert!(output.status.success());

assert!(stdout.contains(expected));
Expand Down Expand Up @@ -144,6 +145,7 @@ pub fn test_ide_contains(input: &str, ide_commands: &[&str], expected: &str) ->

println!("stdout: {stdout}");
println!("stderr: {stderr}");
println!("Expected output to contain: {expected}");

assert!(output.status.success());

Expand Down Expand Up @@ -174,6 +176,7 @@ pub fn fail_test(input: &str, expected: &str) -> TestResult {

println!("stdout: {stdout}");
println!("stderr: {stderr}");
println!("Expected error to contain: {expected}");

assert!(!stderr.is_empty() && stderr.contains(expected));

Expand Down

0 comments on commit 1072bd0

Please sign in to comment.