Add actual value type in assert error message

This commit is contained in:
Fabrice Reix 2024-06-25 13:08:10 +02:00 committed by hurl-bot
parent 668dd36343
commit 4a67bd5cb0
No known key found for this signature in database
GPG Key ID: 1283A2B4A0DCAF8D
6 changed files with 18 additions and 18 deletions

View File

@ -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>
|

View File

@ -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

View File

@ -214,7 +214,7 @@
 | 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

View File

@ -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)
}

View File

@ -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()
}
);

View File

@ -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, ..