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

Conversation

jeffctown
Copy link
Collaborator

@jeffctown jeffctown commented Mar 7, 2019

Uncommenting buggy redirect tests.
Adding xcconfig to put project settings into.
Adding preprocessor macros to let unit test arguments through.
Adding default value of preprocessor macros to default them to run conditional tests when using Xcode.
Adding comments for xcconfig.
Updating Rake arguments.

Checklist

  • I've checked that all new and existing tests pass
  • I've updated the documentation if necessary
  • I've added an entry in the CHANGELOG to credit myself

Description

My original goal was to add a previously commented unit test back to the test suite, and to enable it when testing in Xcode but disable it when testing in CI. During this investigation, I also noticed that the Timing Tests were not working in this way like they were originally intended to. I ended up fixing those tests in this PR too.

Motivation and Context

Timing Tests -

If you look at previous test runs, you see that timing tests were being run in Travis:

screen shot 2019-03-07 at 7 03 59 am

Even though the right Xcode argument was being passed:

screen shot 2019-03-07 at 7 04 15 am

This seems like a bug with the project setup.

I found that we needed to add a preprocessor macro to the project's build settings to let the xcodebuild argument through.

I always like using xcconfig files to manage build settings, so I created a project level xcconfig with the build settings and commented the config. Build settings that are defined in xcconfig files can always be overridden by passing in xcodebuild arguments.

Redirect Tests -

I followed the same pattern with the uncommented redirect tests.

End Result -

You can see here that both sets of tests are run when using Xcode:

screen shot 2019-03-07 at 9 11 00 am

And that neither are ran during CI:

screen shot 2019-03-07 at 9 22 17 am

Uncommenting buggy redirect tests.
Adding xcconfig to put project settings into.
Adding preprocessor macros to let unit test arguments through.
Adding default value of preprocessor macros to default them to run conditional tests when using Xcode.
Adding comments for xcconfig.
Updating Rake arguments.
// 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)
Copy link
Owner

Choose a reason for hiding this comment

The 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 $(inherited) in that definition? (I think the default in Xcode is GCC_PREPROCESSOR_DEFINITIONS=DEBUG=1 in debug — while it's empty in release — so not using $(inherited) here means that debug builds don't have DEBUG=1 set anymore? Not that we currently use #if DEBUG in OHHTTPStubs as far as I know but just for configuration consistency…

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.

I'm honestly not sure how, but the config file looks like it's value resolves to have DEBUG=1, even though it's in the project build settings and not in the file.

screen shot 2019-03-07 at 7 39 47 pm

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 DEBUG=1 to the xcconfig instead, so there is no project build setting for this one?

Copy link
Owner

Choose a reason for hiding this comment

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

Strange that it magically inherit project settings indeed 🧐
Moving DEBUG=1 in the xcconfig file makes sense, but would require two separate xcconfig files then (one for each config), just wondering if that's worth it 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, probably overkill. So do you think we should add $(inherit) or leave it as is?

Copy link
Owner

Choose a reason for hiding this comment

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

Let's try $(inherited) at least for consistency, and validate it still works as expected (eg doesn't double-define DEBUG=1 in the resolved build settings after all)

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.

There were actually a few places where we had DEBUG=1 twice, so I removed the target level preprocessor macros where needed.

Here are the resulting resolved preprocessor macros now:
screen shot 2019-03-08 at 9 12 12 am

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 .

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.

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.

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.

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.

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.

- 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 😄

@AliSoftware
Copy link
Owner

Man it's so refreshing to see CI turn green on the PR without having to restart every CI job manually and pray until it passes 😄🎉

@AliSoftware AliSoftware merged commit 1f029e3 into master Mar 8, 2019
@jeffctown jeffctown deleted the feature/ConditionalCompilationOfUnitTests branch March 8, 2019 18:18
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.

2 participants