Skip to content

[test] fix for hasPrefix and hasSuffix test #629

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

Merged
merged 2 commits into from
Aug 24, 2016

Conversation

glessard
Copy link
Contributor

The previous version wrongly cached a result, which in turn masked a bug in the bridged hasSuffix().
(reported as https://bugs.swift.org/browse/SR-243)

This version also trips hasPrefix, but that involves \u{0}; the correct behaviour there is less obvious.

@glessard
Copy link
Contributor Author

This bug fix surfaces two cases that always failed, but were masked.
They are now both annotated with xfail and links to bug reports.

@glessard glessard force-pushed the NSStringAPI-testfix branch from db795fd to 2d569b2 Compare January 24, 2016 23:18
@glessard glessard force-pushed the NSStringAPI-testfix branch 2 times, most recently from 221edf6 to e98c705 Compare February 5, 2016 19:59
@glessard
Copy link
Contributor Author

glessard commented Feb 5, 2016

Rebased after the changes in #1131

@glessard glessard changed the title NSStringAPI: test fix for hasPrefix and hasSuffix [test] fix for hasPrefix and hasSuffix test Feb 5, 2016
@glessard glessard force-pushed the NSStringAPI-testfix branch from e98c705 to b04f46e Compare March 18, 2016 05:26
@tkremenek
Copy link
Member

@swift-ci test

@tkremenek
Copy link
Member

@gribozavr please review

@glessard
Copy link
Contributor Author

@tkremenek The swift-ci failure was unrelated to these changes; test again?

@jrose-apple
Copy link
Contributor

Drive-by test restarting:

@swift-ci Please test OS X platform

@jckarter
Copy link
Contributor

@gribozavr This ok to merge?

@gribozavr
Copy link
Contributor

@glessard Sorry, I don't understand what this patch changes -- it looks like a pure refactoring to me. I see that you are removing the xfail predicates from the test list, but you're adding them back with the map() function. Why is this making a difference? I'm probably missing something, I would be glad if you could explain to me.

@glessard
Copy link
Contributor Author

glessard commented Apr 16, 2016

(edited)
The bug fix is in the first commit, the rest is dealing with the consequences of it (and of #1131, since they have distinct sets of xfails).

In the original version of 'checkHasPrefixHasSuffix', a pair of expected results is calculated, and then are used twice each. This wasn't correct. In particular, if the first character of s is combining, s.hasSuffix(s) is true, but ("abc"+s).hasSuffix(s) is false. However, the test as originally written expected both answers to be the same (see b6bc624#diff-f7824440e4e317d38fc0554573876bccL256). The original test passed the ("\u{0301}", "\u{0341}") case because of a bug in NSString/CFString (https://bugs.swift.org/browse/SR-243). Without that NSString bug, the original formulation of the test wouldn't have passed.

The fix simply ensures the expected result is recalculated for every single use, by moving the extra suffix and prefix tests to a separate call of checkHasPrefixHasSuffix. (I stumbled upon this while porting the tests for #440)

@glessard glessard force-pushed the NSStringAPI-testfix branch 2 times, most recently from dd8a3e8 to b7f6099 Compare April 20, 2016 21:51
@glessard
Copy link
Contributor Author

@gribozavr Did the above response clarify the patch?

@glessard glessard force-pushed the NSStringAPI-testfix branch from b7f6099 to 69cd0c1 Compare August 11, 2016 19:33
@glessard glessard force-pushed the NSStringAPI-testfix branch from 69cd0c1 to 2e26155 Compare August 24, 2016 00:33
}

let comparisonTests = [
let tests = [
Copy link
Contributor

@CodaFi CodaFi Aug 24, 2016

Choose a reason for hiding this comment

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

It doesn't seem like anything else in the file is using tests. Why not just fold the results of the map into the array itself?

Copy link
Contributor Author

@glessard glessard Aug 24, 2016

Choose a reason for hiding this comment

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

The tests for comparisons and substrings (prefix and suffix) don't overlap cleanly, so I separated them. The array is also mapped in the commit that follows this one (line 281).

Copy link
Contributor

Choose a reason for hiding this comment

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

There definitely needs to be a little bit of documentation on both of the maps and on the special cases of the literal here explaining just that. It's hard to see where and why things XFail without it.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 24, 2016

@swift-ci please smoke test.

_ expectedUnicodeCollation: ExpectedComparisonResult,
lhs: String, rhs: String,
xfail: TestRunPredicate, loc: SourceLoc
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that this is just a change to a default argument, this initializer isn't needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed.

@glessard glessard force-pushed the NSStringAPI-testfix branch from 2e26155 to 5e0e39c Compare August 24, 2016 15:16
@CodaFi
Copy link
Contributor

CodaFi commented Aug 24, 2016

I think I'm out of nitpicks if this was pure refactoring. Thank you @glessard.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 24, 2016

Once you've added a bit of docs, please squash this down to a patch or two.

The expected value should be recalculated for every combination of inputs. It was previously cached and used twice; it appeared to work because of SR-243.
… indicator symbol.

Expected failures when testing comparisons and substrings are not the same; separating them allows better coverage.
@glessard glessard force-pushed the NSStringAPI-testfix branch from 5e0e39c to 5a41eaa Compare August 24, 2016 17:09
@glessard
Copy link
Contributor Author

@CodaFi I think this should do it; thanks for the feedback

@CodaFi
Copy link
Contributor

CodaFi commented Aug 24, 2016

@swift-ci please smoke test.

@CodaFi
Copy link
Contributor

CodaFi commented Aug 24, 2016

macOS
Linux

// @shahmishal

@shahmishal
Copy link
Member

This issue looks like:
janinko/ghprb#150
janinko/ghprb#284

going to retrigger the build to see if it picks up the new sha.

@swift-ci Please smoke test

@CodaFi
Copy link
Contributor

CodaFi commented Aug 24, 2016

I think we're good to go here. Merging.

@CodaFi CodaFi merged commit e2de394 into swiftlang:master Aug 24, 2016
@jrose-apple
Copy link
Contributor

Ah, @gribozavr, did you have any remaining comments?

@gribozavr
Copy link
Contributor

LGTM, thanks!

@glessard glessard deleted the NSStringAPI-testfix branch August 24, 2016 21:39
kateinoigakukun added a commit to kateinoigakukun/swift that referenced this pull request Apr 16, 2020
freak4pc pushed a commit to freak4pc/swift that referenced this pull request Sep 28, 2022
[XFail] Xfailed projects failing on linux.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants