mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-09-11 05:35:53 +03:00
Add actual value type in assert error message
This commit is contained in:
parent
668dd36343
commit
4a67bd5cb0
@ -4,6 +4,6 @@ error: Invalid variable type
|
||||
| GET http://localhost:8000/unused
|
||||
| ...
|
||||
6 | location: {{redirect}}
|
||||
| ^^^^^^^^ expecting boolean, actual value is <10>
|
||||
| ^^^^^^^^ expecting boolean, actual value is integer <10>
|
||||
|
|
||||
|
||||
|
@ -214,7 +214,7 @@ error: Invalid variable type
|
||||
| GET http://localhost:8000/runner_errors
|
||||
| ...
|
||||
137 | verbose: {{verbose}}
|
||||
| ^^^^^^^ expecting boolean, actual value is <1>
|
||||
| ^^^^^^^ expecting boolean, actual value is integer <1>
|
||||
|
|
||||
|
||||
error: Undefined variable
|
||||
|
@ -214,7 +214,7 @@
|
||||
[1;34m |[0m [90mGET http://localhost:8000/runner_errors[0m
|
||||
[1;34m |[0m[90m ...[0m
|
||||
[1;34m137 |[0m verbose: {{verbose}}
|
||||
[1;34m |[0m[1;31m ^^^^^^^ expecting boolean, actual value is <1>[0m
|
||||
[1;34m |[0m[1;31m ^^^^^^^ expecting boolean, actual value is integer <1>[0m
|
||||
[1;34m |[0m
|
||||
|
||||
[1;31merror[0m: [1mUndefined variable[0m
|
||||
|
@ -265,7 +265,7 @@ impl DisplaySourceError for RunnerError {
|
||||
RunnerErrorKind::TemplateVariableInvalidType {
|
||||
value, expecting, ..
|
||||
} => {
|
||||
let message = &format!("expecting {expecting}, actual value is <{value}>");
|
||||
let message = &format!("expecting {expecting}, actual value is {value}");
|
||||
let message = hurl_core::error::add_carets(message, self.source_info, content);
|
||||
color_red_multiline_string(&message)
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ fn eval_boolean_option(
|
||||
v => {
|
||||
let kind = RunnerErrorKind::TemplateVariableInvalidType {
|
||||
name: expr.variable.name.clone(),
|
||||
value: v.to_string(),
|
||||
value: v.format(),
|
||||
expecting: "boolean".to_string(),
|
||||
};
|
||||
Err(RunnerError::new(expr.variable.source_info, kind, false))
|
||||
@ -331,7 +331,7 @@ fn eval_natural_option(
|
||||
if value < 0 {
|
||||
let kind = RunnerErrorKind::TemplateVariableInvalidType {
|
||||
name: expr.variable.name.clone(),
|
||||
value: value.to_string(),
|
||||
value: format!("integer <{value}>"),
|
||||
expecting: "positive integer".to_string(),
|
||||
};
|
||||
Err(RunnerError::new(expr.variable.source_info, kind, false))
|
||||
@ -342,7 +342,7 @@ fn eval_natural_option(
|
||||
v => {
|
||||
let kind = RunnerErrorKind::TemplateVariableInvalidType {
|
||||
name: expr.variable.name.clone(),
|
||||
value: v.to_string(),
|
||||
value: v.format(),
|
||||
expecting: "positive integer".to_string(),
|
||||
};
|
||||
Err(RunnerError::new(expr.variable.source_info, kind, false))
|
||||
@ -367,7 +367,7 @@ fn eval_repeat_option(
|
||||
} else {
|
||||
let kind = RunnerErrorKind::TemplateVariableInvalidType {
|
||||
name: expr.variable.name.clone(),
|
||||
value: value.to_string(),
|
||||
value: format!("integer <{value}>"),
|
||||
expecting: "integer".to_string(),
|
||||
};
|
||||
Err(RunnerError::new(expr.variable.source_info, kind, false))
|
||||
@ -376,7 +376,7 @@ fn eval_repeat_option(
|
||||
v => {
|
||||
let kind = RunnerErrorKind::TemplateVariableInvalidType {
|
||||
name: expr.variable.name.clone(),
|
||||
value: v.to_string(),
|
||||
value: v.format(),
|
||||
expecting: "integer".to_string(),
|
||||
};
|
||||
Err(RunnerError::new(expr.variable.source_info, kind, false))
|
||||
@ -401,7 +401,7 @@ fn eval_retry_option(
|
||||
} else {
|
||||
let kind = RunnerErrorKind::TemplateVariableInvalidType {
|
||||
name: expr.variable.name.clone(),
|
||||
value: value.to_string(),
|
||||
value: format!("integer <{value}>"),
|
||||
expecting: "integer".to_string(),
|
||||
};
|
||||
Err(RunnerError::new(expr.variable.source_info, kind, false))
|
||||
@ -516,7 +516,7 @@ mod tests {
|
||||
error.kind,
|
||||
RunnerErrorKind::TemplateVariableInvalidType {
|
||||
name: "verbose".to_string(),
|
||||
value: "10".to_string(),
|
||||
value: "integer <10>".to_string(),
|
||||
expecting: "boolean".to_string()
|
||||
}
|
||||
);
|
||||
|
@ -137,7 +137,7 @@ impl Number {
|
||||
}
|
||||
|
||||
impl Value {
|
||||
fn expected(&self) -> String {
|
||||
pub(crate) fn format(&self) -> String {
|
||||
match self {
|
||||
Value::Bool(value) => format!("bool <{value}>"),
|
||||
Value::Bytes(values) => format!("list of size {}", values.len()),
|
||||
@ -182,23 +182,23 @@ fn expected_no_value(
|
||||
match &predicate_func_value {
|
||||
PredicateFuncValue::Equal { value, .. } | PredicateFuncValue::NotEqual { value, .. } => {
|
||||
let value = eval_predicate_value(value, variables, context_dir)?;
|
||||
Ok(value.expected())
|
||||
Ok(value.format())
|
||||
}
|
||||
PredicateFuncValue::GreaterThan { value, .. } => {
|
||||
let value = eval_predicate_value(value, variables, context_dir)?;
|
||||
Ok(format!("greater than <{}>", value.expected()))
|
||||
Ok(format!("greater than <{}>", value.format()))
|
||||
}
|
||||
PredicateFuncValue::GreaterThanOrEqual { value, .. } => {
|
||||
let value = eval_predicate_value(value, variables, context_dir)?;
|
||||
Ok(format!("greater than or equals to <{}>", value.expected()))
|
||||
Ok(format!("greater than or equals to <{}>", value.format()))
|
||||
}
|
||||
PredicateFuncValue::LessThan { value, .. } => {
|
||||
let value = eval_predicate_value(value, variables, context_dir)?;
|
||||
Ok(format!("less than <{}>", value.expected()))
|
||||
Ok(format!("less than <{}>", value.format()))
|
||||
}
|
||||
PredicateFuncValue::LessThanOrEqual { value, .. } => {
|
||||
let value = eval_predicate_value(value, variables, context_dir)?;
|
||||
Ok(format!("less than or equals to <{}>", value.expected()))
|
||||
Ok(format!("less than or equals to <{}>", value.format()))
|
||||
}
|
||||
PredicateFuncValue::StartWith {
|
||||
value: expected, ..
|
||||
@ -220,7 +220,7 @@ fn expected_no_value(
|
||||
}
|
||||
PredicateFuncValue::Include { value, .. } => {
|
||||
let value = eval_predicate_value(value, variables, context_dir)?;
|
||||
Ok(format!("include {}", value.expected()))
|
||||
Ok(format!("include {}", value.format()))
|
||||
}
|
||||
PredicateFuncValue::Match {
|
||||
value: expected, ..
|
||||
|
Loading…
Reference in New Issue
Block a user