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

[trainer] fix issues where number of failures would always be zero #21432

Merged
merged 6 commits into from
Jan 10, 2024
Merged
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
16 changes: 6 additions & 10 deletions trainer/lib/trainer/xcresult.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ def all_subtests
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:
Expand All @@ -184,16 +186,10 @@ def find_failure(failures)
# or identifier: "TestThisDude/testFailureJosh2" (when Objective-C)

found_failure = failures.find do |failure|
# Clean test_case_name to match identifier format
# Sanitize for Swift by replacing "." for "/"
# Sanitize for Objective-C by removing "-", "[", "]", and replacing " " for ?/
sanitized_test_case_name = failure.test_case_name
.tr(".", "/")
.tr("-", "")
.tr("[", "")
.tr("]", "")
.tr(" ", "/")
self.identifier == sanitized_test_case_name
# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is a regression. See #21432 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix #21990

end
return found_failure
else
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"testmanagerd.log","type":1}]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"name":"SpaceTestsTests-537E3596-221E-4A31-9389-071C5541B922","type":2},{"name":"scheduling.log","type":1}]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.with_spaces.xcresult/Info.plist
Original file line number Diff line number Diff line change
@@ -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>2023-07-31T19:01:10Z</date>
<key>externalLocations</key>
<array/>
<key>rootId</key>
<dict>
<key>hash</key>
<string>0~SsRyiCHDfQl2m19SwdRuZY_vhc88s24Xb6jgs7SXLFpWpNV6sGPwMav-Pin-3_-rheMqlGi_0gxrcwMBrUii1w==</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>
38 changes: 38 additions & 0 deletions trainer/spec/test_parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,44 @@
expect(failure_messages).to eq(["XCTAssertTrue failed", "XCTAssertTrue failed"])
RSpec::Mocks.space.proxy_for(Trainer::XCResult::TestFailureIssueSummary).reset
end

it "works as expected with xcresult with spaces", requires_xcode: true do
tp = Trainer::TestParser.new("./trainer/spec/fixtures/Test.with_spaces.xcresult")
expect(tp.data).to eq([
{
project_path: "SpaceTests.xcodeproj",
target_name: "SpaceTestsTests",
test_name: "SpaceTestsTests",
configuration_name: "Test Scheme Action",
duration: 0.21180307865142822,
tests: [
{
identifier: "SpaceTestsSpec.a test with spaces, should always fail()",
name: "a test with spaces, should always fail()",
duration: 0.21180307865142822,
status: "Failure",
test_group: "SpaceTestsSpec",
guid: "",
failures: [
{
failure_message: "expected to equal <1>, got <2>\n (/Users/mahmood.tahir/Developer/SpaceTests/SpaceTestsTests/TestSpec.swift#CharacterRangeLen=0&EndingLineNumber=15&StartingLineNumber=15)",
file_name: "",
line_number: 0,
message: "",
performance_failure: {}
}
]
}
],
number_of_tests: 1,
number_of_failures: 1,
number_of_skipped: 0,
number_of_tests_excluding_retries: 1,
number_of_failures_excluding_retries: 1,
number_of_retries: 0
}
])
end
end
end
end