Improve coverage on options section.

This commit is contained in:
Jean-Christophe Amiel 2024-07-06 21:01:18 +02:00
parent 97f1a05000
commit 25d6716145
No known key found for this signature in database
GPG Key ID: 07FF11CFD55356CC
15 changed files with 150 additions and 13 deletions

View File

@ -0,0 +1,7 @@
error: Parsing literal
--> tests_error_parser/invalid_option_retry.hurl:3:8
|
3 | retry: -24
| ^ expecting 'integer >= -1'
|

View File

@ -0,0 +1 @@
2

View File

@ -0,0 +1,4 @@
GET https://localhost:8000/hello
[Options]
retry: -24
HTTP 200

View File

@ -0,0 +1,4 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
hurl tests_error_parser/invalid_option_retry.hurl

View File

@ -0,0 +1,4 @@
#!/bin/bash
set -Eeuo pipefail
hurl tests_error_parser/invalid_option_retry.hurl

View File

@ -5,3 +5,10 @@ error: HTTP connection
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ too many redirect
|
error: HTTP connection
--> tests_failed/max_redirect_option.hurl:9:5
|
9 | GET http://localhost:8000/redirect/7
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ too many redirect
|

View File

@ -2,7 +2,13 @@ GET http://localhost:8000/redirect/7
[Options]
location: true
max-redirs: 5
HTTP 200
# max-redirs should work in template also
GET http://localhost:8000/redirect/7
[Options]
variable: max=5
location: true
max-redirs: {{max}}
HTTP 200

View File

@ -1,3 +1,4 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
hurl tests_failed/max_redirect_option.hurl
hurl --continue-on-error tests_failed/max_redirect_option.hurl

View File

@ -1,3 +1,4 @@
#!/bin/bash
set -Eeuo pipefail
hurl tests_failed/max_redirect_option.hurl
hurl --continue-on-error tests_failed/max_redirect_option.hurl

View File

@ -1,9 +1,63 @@
error: Invalid variable type
--> tests_failed/options_template.hurl:6:13
--> tests_failed/options_template.hurl:8:13
|
| GET http://localhost:8000/unused
| ...
6 | location: {{redirect}}
8 | location: {{location}}
| ^^^^^^^^ expecting boolean, actual value is integer <10>
|
error: Invalid variable type
--> tests_failed/options_template.hurl:15:15
|
| GET http://localhost:8000/unused
| ...
15 | max-redirs: {{max_redirect}}
| ^^^^^^^^^^^^ expecting positive integer, actual value is integer <-123>
|
error: Invalid variable type
--> tests_failed/options_template.hurl:22:15
|
| GET http://localhost:8000/unused
| ...
22 | max-redirs: {{max_redirect}}
| ^^^^^^^^^^^^ expecting positive integer, actual value is string <abc>
|
error: Invalid variable type
--> tests_failed/options_template.hurl:29:11
|
| GET http://localhost:8000/unused
| ...
29 | repeat: {{count}}
| ^^^^^ expecting integer, actual value is integer <-2>
|
error: Invalid variable type
--> tests_failed/options_template.hurl:36:11
|
| GET http://localhost:8000/unused
| ...
36 | repeat: {{count}}
| ^^^^^ expecting integer, actual value is string <foo>
|
error: Invalid variable type
--> tests_failed/options_template.hurl:43:10
|
| GET http://localhost:8000/unused
| ...
43 | retry: {{count}}
| ^^^^^ expecting integer >= -1, actual value is integer <-2>
|
error: Invalid variable type
--> tests_failed/options_template.hurl:50:10
|
| GET http://localhost:8000/unused
| ...
50 | retry: {{count}}
| ^^^^^ expecting integer, actual value is foo
|

View File

@ -1,6 +1,51 @@
# Invalid type at runtime
# Invalid options values. We computed these options at runtime using
# variables, to bypass the parser check that is run before executing
# a Hurl file.
GET http://localhost:8000/unused
[Options]
variable: redirect=10
location: {{redirect}}
variable: location=10
location: {{location}}
HTTP 200
GET http://localhost:8000/unused
[Options]
variable: max_redirect=-123
max-redirs: {{max_redirect}}
HTTP 200
GET http://localhost:8000/unused
[Options]
variable: max_redirect=abc
max-redirs: {{max_redirect}}
HTTP 200
GET http://localhost:8000/unused
[Options]
variable: count=-2
repeat: {{count}}
HTTP 200
GET http://localhost:8000/unused
[Options]
variable: count=foo
repeat: {{count}}
HTTP 200
GET http://localhost:8000/unused
[Options]
variable: count=-2
retry: {{count}}
HTTP 200
GET http://localhost:8000/unused
[Options]
variable: count=foo
retry: {{count}}
HTTP 200

View File

@ -1,3 +1,4 @@
Set-StrictMode -Version latest
$ErrorActionPreference = 'Stop'
hurl tests_failed/options_template.hurl
hurl --continue-on-error tests_failed/options_template.hurl

View File

@ -1,3 +1,4 @@
#!/bin/bash
set -Eeuo pipefail
hurl tests_failed/options_template.hurl
hurl --continue-on-error tests_failed/options_template.hurl

View File

@ -320,6 +320,7 @@ fn eval_boolean_option(
}
}
/// Evals a natural option value (>=0), given a set of `variables`.
fn eval_natural_option(
natural_value: &NaturalOption,
variables: &HashMap<String, Value>,
@ -402,7 +403,7 @@ fn eval_retry_option(
let kind = RunnerErrorKind::TemplateVariableInvalidType {
name: expr.variable.name.clone(),
value: format!("integer <{value}>"),
expecting: "integer".to_string(),
expecting: "integer >= -1".to_string(),
};
Err(RunnerError::new(expr.variable.source_info, kind, false))
}

View File

@ -346,7 +346,7 @@ fn retry_option(reader: &mut Reader) -> ParseResult<RetryOption> {
reader.seek(start);
let exp = expr::parse(reader).map_err(|e| {
let kind = ParseErrorKind::Expecting {
value: "integer".to_string(),
value: "integer >= -1".to_string(),
};
ParseError::new(e.pos, false, kind)
})?;
@ -588,7 +588,7 @@ mod tests {
assert_eq!(
error.kind,
ParseErrorKind::Expecting {
value: "integer".to_string()
value: "integer >= -1".to_string()
}
);
}