Skip to content

Commit

Permalink
Refacto error_string in order to support diff messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fabricereix committed Apr 7, 2024
1 parent e1a1635 commit 57f9c33
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 100 deletions.
4 changes: 2 additions & 2 deletions integration/hurl/tests_failed/assert_newline.err
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ error: Assert body value
| ...
10 | <p>Hello</p>
| ^ actual value is <<p>Hello</p>

>
|
| >
|

4 changes: 2 additions & 2 deletions integration/hurl/tests_failed/assert_value_error.err
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ error: Assert failure
| ...
11 | jsonpath "$.line_terminator" == "\r\n"
| actual: string <
| >
|>
| expected: string <
| >
|>
|

error: Assert failure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
},
{
"line": 11,
"message": "Assert failure\n --> tests_failed/assert_value_error.hurl:11:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n11 | jsonpath \"$.line_terminator\" == \"\\r\\n\"\n | actual: string <\n | >\n | expected: string <\n | >\n |",
"message": "Assert failure\n --> tests_failed/assert_value_error.hurl:11:0\n |\n | GET http://localhost:8000/error-assert-value\n | ...\n11 | jsonpath \"$.line_terminator\" == \"\\r\\n\"\n | actual: string <\n |>\n | expected: string <\n |>\n |",
"success": false
},
{
Expand Down
12 changes: 10 additions & 2 deletions packages/hurl/src/runner/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ impl hurl_core::error::Error for Error {
..
} => {
let additional = if *type_mismatch {
"\n>>> types between actual and expected are not consistent"
"\n >>> types between actual and expected are not consistent"
} else {
""
};
format!("actual: {actual}\nexpected: {expected}{additional}")
format!(" actual: {actual}\n expected: {expected}{additional}")
}
RunnerError::AssertHeaderValueError { actual } => {
format!("actual value is <{actual}>")
Expand Down Expand Up @@ -257,6 +257,14 @@ impl hurl_core::error::Error for Error {
}
}
}

fn show_source_line(&self) -> bool {
true
}

fn show_caret(&self) -> bool {
!matches!(&self.inner, RunnerError::AssertFailure { .. })
}
}

impl From<HttpError> for RunnerError {
Expand Down
Loading

0 comments on commit 57f9c33

Please sign in to comment.