-
Notifications
You must be signed in to change notification settings - Fork 603
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
Conditional Compilation Fixes. #302
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// OHHTTPStubsProject.xcconfig | ||
// OHHTTPStubs | ||
// | ||
// Created by Jeff Lett on 3/7/19. | ||
// Copyright © 2019 AliSoftware. All rights reserved. | ||
// | ||
|
||
// Configuration settings file format documentation can be found at: | ||
// https://help.apple.com/xcode/#/dev745c5c974 | ||
|
||
// These build settings are used to disable specific unit tests. | ||
// They can and should be overridden when running tests in CI using an xcodebuild argument. | ||
|
||
|
||
// xcodebuild Example: | ||
// xcodebuild -workspace OHHTTPStubs/OHHTTPStubs.xcworkspace -scheme "OHHTTPStubs iOS StaticLib" -sdk iphonesimulator -configuration Debug ONLY_ACTIVE_ARCH=NO OHHTTPSTUBS_SKIP_TIMING_TESTS=1 -destination 'name=iPhone 7,OS=latest' clean build test | ||
// | ||
// rake Example: | ||
// rake ios['iOS StaticLib','latest','build-for-testing test-without-building',"OHHTTPSTUBS_SKIP_TIMING_TESTS=1"] | ||
OHHTTPSTUBS_SKIP_TIMING_TESTS=0 | ||
|
||
// xcodebuild Example: | ||
// xcodebuild -workspace OHHTTPStubs/OHHTTPStubs.xcworkspace -scheme "OHHTTPStubs iOS StaticLib" -sdk iphonesimulator -configuration Debug ONLY_ACTIVE_ARCH=NO OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1 -destination 'name=iPhone 7,OS=latest' clean build test | ||
// | ||
// rake Example: | ||
// rake ios['iOS StaticLib','latest','build-for-testing test-without-building',"OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1"] | ||
OHHTTPSTUBS_SKIP_REDIRECT_TESTS=0 | ||
|
||
GCC_PREPROCESSOR_DEFINITIONS=OHHTTPSTUBS_SKIP_TIMING_TESTS=$(OHHTTPSTUBS_SKIP_TIMING_TESTS) OHHTTPSTUBS_SKIP_REDIRECT_TESTS=$(OHHTTPSTUBS_SKIP_REDIRECT_TESTS) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure that really matters in practice in our case but shouldn't we used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm honestly not sure how, but the config file looks like it's value resolves to have I thought build settings always inherited from right to left in Xcode's levels view (^^ that view).. so I wouldn't expect the config file to inherit a setting from the project, but it does. 🤷♂️ Now that I think more about it - I normally don't mix project build settings and also have an xcconfig with them. My opinion is normally that if you have an xcconfig you should put the entire value of that setting into the xcconfig instead of the project's build settings. @AliSoftware - What do you think of moving There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Strange that it magically inherit project settings indeed 🧐 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, probably overkill. So do you think we should add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -294,65 +294,69 @@ - (void)test_NSURLSessionDefaultConfig_notFollowingRedirects | |
Verify that redirects of different methods and status codes are handled properly and | ||
that we retain the HTTP Method for specific HTTP status codes as well as the data payload. | ||
**/ | ||
//- (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect | ||
//{ | ||
// if ([NSURLSessionConfiguration class] && [NSURLSession class]) | ||
// { | ||
// NSDictionary* json = @{ @"query": @"Hello World" }; | ||
// NSArray<NSString*>* allMethods = @[@"GET", @"HEAD", @"POST", @"PATCH", @"PUT"]; | ||
// | ||
// /** 301, 302, 307, 308: GET, HEAD, POST, PATCH, PUT should all maintain HTTP method and body unchanged **/ | ||
// for (NSNumber* redirectStatusCode in @[@301, @302, @307, @308]) { | ||
// int statusCode = redirectStatusCode.intValue; | ||
// for (NSString* method in allMethods) { | ||
// | ||
// NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; | ||
// NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil]; | ||
// NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil]; | ||
// | ||
// [self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:statusCode | ||
// completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse) | ||
// { | ||
// XCTAssertEqualObjects(redirectedRequestMethod, method, | ||
// @"Expected the HTTP method to be unchanged after %d redirect", statusCode); | ||
// XCTAssertEqualObjects(redirectedRequestJSONBody, json, | ||
// @"Expected %d-redirected request to have the same body as the original request", statusCode); | ||
// XCTAssertNil(redirectHTTPResponse, | ||
// @"%d Redirect response should not have been captured by the task completion block", statusCode); | ||
// XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, | ||
// @"Unexpected JSON response received after %d redirect", statusCode); | ||
// XCTAssertNil(errorResponse, @"Unexpected error during %d redirect", statusCode); | ||
// }]; | ||
// | ||
// [session finishTasksAndInvalidate]; | ||
// } | ||
// } | ||
// | ||
// /** 303: GET, HEAD, POST, PATCH, PUT should use a GET HTTP method after redirection and not forward the body **/ | ||
// for (NSString* method in allMethods) { | ||
// | ||
// NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; | ||
// NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil]; | ||
// NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil]; | ||
// | ||
// [self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:303 | ||
// completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse) | ||
// { | ||
// XCTAssertEqualObjects(redirectedRequestMethod, @"GET", @"Expected 303 redirected request HTTP method to be reset to GET"); | ||
// XCTAssertNil(redirectedRequestJSONBody, @"Expected 303-redirected request to have empty body"); | ||
// XCTAssertNil(redirectHTTPResponse, @"303 Redirect response should not have been captured by the task completion block"); | ||
// XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, @"Unexpected JSON response received after 303 redirect"); | ||
// XCTAssertNil(errorResponse, @"Unexpected error during 303 redirect"); | ||
// }]; | ||
// | ||
// [session finishTasksAndInvalidate]; | ||
// } | ||
// } | ||
// else | ||
// { | ||
// NSLog(@"/!\\ Test skipped because the NSURLSession class is not available on this OS version. Run the tests a target with a more recent OS.\n"); | ||
// } | ||
//} | ||
#if OHHTTPSTUBS_SKIP_REDIRECT_TESTS | ||
#warning Redirect Tests will be skipped for this run. | ||
#else | ||
- (void)test_NSURLSessionDefaultConfig_MethodAndDataRetentionOnRedirect | ||
{ | ||
if ([NSURLSessionConfiguration class] && [NSURLSession class]) | ||
{ | ||
NSDictionary* json = @{ @"query": @"Hello World" }; | ||
NSArray<NSString*>* allMethods = @[@"GET", @"HEAD", @"POST", @"PATCH", @"PUT"]; | ||
|
||
/** 301, 302, 307, 308: GET, HEAD, POST, PATCH, PUT should all maintain HTTP method and body unchanged **/ | ||
for (NSNumber* redirectStatusCode in @[@301, @302, @307, @308]) { | ||
int statusCode = redirectStatusCode.intValue; | ||
for (NSString* method in allMethods) { | ||
|
||
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; | ||
NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil]; | ||
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil]; | ||
|
||
[self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:statusCode | ||
completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse) | ||
{ | ||
XCTAssertEqualObjects(redirectedRequestMethod, method, | ||
@"Expected the HTTP method to be unchanged after %d redirect", statusCode); | ||
XCTAssertEqualObjects(redirectedRequestJSONBody, json, | ||
@"Expected %d-redirected request to have the same body as the original request", statusCode); | ||
XCTAssertNil(redirectHTTPResponse, | ||
@"%d Redirect response should not have been captured by the task completion block", statusCode); | ||
XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, | ||
@"Unexpected JSON response received after %d redirect", statusCode); | ||
XCTAssertNil(errorResponse, @"Unexpected error during %d redirect", statusCode); | ||
}]; | ||
|
||
[session finishTasksAndInvalidate]; | ||
} | ||
} | ||
|
||
/** 303: GET, HEAD, POST, PATCH, PUT should use a GET HTTP method after redirection and not forward the body **/ | ||
for (NSString* method in allMethods) { | ||
|
||
NSURLSessionConfiguration* config = [NSURLSessionConfiguration defaultSessionConfiguration]; | ||
NSURLSessionTestDelegate* delegate = [NSURLSessionTestDelegate delegateFollowingRedirects:YES fulfillOnCompletion:nil]; | ||
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:delegate delegateQueue:nil]; | ||
|
||
[self _test_redirect_NSURLSession:session httpMethod:method jsonBody:json delays:0.0 redirectStatusCode:303 | ||
completion:^(NSString *redirectedRequestMethod, id redirectedRequestJSONBody, NSHTTPURLResponse *redirectHTTPResponse, id finalJSONResponse, NSError *errorResponse) | ||
{ | ||
XCTAssertEqualObjects(redirectedRequestMethod, @"GET", @"Expected 303 redirected request HTTP method to be reset to GET"); | ||
XCTAssertNil(redirectedRequestJSONBody, @"Expected 303-redirected request to have empty body"); | ||
XCTAssertNil(redirectHTTPResponse, @"303 Redirect response should not have been captured by the task completion block"); | ||
XCTAssertEqualObjects(finalJSONResponse, @{ @"RequestBody": json }, @"Unexpected JSON response received after 303 redirect"); | ||
XCTAssertNil(errorResponse, @"Unexpected error during 303 redirect"); | ||
}]; | ||
|
||
[session finishTasksAndInvalidate]; | ||
} | ||
} | ||
else | ||
{ | ||
NSLog(@"/!\\ Test skipped because the NSURLSession class is not available on this OS version. Run the tests a target with a more recent OS.\n"); | ||
} | ||
} | ||
#endif | ||
- (void)test_NSURLSessionEphemeralConfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (Just because I like nitpicking: this feels a bit packed, so if you have the occasion of a new commit in this PR, adding an extra empty line to separate the endif and the next function while you're at it might help us breathe 😅) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 6bb7397 . |
||
{ | ||
if ([NSURLSessionConfiguration class] && [NSURLSession class]) | ||
|
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.
I'm happy surprised that the space character added in there doesn't break anything btw 😅 I guess I properly remembered in the CI config file to use quotes around
"$RAKETASK"
when incoming take, pfew 😄