Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix trainer failure result handling with objective C tests #21990

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions trainer/lib/trainer/test_parser.rb
Expand Up @@ -267,19 +267,17 @@ def summaries_to_data(summaries, failures, output_remove_retry_attempts: false)
end
info[:retry_count] = retry_count

# Set failure message if failure found
failure = test.find_failure(failures)
if failure
case test.test_status
when "Failure"
test_row[:failures] = [{
file_name: "",
line_number: 0,
message: "",
performance_failure: {},
failure_message: failure.failure_message
failure_message: test.failure_message(failures)
}]

info[:failure_count] += 1
elsif test.test_status == "Skipped"
when "Skipped"
test_row[:skipped] = true
info[:skip_count] += 1
else
Expand Down
41 changes: 19 additions & 22 deletions trainer/lib/trainer/xcresult.rb
Expand Up @@ -172,29 +172,11 @@ def all_subtests
return [self]
end

def find_failure(failures)
sanitizer = proc { |name| name.gsub(/\W/, "_") }
sanitized_identifier = sanitizer.call(self.identifier)
if self.test_status == "Failure"
# Tries to match failure on test case name
# Example TestFailureIssueSummary:
# producingTarget: "TestThisDude"
# test_case_name: "TestThisDude.testFailureJosh2()" (when Swift)
# or "-[TestThisDudeTests testFailureJosh2]" (when Objective-C)
# Example ActionTestMetadata
# identifier: "TestThisDude/testFailureJosh2()" (when Swift)
# or identifier: "TestThisDude/testFailureJosh2" (when Objective-C)

found_failure = failures.find do |failure|
# Sanitize both test case name and identifier in a consistent fashion, then replace all non-word
# chars with underscore, and compare them
sanitized_test_case_name = sanitizer.call(failure.test_case_name)
sanitized_identifier == sanitized_test_case_name
end
return found_failure
else
return nil
def failure_message(failures)
found = failures.find do |failure|
self.identifier == failure.normalized_name
end
return found ? found.failure_message : "unknown failure message"
end
end

Expand Down Expand Up @@ -385,6 +367,21 @@ def initialize(data)
super
end

def normalized_name
# Return test_case_name normalized to match the identifier from ActionTestMetadata
# Example TestFailureIssueSummary:
# producingTarget: "TestThisDude"
# test_case_name: "TestThisDude.testFailureJosh2()" (when Swift)
# or "-[TestThisDudeTests testFailureJosh2]" (when Objective-C)
# Example ActionTestMetadata
# identifier: "TestThisDude/testFailureJosh2()" (when Swift)
# or identifier: "TestThisDude/testFailureJosh2" (when Objective-C)
if self.test_case_name.start_with?("-[") && self.test_case_name.end_with?("]")
return self.test_case_name[2...-1].tr(" ", "/")
end
return self.test_case_name.tr(".", "/")
end

def failure_message
new_message = self.message
if self.document_location_in_creating_workspace&.url
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
29 changes: 29 additions & 0 deletions trainer/spec/fixtures/Test.objc.xcresult/Info.plist
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>dateCreated</key>
<date>2024-04-23T23:38:03Z</date>
<key>externalLocations</key>
<array/>
<key>rootId</key>
<dict>
<key>hash</key>
<string>0~QcTkA55UPcxEP1nO1AY1osK3wJ6ccJbYiM6K7BJmWZ0MFG5UOgWiKPIxZQdQeP-BtGoBEwiEcoYSkz_QqfjjMA==</string>
</dict>
<key>storage</key>
<dict>
<key>backend</key>
<string>fileBacked2</string>
<key>compression</key>
<string>standard</string>
</dict>
<key>version</key>
<dict>
<key>major</key>
<integer>3</integer>
<key>minor</key>
<integer>39</integer>
</dict>
</dict>
</plist>
47 changes: 47 additions & 0 deletions trainer/spec/test_parser_spec.rb
Expand Up @@ -245,6 +245,53 @@
}
])
end

it "works as expected with Objective C xcresult", requires_xcode: true do
tp = Trainer::TestParser.new("./trainer/spec/fixtures/Test.objc.xcresult")
expect(tp.data).to eq([
{
project_path: "HelloWorldTest.xcodeproj",
target_name: "HelloWorldTestTests",
test_name: "HelloWorldTestTests",
configuration_name: "Test Scheme Action",
duration: 0.04512190818786621,
tests: [
{
identifier: "HelloWorldTestTests.testExample",
name: "testExample",
duration: 0.0011409521102905273,
status: "Success",
test_group: "HelloWorldTestTests",
guid: "",
},
{
identifier: "HelloWorldTestTests.testFailure",
name: "testFailure",
duration: 0.043980956077575684,
status: "Failure",
test_group: "HelloWorldTestTests",
guid: "",
failures: [
{
failure_message: "((NO) is true) failed - Fail (/Users/jsoffian/HelloWorldTest/HelloWorldTestTests/HelloWorldTestTests.m#CharacterRangeLen=0&EndingLineNumber=39&StartingLineNumber=39)",
file_name: "",
line_number: 0,
message: "",
performance_failure: {}
}
]
}
],
number_of_tests: 2,
number_of_failures: 1,
number_of_skipped: 0,
number_of_tests_excluding_retries: 2,
number_of_failures_excluding_retries: 1,
number_of_retries: 0
}
])
end

end
end
end