Skip to content

Commit

Permalink
Merge pull request #173 from bshifter/filterx-condition-fix
Browse files Browse the repository at this point in the history
filterx condition error handling quick fix
  • Loading branch information
alltilla authored Jun 24, 2024
2 parents 7abac0a + c87ce9a commit 19b3063
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
6 changes: 1 addition & 5 deletions lib/filterx/expr-condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ _eval_condition(FilterXConditional *c)
goto exit;
}

if (!filterx_expr_list_eval(c->statements, &result))
{
filterx_object_unref(result);
return filterx_boolean_new(FALSE);
}
filterx_expr_list_eval(c->statements, &result);
exit:
filterx_object_unref(condition_value);
return result;
Expand Down
26 changes: 24 additions & 2 deletions lib/filterx/tests/test_expr_condition.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ Test(expr_condition, test_condition_must_return_last_expression_from_evaluated_c
}


Test(expr_condition, test_condition_falsey_expression_must_interrupt_sequential_code_execution)
Test(expr_condition, test_condition_falsey_statement_must_interrupt_sequential_code_execution)
{
GList *stmts = g_list_append(NULL, _assert_assign_var("$control-value", _string_to_filterXExpr("matching")));
stmts = g_list_append(stmts, filterx_literal_new(filterx_boolean_new(false)));
Expand All @@ -318,7 +318,7 @@ Test(expr_condition, test_condition_falsey_expression_must_interrupt_sequential_
stmts);

FilterXObject *cond_eval = filterx_expr_eval(cond);
cr_assert(cond_eval != NULL);
cr_assert_not_null(cond_eval);
cr_assert(filterx_object_truthy(cond_eval) == FALSE);

FilterXObject *control_value = _assert_get_test_variable("$control-value");
Expand All @@ -332,6 +332,28 @@ Test(expr_condition, test_condition_falsey_expression_must_interrupt_sequential_
filterx_object_unref(cond_eval);
}

Test(expr_condition, test_condition_error_statement_must_return_null)
{
GList *stmts = g_list_append(NULL, _assert_assign_var("$control-value", _string_to_filterXExpr("matching")));
stmts = g_list_append(stmts, filterx_dummy_error_new(""));
stmts = g_list_append(stmts, _assert_assign_var("$control-value3", _string_to_filterXExpr("matching3")));

FilterXExpr *cond = filterx_conditional_new_conditional_codeblock(filterx_literal_new(filterx_boolean_new(true)),
stmts);

FilterXObject *cond_eval = filterx_expr_eval(cond);
cr_assert_null(cond_eval);

FilterXObject *control_value = _assert_get_test_variable("$control-value");
cr_assert_eq(0, _assert_cmp_string_to_filterx_object("matching", control_value));
filterx_object_unref(control_value);
control_value = _assert_get_test_variable("$control-value3");
cr_assert_eq(0, _assert_cmp_string_to_filterx_object("default3", control_value));
filterx_object_unref(control_value);

filterx_expr_unref(cond);
filterx_object_unref(cond_eval);
}

Test(expr_condition, test_condition_do_not_allow_to_add_else_into_else, .signal=SIGABRT)
{
Expand Down

0 comments on commit 19b3063

Please sign in to comment.