Skip to content

Commit

Permalink
Make error checking more lenient
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Oct 4, 2022
1 parent 646e473 commit 1f610e4
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 12 deletions.
38 changes: 31 additions & 7 deletions distribution/lib/Standard/Test/0.0.0-dev/src/Problems.enso
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,52 @@ import Standard.Test
the standard testing approach, like `x.should_equal y`.
test_problem_handling : (Problem_Behavior -> Any) -> Vector Any -> (Any -> Nothing) -> Nothing
test_problem_handling action expected_problems result_checker =
error_checker error_result =
first_problem = expected_problems.first
first_problem_type = Meta.meta first_problem . constructor
error_result . should_fail_with first_problem_type frames_to_skip=3
error_result.catch . should_equal first_problem frames_to_skip=3
warnings_checker warnings =
## TODO [RW] we are not checking if there are no duplicate warnings, because the warnings are in fact duplicated - we should figure out how to handle that and then possibly modify the test
warnings . should_contain_the_same_elements_as expected_problems frames_to_skip=3
test_advanced_problem_handling action error_checker warnings_checker result_checker

## UNSTABLE
Tests how a specific operation behaves depending on the requested
`Problem_Behavior`. A variant that allows more customization over how
expected problems are checked.

Arguments:
- action: The action to execute. It takes a `Problem_Behavior` which
specifies whether it should ignore problems, report them as warnings or
raise a dataflow error on the first encountered problem.
- error_checker: A function which should verify that the returned error is as
expected.
- warnings_checker: A function which should verify that the returned warnings
are as expected.
- result_checker: A function which should verify that the result generated by
the action is correct. It does not return anything, instead it should use
the standard testing approach, like `x.should_equal y`.
test_advanced_problem_handling : (Problem_Behavior -> Any) -> (Any -> Nothing) -> (Vector Any -> Nothing) -> (Any -> Nothing) -> Nothing
test_advanced_problem_handling action error_checker warnings_checker result_checker =
# First, we check the action ignoring any warnings.
result_ignoring = action Problem_Behavior.Ignore
result_checker result_ignoring
Warning.get_all result_ignoring . should_equal [] frames_to_skip=1

# Then, we check the fail-on-first-error mode.
first_problem = expected_problems.first
first_problem_type = Meta.meta first_problem . constructor
error_result = action Problem_Behavior.Report_Error
error_result . should_fail_with first_problem_type frames_to_skip=1
error_result.catch . should_equal first_problem frames_to_skip=1
error_checker error_result

# Lastly, we check the report warnings mode and ensure that both the result is correct and the warnings are as expected.
result_warning = action Problem_Behavior.Report_Warning
result_checker result_warning
warnings = Warning.get_all result_warning . map .value
## TODO [RW] we are not checking if there are no duplicate warnings, because the warnings are in fact duplicated - we should figure out how to handle that and then possibly modify the test
warnings . should_contain_the_same_elements_as expected_problems frames_to_skip=1
warnings_checker warnings

## UNSTABLE
Checks if the provided value does not have any attached problems.
assume_no_problems result =
result.is_error.should_be_false
warnings = Warning.get_all result . map .value
warnings.should_equal []
warnings.should_equal []
22 changes: 17 additions & 5 deletions test/Table_Tests/src/Common_Table_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -1137,8 +1137,14 @@ spec prefix table_builder test_selection pending=Nothing =

check_column_type_error_handling action =
tester = check_empty ["ix", "X", "Y"]
problems = [Invalid_Value_Type.Invalid_Value_Type_Data Value_Type.Char Value_Type.Integer]
Problems.test_problem_handling action problems tester
check_problem problem =
problem.should_be_a Invalid_Value_Type.Invalid_Value_Type_Data
problem.expected . should_equal Value_Type.Char
warnings_tester warnings =
(warnings.length >= 1).should_be_true
check_problem warnings.first
error_tester result = check_problem result.catch
Problems.test_advanced_problem_handling action error_tester warnings_tester tester
check_column_type_error_handling (t.filter "X" (Filter_Condition.Starts_With (t.at "ix")) on_problems=_)
check_column_type_error_handling (t.filter "X" (Filter_Condition.Ends_With (t.at "ix")) on_problems=_)
check_column_type_error_handling (t.filter "X" (Filter_Condition.Contains (t.at "ix")) on_problems=_)
Expand Down Expand Up @@ -1170,9 +1176,15 @@ spec prefix table_builder test_selection pending=Nothing =
t.filter "b" Filter_Condition.Is_False on_problems=Report_Error . at "ix" . to_vector . should_equal [2]

tester = check_empty ["ix", "b"]
problems = [Invalid_Value_Type.Invalid_Value_Type_Data Value_Type.Boolean Value_Type.Integer]
Problems.test_problem_handling (t.filter "ix" Filter_Condition.Is_True on_problems=_) problems tester
Problems.test_problem_handling (t.filter "ix" Filter_Condition.Is_False on_problems=_) problems tester
check_problem problem =
problem.should_be_a Invalid_Value_Type.Invalid_Value_Type_Data
problem.expected . should_equal Value_Type.Boolean
warnings_tester warnings =
(warnings.length >= 1).should_be_true
check_problem warnings.first
error_tester result = check_problem result.catch
Problems.test_advanced_problem_handling (t.filter "ix" Filter_Condition.Is_True on_problems=_) error_tester warnings_tester tester
Problems.test_advanced_problem_handling (t.filter "ix" Filter_Condition.Is_False on_problems=_) error_tester warnings_tester tester

Test.specify "by a custom expression built from table's columns" <|
t = table_builder [["ix", [1, 2, 3, 4, 5]], ["X", [10, 20, 13, 4, 5]], ["Y", [0, -100, 8, 2, 5]]]
Expand Down

0 comments on commit 1f610e4

Please sign in to comment.