mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-23 00:44:55 +03:00
Fix coloring in the error string
This commit is contained in:
parent
a870767e99
commit
a28fe82622
8
integration/hurl/tests_failed/color.err
Normal file
8
integration/hurl/tests_failed/color.err
Normal file
@ -0,0 +1,8 @@
|
||||
[1;31merror[0m: [1mAssert status code[0m
|
||||
[1;34m-->[0m tests_failed/color.hurl:2:6
|
||||
[1;34m |[0m
|
||||
[1;34m |[0m [90mGET http://localhost:8000/undefined[0m
|
||||
[1;34m 2 |[0m HTTP 200
|
||||
[1;34m |[0m[1;31m ^^^ [0m[1;31mactual value is <404>[0m
|
||||
[1;34m |[0m
|
||||
|
1
integration/hurl/tests_failed/color.exit
Executable file
1
integration/hurl/tests_failed/color.exit
Executable file
@ -0,0 +1 @@
|
||||
4
|
4
integration/hurl/tests_failed/color.hurl
Normal file
4
integration/hurl/tests_failed/color.hurl
Normal file
@ -0,0 +1,4 @@
|
||||
GET http://localhost:8000/undefined
|
||||
HTTP 200
|
||||
|
||||
|
3
integration/hurl/tests_failed/color.ps1
Normal file
3
integration/hurl/tests_failed/color.ps1
Normal file
@ -0,0 +1,3 @@
|
||||
Set-StrictMode -Version latest
|
||||
$ErrorActionPreference = 'Stop'
|
||||
hurl tests_failed/color.hurl --color
|
3
integration/hurl/tests_failed/color.sh
Executable file
3
integration/hurl/tests_failed/color.sh
Executable file
@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
set -Eeuo pipefail
|
||||
hurl tests_failed/color.hurl --color
|
@ -448,13 +448,21 @@ pub(crate) fn error_string<E: Error>(
|
||||
// The number of digits of the lines count.
|
||||
let loc_max_width = max(lines.len().to_string().len(), 2);
|
||||
let separator = "|";
|
||||
let separator = if colored {
|
||||
separator.blue().bold().to_string()
|
||||
} else {
|
||||
separator.to_string()
|
||||
};
|
||||
|
||||
let spaces = " ".repeat(loc_max_width);
|
||||
let prefix = format!("{spaces} {separator}");
|
||||
let prefix = if colored {
|
||||
prefix.blue().bold().to_string()
|
||||
} else {
|
||||
prefix.to_string()
|
||||
};
|
||||
|
||||
let prefix_with_number = format!("{error_line:>loc_max_width$} {separator}");
|
||||
let prefix_with_number = if colored {
|
||||
prefix_with_number.blue().bold().to_string()
|
||||
} else {
|
||||
prefix_with_number.to_string()
|
||||
};
|
||||
|
||||
// 1. First line is the description, ex. `Assert status code`.
|
||||
let description = if colored {
|
||||
@ -510,18 +518,9 @@ pub(crate) fn error_string<E: Error>(
|
||||
// with the line number '|' prefix
|
||||
let message = get_message(error, &lines, colored);
|
||||
for (i, line) in split_lines(&message).iter().enumerate() {
|
||||
if i == 0 {
|
||||
let loc_max_width = max(lines.len().to_string().len(), 2);
|
||||
|
||||
let mut s = format!("{error_line:>loc_max_width$}");
|
||||
if colored {
|
||||
s = s.blue().bold().to_string();
|
||||
}
|
||||
|
||||
text.push_str(format!("\n{s} |{line}").as_str());
|
||||
} else {
|
||||
text.push_str(format!("\n{prefix}{line}").as_str());
|
||||
}
|
||||
text.push('\n');
|
||||
text.push_str(if i == 0 { &prefix_with_number } else { &prefix });
|
||||
text.push_str(line);
|
||||
}
|
||||
|
||||
// 6. Appends additional empty line
|
||||
|
Loading…
Reference in New Issue
Block a user