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
NSRange: fix init from region RangeExpression in target String #1894
NSRange: fix init from region RangeExpression in target String #1894
Conversation
Prior to Swift 5, String uses UTF-16 for its Index and encodedOffset. However, this assumption is no longer valid and encodedOffset might be in UTF-8 for native contents in Swift 5. This change should make the initializer work as expected under either circumstances.
@swift-ci test |
I don't think there's any existing test for this. I'll write some now. |
Can we port the code from https://github.com/apple/swift/blob/master/stdlib/public/Darwin/Foundation/NSRange.swift instead? |
@ianpartridge sure. Thanks for pointing it out! |
@swift-ci test |
Looks like tests passed but no status reported? https://ci.swift.org/job/swift-corelibs-foundation-PR-Linux/1903/ |
You're really going to want to stay up to date with the overlays in swift. |
Can you add a LIT test that makes sure they don't diff at the very least? |
Sorry for my inexperience, but could you please explain where I could write the lit test? @milseman Just my assumption, but I should add a file here?: https://github.com/apple/swift/blob/master/test/stdlib/NSRange.swift |
I don't know the testing or build set up for corelibs-foundation, but there could be many approaches. Is a checkout of the swift source code required to build/test corelibs-foundation? If so, then as a build step corelibs-foundation could copy these overlay files over, that way they are always in sync. If the build system is not configurable, but corelibs-foundation supports LIT-stye unit tests, then we can at least diff the files and error if there is any difference, similar to how the ABI checker works. If corelibs-foundation testing is constrained to XCTest only, we should still be able to diff the files, but I don't know XCTest very well. @ianpartridge or @parkera might know more. |
|
We don't use |
TestFoundation/TestNSRange.swift
Outdated
@@ -126,4 +128,52 @@ class TestNSRange : XCTestCase { | |||
XCTAssertEqual(NSStringFromRange(range), string) | |||
} | |||
} | |||
|
|||
private func _assert<S: StringProtocol, R: RangeExpression>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we give this a more specific name to indicate that it is specialized for the below test?
And use more robust implementation
@parkera updated |
@swift-ci test |
@swift-ci please test |
you have to be courteous to robots. :) |
To add to the discussion here: I absolutely would love to unify the overlay and s-c-f code where it’s redundant, but it is really not in the cards for this 5.x cycle. |
Looks like the test has failed due to s-c-xctest:
from this code: // CHECK: Test Case 'ExpectationsTestCase.test_outerWaiterTimesOut_InnerWaitersAreInterrupted' started at \d+-\d+-\d+ \d+:\d+:\d+\.\d+
// CHECK: .*/Tests/Functional/Asynchronous/Expectations/main.swift:[[@LINE+22]]: error: ExpectationsTestCase.test_outerWaiterTimesOut_InnerWaitersAreInterrupted : Asynchronous wait failed - Exceeded timeout of 0.1 seconds, with unfulfilled expectations: outer
// CHECK: .*/Tests/Functional/Asynchronous/Expectations/main.swift:[[@LINE+11]]: error: ExpectationsTestCase.test_outerWaiterTimesOut_InnerWaitersAreInterrupted : Asynchronous waiter <XCTWaiter expectations: 'inner-1'> failed - Interrupted by timeout of containing waiter <XCTWaiter expectations: 'outer'>
// CHECK: .*/Tests/Functional/Asynchronous/Expectations/main.swift:[[@LINE+15]]: error: ExpectationsTestCase.test_outerWaiterTimesOut_InnerWaitersAreInterrupted : Asynchronous waiter <XCTWaiter expectations: 'inner-2'> failed - Interrupted by timeout of containing waiter <XCTWaiter expectations: 'outer'>
// CHECK: Test Case 'ExpectationsTestCase.test_outerWaiterTimesOut_InnerWaitersAreInterrupted' failed \(\d+\.\d+ seconds\)
func test_outerWaiterTimesOut_InnerWaitersAreInterrupted() { I'll look into what's causing this, but I'm confident that it has nothing to do with this pull request, since Build #1922 failed for the same reason |
@swift-ci test |
Is there a chance this is related to this bot failure on Ubuntu 18.04? It looks possibly range-in-string-related: https://ci.swift.org/job/oss-swift-incremental-RA-linux-ubuntu-18_04-long-test/1231/console
|
@jckarter your link and output segment seems to be unrelated, so I’ll address both:
|
Oops, sorry for pasting the wrong link. #1915 should address this, thanks! |
Sorry for brining this up again, but should this fix actually go into the swift-5.0-branch instead/also? |
Yes, please open a PR against that branch. |
Prior to Swift 5, String uses UTF-16 for its Index and encodedOffset. However, this assumption is no longer valid and encodedOffset might be in UTF-8 for native contents in Swift 5.
This change should make the initializer work as expected under either circumstances.