Skip to content

Commit

Permalink
tests, better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Oct 14, 2024
1 parent 49bbb2b commit e8a2f42
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import project.Suite_Config.Suite_Config
import project.Test.Test
import project.Test_Result.Test_Result

polyglot java import java.lang.IllegalArgumentException
polyglot java import java.lang.StringBuilder
polyglot java import java.lang.System as Java_System

Expand Down Expand Up @@ -113,13 +114,16 @@ generate_github_error_annotation (title : Text) (message : Text) =
end = parts.at 1
start_field_name+"="+start+","+end_field_name+"="+end
on_location_failing_to_parse caught_panic =
Test_Result.log_message "Failed to parse file location ["+location_match.to_display_text+"]: "+caught_panic.to_display_text
Test_Result.log_message "Failed to parse file location ["+location_match.to_display_text+"]: "+caught_panic.payload.to_display_text
""
location_part = if location_match.is_nothing then "" else
Panic.catch Any handler=on_location_failing_to_parse <|
repo_root = enso_project.root.parent.parent.absolute.normalize
path = File.new (location_match.get 1)
relative_path = repo_root.relativize path
## We try to relativize the path, but if it fails, we just use the original path.
(It may fail eg. if the project root and the test files are on different drives -
very unlikely but not impossible if tests import other libraries located in weird places.)
relative_path = Panic.catch IllegalArgumentException (repo_root.relativize path) _->path
lines_part = split_on_dash "line" "endLine" (location_match.get 2)
columns_part = split_on_dash "col" "endColumn" (location_match.get 3)
",file="+(sanitize_parameter relative_path.path)+","+lines_part+","+columns_part
Expand Down
35 changes: 35 additions & 0 deletions test/Base_Internal_Tests/src/Github_Annotations_Spec.enso
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from Standard.Base import all

from Standard.Test import all
import Standard.Test.Test_Reporter

# While we're lacking the ability to run the documentation examples
# automatically (#1706), these tests at least check that each of the examples
# executes without an error resulting.

add_specs suite_builder = suite_builder.group "Test Reporter running on GitHub" group_builder->
file = (enso_project.root / "src" / "test-file.enso") . absolute . normalize
file_relative_to_repo_root = (File.new "test") / "Base_Internal_Tests" / "src" / "test-file.enso"
group_builder.specify "should correctly parse error message" <|
message = "[False, False, False, True] did not equal [False, False, True, True]; first difference at index 2 (at "+file.path+":1:13-110)."
line = Test_Reporter.generate_github_error_annotation 'Test, and\n special characters' message
line.should_equal "::error title=Test%2C and%0A special characters,file="+file_relative_to_repo_root.path+",line=1,col=13,endColumn=110::[False, False, False, True] did not equal [False, False, True, True]; first difference at index 2 (at "+file.path+":1:13-110)."

group_builder.specify "should be able to parse dashes" <|
message = "test failure (at "+file.path+":1-2:3-4)."
line = Test_Reporter.generate_github_error_annotation "Test" message
line.should_equal "::error title=Test,file="+file_relative_to_repo_root.path+",line=1,endLine=2,col=3,endColumn=4::test failure (at "+file.path+":1-2:3-4)."

message2 = "test failure (at "+file.path+":1234-5678:91011-121314)."
line2 = Test_Reporter.generate_github_error_annotation "Test" message2
line2.should_equal "::error title=Test,file="+file_relative_to_repo_root.path+",line=1234,endLine=5678,col=91011,endColumn=121314::test failure (at "+file.path+":1234-5678:91011-121314)."

group_builder.specify "should be able to parse no dashes" <|
message = "test failure (at "+file.path+":1234:7)."
line = Test_Reporter.generate_github_error_annotation "Test" message
line.should_equal "::error title=Test,file="+file_relative_to_repo_root.path+",line=1234,col=7::test failure (at "+file.path+":1234:7)."

main filter=Nothing =
suite = Test.build suite_builder->
add_specs suite_builder
suite.run_with_filter filter
2 changes: 2 additions & 0 deletions test/Base_Internal_Tests/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import project.Input_Output_Spec
import project.Comparator_Spec
import project.Decimal_Constructor_Spec
import project.Grapheme_Spec
import project.Github_Annotations_Spec

main filter=Nothing =
suite = Test.build suite_builder->
Comparator_Spec.add_specs suite_builder
Decimal_Constructor_Spec.add_specs suite_builder
Grapheme_Spec.add_specs suite_builder
Input_Output_Spec.add_specs suite_builder
Github_Annotations_Spec.add_specs suite_builder

suite.run_with_filter filter

0 comments on commit e8a2f42

Please sign in to comment.