Skip to content

Commit ad63978

Browse files
committed
Add option error-format in config_file
1 parent af6d2bf commit ad63978

7 files changed

Lines changed: 234 additions & 0 deletions

File tree

docs/spec/options/hurl/error_format.option

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ value_parser: ["short", "long"]
66
help: Control the format of error messages
77
help_heading: Output options
88
cli_only: true
9+
config_file: true
910
env_var: HURL_ERROR_FORMAT
1011
---
1112
Control the format of error message (short by default or long). When using long, the response body is logged when there are errors.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--error-format=long
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
* Request can be run with the following curl command:
2+
* curl 'http://localhost:8000/error-format-long/html'
3+
4+
HTTP/1.1 200
5+
Content-Length: 45
6+
Content-Type: text/html; charset=utf-8
7+
Date: <<<.*?>>>
8+
Server: Flask Server
9+
Via: waitress
10+
11+
<html><head><title>Test</title></head></html>
12+
13+
error: Assert header value
14+
--> tests_failed/error_format_long/error_format_long.hurl:7:15
15+
|
16+
| GET http://localhost:8000/error-format-long/html
17+
| ...
18+
7 | Content-Type: text/html
19+
| ^^^^^^^^^ actual value is <text/html; charset=utf-8>
20+
|
21+
22+
error: Assert failure
23+
--> tests_failed/error_format_long/error_format_long.hurl:9:0
24+
|
25+
| GET http://localhost:8000/error-format-long/html
26+
| ...
27+
9 | xpath "string(//head/title)" == "Welcome!"
28+
| actual: string <Test>
29+
| expected: string <Welcome!>
30+
|
31+
32+
error: Assert failure
33+
--> tests_failed/error_format_long/error_format_long.hurl:11:0
34+
|
35+
| GET http://localhost:8000/error-format-long/html
36+
| ...
37+
11 | xpath "//title" count == 2
38+
| actual: integer <1>
39+
| expected: integer <2>
40+
|
41+
42+
* Request can be run with the following curl command:
43+
* curl 'http://localhost:8000/error-format-long/json'
44+
45+
HTTP/1.1 200
46+
Content-Length: 115
47+
Content-Type: application/json
48+
Date: <<<.*?>>>
49+
Server: Flask Server
50+
Via: waitress
51+
52+
{"books": [{"name": "Dune", "author": "Franck Herbert"}, {"name": "Les Mis\u00e9rables", "author": "Victor Hugo"}]}
53+
54+
error: Assert failure
55+
--> tests_failed/error_format_long/error_format_long.hurl:18:0
56+
|
57+
| GET http://localhost:8000/error-format-long/json
58+
| ...
59+
18 | jsonpath "$.books" count == 12
60+
| actual: integer <2>
61+
| expected: integer <12>
62+
|
63+
64+
* Request can be run with the following curl command:
65+
* curl 'http://localhost:8000/error-format-long/rfc-7807'
66+
67+
HTTP/1.1 200
68+
Content-Length: 258
69+
Content-Type: application/problem+json
70+
Date: <<<.*?>>>
71+
Server: Flask Server
72+
Via: waitress
73+
74+
{"type": "https://example.com/probs/out-of-credit", "title": "You do not have enough credit.", "detail": "Your current balance is 30, but that costs 50.", "instance": "/account/12345/msgs/abc", "balance": 30, "accounts": ["/account/12345", "/account/67890"]}
75+
76+
error: Assert failure
77+
--> tests_failed/error_format_long/error_format_long.hurl:26:0
78+
|
79+
| GET http://localhost:8000/error-format-long/rfc-7807
80+
| ...
81+
26 | jsonpath "$.title" == "You have enough credit."
82+
| actual: string <You do not have enough credit.>
83+
| expected: string <You have enough credit.>
84+
|
85+
86+
* Request can be run with the following curl command:
87+
* curl 'http://localhost:8000/error-format-long/fhir'
88+
89+
HTTP/1.1 200
90+
Content-Length: 902
91+
Content-Type: application/fhir+json
92+
Date: <<<.*?>>>
93+
Server: Flask Server
94+
Via: waitress
95+
96+
{"resourceType": "Practitioner", "id": "example", "text": {"status": "generated", "div": "<div xmlns=\"http://www.w3.org/1999/xhtml\">\n <p>Dr Adam Careful is a Referring Practitioner for Acme Hospital from 1-Jan 2012 to 31-Mar\n 2012</p>\n </div>"}, "identifier": [{"system": "http://www.acme.org/practitioners", "value": "23"}], "active": true, "name": [{"family": "Careful", "given": ["Adam"], "prefix": ["Dr"]}], "address": [{"use": "home", "line": ["534 Erewhon St"], "city": "PleasantVille", "state": "Vic", "postalCode": "3999"}], "qualification": [{"identifier": [{"system": "http://example.org/UniversityIdentifier", "value": "12345"}], "code": {"coding": [{"system": "http://terminology.hl7.org/CodeSystem/v2-0360/2.7", "code": "BS", "display": "Bachelor of Science"}], "text": "Bachelor of Science"}, "period": {"start": "1995"}, "issuer": {"display": "Example University"}}]}
97+
98+
error: Assert failure
99+
--> tests_failed/error_format_long/error_format_long.hurl:34:0
100+
|
101+
| GET http://localhost:8000/error-format-long/fhir
102+
| ...
103+
34 | jsonpath "$.id" == "foo"
104+
| actual: string <example>
105+
| expected: string <foo>
106+
|
107+
108+
* Request can be run with the following curl command:
109+
* curl 'http://localhost:8000/error-format-long/csv'
110+
111+
HTTP/1.1 200
112+
Content-Length: 726
113+
Content-Type: text/csv; charset=utf-8
114+
Date: <<<.*?>>>
115+
Server: Flask Server
116+
Via: waitress
117+
118+
"Year","Score","Title"
119+
1968,86,"Greetings"
120+
1970,17,"Bloody Mama"
121+
1970,73,"Hi, Mom!"
122+
1971,40,"Born to Win"
123+
1973,98,"Mean Streets"
124+
1973,88,"Bang the Drum Slowly"
125+
1974,97,"The Godfather, Part II"
126+
1976,41,"The Last Tycoon"
127+
1976,99,"Taxi Driver"
128+
1977,47,"1900"
129+
1977,67,"New York, New York"
130+
1978,93,"The Deer Hunter"
131+
1980,97,"Raging Bull"
132+
1981,75,"True Confessions"
133+
1983,90,"The King of Comedy"
134+
1984,89,"Once Upon a Time in America"
135+
1984,60,"Falling in Love"
136+
1985,98,"Brazil"
137+
1986,65,"The Mission"
138+
1987,00,"Dear America: Letters Home From Vietnam"
139+
1987,80,"The Untouchables"
140+
1987,78,"Angel Heart"
141+
1988,96,"Midnight Run"
142+
1989,64,"Jacknife"
143+
1989,47,"We're No Angels"
144+
1990,88,"Awakenings"
145+
1990,29,"Stanley & Iris"
146+
1990,96,"Goodfellas"
147+
148+
149+
error: Assert failure
150+
--> tests_failed/error_format_long/error_format_long.hurl:42:0
151+
|
152+
| GET http://localhost:8000/error-format-long/csv
153+
| ...
154+
42 | body split "\n" nth 9 split "," nth 2 == "\"Taxi\""
155+
| actual: string <"Taxi Driver">
156+
| expected: string <"Taxi">
157+
|
158+
159+
* Request can be run with the following curl command:
160+
* curl 'http://localhost:8000/error-format-long/bytes'
161+
162+
HTTP/1.1 200
163+
Content-Length: 4
164+
Content-Type: application/octet-stream
165+
Date: <<<.*?>>>
166+
Server: Flask Server
167+
Via: waitress
168+
169+
Bytes <deadbeef...>
170+
171+
error: Assert failure
172+
--> tests_failed/error_format_long/error_format_long.hurl:50:0
173+
|
174+
| GET http://localhost:8000/error-format-long/bytes
175+
| ...
176+
50 | bytes == hex,beef;
177+
| actual: bytes <deadbeef>
178+
| expected: bytes <beef>
179+
|
180+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Set-StrictMode -Version latest
2+
$ErrorActionPreference = 'Stop'
3+
4+
$env:XDG_CONFIG_HOME = "$PSScriptRoot/config"
5+
6+
hurl --continue-on-error tests_failed/error_format_long/error_format_long.hurl
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
set -Eeuo pipefail
3+
4+
XDG_CONFIG_HOME=$(dirname "$0")/config
5+
export XDG_CONFIG_HOME
6+
7+
hurl --continue-on-error tests_failed/error_format_long/error_format_long.hurl

packages/hurl/src/cli/options/config_file/mod.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ mod primitives;
1919

2020
use std::path::Path;
2121

22+
use crate::cli::options::ErrorFormat;
2223
use crate::cli::options::HttpVersion;
2324
use crate::cli::options::config_file::primitives::{
2425
expect_no_value, parse_value, parse_value_separator,
@@ -255,6 +256,19 @@ fn parse_option(reader: &mut Reader, options: &mut CliOptions) -> Result<(), Con
255256
options.continue_on_error = true;
256257
Ok(())
257258
}
259+
"error-format" => {
260+
parse_value_separator(reader)?;
261+
save = reader.cursor();
262+
let value = parse_value(reader)?;
263+
let error_format = value.parse::<ErrorFormat>().map_err(|_| {
264+
ConfigFileError::new(
265+
save.pos,
266+
"Option --error-format requires one of the following values: short, long",
267+
)
268+
})?;
269+
options.error_format = error_format;
270+
Ok(())
271+
}
258272
"no-assert" => {
259273
expect_no_value(reader)?;
260274
options.no_assert = true;
@@ -539,6 +553,30 @@ mod tests {
539553
assert_eq!(reader.cursor().pos, Pos::new(2, 1));
540554
}
541555

556+
#[test]
557+
fn test_parse_option_error_format() {
558+
let mut reader = Reader::new("--error-format=long\n");
559+
let mut options = CliOptions::default();
560+
assert_eq!(options.error_format, ErrorFormat::Short);
561+
assert!(parse_option(&mut reader, &mut options).is_ok());
562+
assert_eq!(options.error_format, ErrorFormat::Long);
563+
assert_eq!(reader.cursor().pos, Pos::new(2, 1));
564+
}
565+
566+
#[test]
567+
fn test_parse_option_error_format_invalid_value() {
568+
let mut reader = Reader::new("--error-format=foo\n");
569+
let mut options = CliOptions::default();
570+
let error = parse_option(&mut reader, &mut options).unwrap_err();
571+
assert_eq!(
572+
error,
573+
ConfigFileError::new(
574+
Pos::new(1, 16),
575+
"Option --error-format requires one of the following values: short, long"
576+
)
577+
);
578+
}
579+
542580
#[test]
543581
fn test_parse_option_http11() {
544582
let mut reader = Reader::new("--http1.1\n");

0 commit comments

Comments
 (0)