Skip to content

Commit

Permalink
[trainer] fix issues where number of failures would always be zero (#…
Browse files Browse the repository at this point in the history
…21432)

* Sanitize both identifier and test case

* Add unit tests

* Replace String extension with individual rules with simpler `proc` regex.

* Add `.gitattributes` and represent .xcresult as binary.

* Revert "Add `.gitattributes` and represent .xcresult as binary."

This reverts commit 0281dc5.

---------

Co-authored-by: Roger Oba <rogerluan.oba@gmail.com>
  • Loading branch information
tahirmt and rogerluan committed Jan 10, 2024
1 parent ebd6daf commit dda4007
Show file tree
Hide file tree
Showing 33 changed files with 76 additions and 10 deletions.
16 changes: 6 additions & 10 deletions trainer/lib/trainer/xcresult.rb
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
end
return found_failure
else
Expand Down
@@ -0,0 +1 @@
[]
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
[{"name":"testmanagerd.log","type":1}]
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -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
@@ -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
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

0 comments on commit dda4007

Please sign in to comment.