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

Conditional Compilation Fixes. #302

Merged
merged 3 commits into from
Mar 8, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ before_install:
matrix:
include:
- osx_image: xcode8.3
env: RAKETASK="ios[iOS Framework,latest,build test,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
env: RAKETASK="ios[iOS Framework,latest,build test,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]"
- osx_image: xcode8.3
env: RAKETASK="osx[Mac Framework,x86_64,build test,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
env: RAKETASK="osx[Mac Framework,x86_64,build test,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]"
Copy link
Owner

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 😄

- osx_image: xcode9.1
env: RAKETASK="ios[iOS StaticLib,latest,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
env: RAKETASK="ios[iOS StaticLib,latest,build-for-testing test-without-building,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]"
- osx_image: xcode9.1
env: RAKETASK="ios[iOS Framework,latest,build-for-testing test-without-building]"
env: RAKETASK="ios[iOS Framework,latest,build-for-testing test-without-building,OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]"
- osx_image: xcode9.1
env: RAKETASK="osx[Mac Framework,x86_64,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
env: RAKETASK="osx[Mac Framework,x86_64,build-for-testing test-without-building,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]"
- osx_image: xcode9.1
env: RAKETASK="tvos[tvOS Framework,latest,build-for-testing test-without-building,-DOHHTTPSTUBS_SKIP_TIMING_TESTS=1]"
env: RAKETASK="tvos[tvOS Framework,latest,build-for-testing test-without-building,OHHTTPSTUBS_SKIP_TIMING_TESTS=1 OHHTTPSTUBS_SKIP_REDIRECT_TESTS=1]"

script:
- rake "$RAKETASK"
Expand Down
10 changes: 5 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# OHHTTPStubs — CHANGELOG

## [Future release]
* Enabled application extension API only.
* Enabled application extension API only.
[@lightsprint09](https://github.com/lightsprint09)
* Disabled a flaky redirect test and adding the known issue with redirects to the README.
[@jeffctown](https://github.com/jeffctown)
[#301](https://github.com/AliSoftware/OHHTTPStubs/pull/301)

* Disabled a flaky redirect test and adding the known issue with redirects to the README.
[@jeffctown](https://github.com/jeffctown) [#301](https://github.com/AliSoftware/OHHTTPStubs/pull/301)
* Updating Conditional Unit Test Compilation.
[@jeffctown](https://github.com/jeffctown) [#302](https://github.com/AliSoftware/OHHTTPStubs/pull/302)

## [6.1.0](https://github.com/AliSoftware/OHHTTPStubs/releases/tag/6.1.0)

Expand Down
24 changes: 4 additions & 20 deletions OHHTTPStubs/OHHTTPStubs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
1D0F8E811B6E31B00049A7D2 /* MocktailFolder */ = {isa = PBXFileReference; lastKnownFileType = folder; path = MocktailFolder; sourceTree = "<group>"; };
1D6DB84E1B763B7A00FCF855 /* OHHTTPStubs+Mocktail.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "OHHTTPStubs+Mocktail.h"; sourceTree = "<group>"; };
1D6DB84F1B763B7A00FCF855 /* OHHTTPStubs+Mocktail.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "OHHTTPStubs+Mocktail.m"; sourceTree = "<group>"; };
1FE7BADB223157DB00FFF120 /* OHHTTPStubsProject.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = OHHTTPStubsProject.xcconfig; sourceTree = "<group>"; };
221C34A41B0CCF0600FCA8FF /* OHPathHelpersTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OHPathHelpersTests.m; sourceTree = "<group>"; };
221C34A61B0CCF9D00FCA8FF /* empty.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = empty.bundle; sourceTree = "<group>"; };
451243C1FC2A423646391951 /* Pods-TestingPods-OHHTTPStubs iOS Fmk Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-TestingPods-OHHTTPStubs iOS Fmk Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-TestingPods-OHHTTPStubs iOS Fmk Tests/Pods-TestingPods-OHHTTPStubs iOS Fmk Tests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -368,6 +369,7 @@
09110A3819805F4800D175E4 = {
isa = PBXGroup;
children = (
1FE7BADB223157DB00FFF120 /* OHHTTPStubsProject.xcconfig */,
09110A4619805F4800D175E4 /* OHHTTPStubs */,
095981C519806A7900807DBE /* Supporting Files */,
09110A5A19805F4800D175E4 /* UnitTests */,
Expand Down Expand Up @@ -1280,6 +1282,7 @@
/* Begin XCBuildConfiguration section */
09110A6219805F4800D175E4 /* Debug */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 1FE7BADB223157DB00FFF120 /* OHHTTPStubsProject.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -1336,6 +1339,7 @@
};
09110A6319805F4800D175E4 /* Release */ = {
isa = XCBuildConfiguration;
baseConfigurationReference = 1FE7BADB223157DB00FFF120 /* OHHTTPStubsProject.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
Expand Down Expand Up @@ -1463,10 +1467,6 @@
);
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "UnitTests/UnitTests-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These were added at the target level, and caused DEBUG=1 to end up in the resolved macros twice.

INFOPLIST_FILE = "UnitTests/UnitTests-Info.plist";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
OTHER_LDFLAGS = (
Expand Down Expand Up @@ -1519,10 +1519,6 @@
);
FRAMEWORK_VERSION = A;
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These were added at the target level, and caused DEBUG=1 to end up in the resolved macros twice.

INFOPLIST_FILE = "Supporting Files/OHHTTPStubs Mac-Info.plist";
INSTALL_PATH = "@rpath";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand Down Expand Up @@ -1572,10 +1568,6 @@
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = "UnitTests/UnitTests-Prefix.pch";
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These were added at the target level, and caused DEBUG=1 to end up in the resolved macros twice.

LD_RUNPATH_SEARCH_PATHS = "$inherited @executable_path/../Frameworks @loader_path/../Frameworks";
OTHER_LDFLAGS = (
"$(inherited)",
Expand Down Expand Up @@ -1623,10 +1615,6 @@
DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These were added at the target level, and caused DEBUG=1 to end up in the resolved macros twice.

INFOPLIST_FILE = "Supporting Files/OHHTTPStubs iOS-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand Down Expand Up @@ -1707,10 +1695,6 @@
DYLIB_CURRENT_VERSION = "$(CURRENT_PROJECT_VERSION)";
DYLIB_INSTALL_NAME_BASE = "@rpath";
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
"$(inherited)",
);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These were added at the target level, and caused DEBUG=1 to end up in the resolved macros twice.

INFOPLIST_FILE = "Supporting Files/OHHTTPStubs iOS-Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
Expand Down
30 changes: 30 additions & 0 deletions OHHTTPStubs/OHHTTPStubsProject.xcconfig
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=$(inherited) OHHTTPSTUBS_SKIP_TIMING_TESTS=$(OHHTTPSTUBS_SKIP_TIMING_TESTS) OHHTTPSTUBS_SKIP_REDIRECT_TESTS=$(OHHTTPSTUBS_SKIP_REDIRECT_TESTS)
123 changes: 64 additions & 59 deletions OHHTTPStubs/UnitTests/Test Suites/NSURLSessionTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,65 +294,70 @@ - (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
Copy link
Owner

Choose a reason for hiding this comment

The 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 😅)

Copy link
Collaborator Author

@jeffctown jeffctown Mar 8, 2019

Choose a reason for hiding this comment

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

Addressed in 6bb7397 .

{
if ([NSURLSessionConfiguration class] && [NSURLSession class])
Expand Down