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

Expand Test Execution Coverage #979

Merged
merged 8 commits into from
Jul 12, 2018
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
- TEST_TYPE=installation_cocoapods_frameworks
- TEST_TYPE=lint
- TEST_TYPE=tests
- TEST_TYPE=builds
- TEST_TYPE=analyzer
- TEST_TYPE=documentation

Expand All @@ -28,6 +29,7 @@ script:
- "./ci_scripts/check_resource_bundle.rb"
- '[ "$TEST_TYPE" != lint ] || ./ci_scripts/check_fauxpas.sh'
- '[ "$TEST_TYPE" != tests ] || travis_retry ./ci_scripts/run_tests.sh'
- '[ "$TEST_TYPE" != builds ] || travis_retry ./ci_scripts/run_builds.sh'
- '[ "$TEST_TYPE" != analyzer ] || ./ci_scripts/run_analyzer.sh'
- '[ "$TEST_TYPE" != installation_cocoapods_objc ] || ./Tests/installation_tests/cocoapods/without_frameworks_objc/test.sh'
- '[ "$TEST_TYPE" != installation_cocoapods_frameworks_objc ] || ./Tests/installation_tests/cocoapods/with_frameworks_objc/test.sh'
Expand Down
43 changes: 23 additions & 20 deletions Tests/Tests/STPColorUtilsTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,26 +104,24 @@ - (void)testAllColorSpaces {
};

CFStringRef colorSpaceNames[] = {
kCGColorSpaceSRGB,
kCGColorSpaceDCIP3,
kCGColorSpaceROMMRGB,
kCGColorSpaceITUR_709,
kCGColorSpaceDisplayP3,
kCGColorSpaceITUR_2020,
kCGColorSpaceGenericRGB,
kCGColorSpaceGenericXYZ,
kCGColorSpaceLinearGray,
kCGColorSpaceLinearSRGB,
kCGColorSpaceGenericCMYK,
kCGColorSpaceGenericGray,
kCGColorSpaceACESCGLinear,
kCGColorSpaceAdobeRGB1998,
kCGColorSpaceExtendedGray,
kCGColorSpaceExtendedSRGB,
kCGColorSpaceGenericRGBLinear,
kCGColorSpaceExtendedLinearGray,
kCGColorSpaceExtendedLinearSRGB,
kCGColorSpaceGenericGrayGamma2_2,
kCGColorSpaceSRGB,
kCGColorSpaceDCIP3,
kCGColorSpaceROMMRGB,
kCGColorSpaceITUR_709,
kCGColorSpaceDisplayP3,
kCGColorSpaceITUR_2020,
kCGColorSpaceGenericRGB,
kCGColorSpaceGenericXYZ,
kCGColorSpaceLinearSRGB,
kCGColorSpaceGenericCMYK,
kCGColorSpaceGenericGray,
kCGColorSpaceACESCGLinear,
kCGColorSpaceAdobeRGB1998,
kCGColorSpaceExtendedGray,
kCGColorSpaceExtendedSRGB,
kCGColorSpaceGenericRGBLinear,
kCGColorSpaceExtendedLinearSRGB,
kCGColorSpaceGenericGrayGamma2_2,
};

int colorSpaceCount = sizeof(colorSpaceNames) / sizeof(colorSpaceNames[0]);
Expand All @@ -132,6 +130,11 @@ - (void)testAllColorSpaces {
testColorSpace(colorSpaceNames[i], colorSpaceNames[i] != kCGColorSpaceGenericCMYK);
}

if (@available(iOS 10.0, *)) {
testColorSpace(kCGColorSpaceLinearGray, YES);
testColorSpace(kCGColorSpaceExtendedLinearGray, YES);
}

if (@available(iOS 11.0, *)) {
// in LAB all 1's is dark
testColorSpace(kCGColorSpaceGenericLab, NO);
Expand Down
34 changes: 25 additions & 9 deletions Tests/Tests/STPRedirectContextTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -458,19 +458,29 @@ - (void)testNativeRedirectSupportingSourceFlow_validNativeURL {

id applicationMock = OCMClassMock([UIApplication class]);
OCMStub([applicationMock sharedApplication]).andReturn(applicationMock);
OCMStub([applicationMock openURL:[OCMArg any]
options:[OCMArg any]
completionHandler:([OCMArg invokeBlockWithArgs:@YES, nil])]);
if (@available(iOS 10, *)) {
OCMStub([applicationMock openURL:[OCMArg any]
options:[OCMArg any]
completionHandler:([OCMArg invokeBlockWithArgs:@YES, nil])]);
}
else {
OCMStub([applicationMock openURL:[OCMArg any]]).andReturn(YES);
}

OCMReject([sut startSafariViewControllerRedirectFlowFromViewController:[OCMArg any]]);
OCMReject([sut startSafariAppRedirectFlow]);

id mockVC = OCMClassMock([UIViewController class]);
[sut startRedirectFlowFromViewController:mockVC];

OCMVerify([applicationMock openURL:[OCMArg isEqual:sourceURL]
options:[OCMArg isEqual:@{}]
completionHandler:[OCMArg isNotNil]]);
if (@available(iOS 10, *)) {
OCMVerify([applicationMock openURL:[OCMArg isEqual:sourceURL]
options:[OCMArg isEqual:@{}]
completionHandler:[OCMArg isNotNil]]);
}
else {
OCMVerify([applicationMock openURL:[OCMArg isEqual:sourceURL]]);
}

[sut unsubscribeFromNotifications];
}
Expand All @@ -491,9 +501,15 @@ - (void)testNativeRedirectSupportingSourceFlow_invalidNativeURL {
id applicationMock = OCMClassMock([UIApplication class]);
OCMStub([applicationMock sharedApplication]).andReturn(applicationMock);

OCMReject([applicationMock openURL:[OCMArg any]
options:[OCMArg any]
completionHandler:[OCMArg any]]);
if (@available(iOS 10, *)) {
OCMReject([applicationMock openURL:[OCMArg any]
options:[OCMArg any]
completionHandler:[OCMArg any]]);
}
else {
OCMReject([applicationMock openURL:[OCMArg any]]);
}


id mockVC = OCMClassMock([UIViewController class]);
[sut startRedirectFlowFromViewController:mockVC];
Expand Down
63 changes: 63 additions & 0 deletions ci_scripts/run_builds.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

function info {
echo "[$(basename "${0}")] [INFO] ${1}"
}

function die {
echo "[$(basename "${0}")] [ERROR] ${1}"
exit 1
}

# Verify xcpretty is installed
if ! command -v xcpretty > /dev/null; then
if [[ "${CI}" != "true" ]]; then
die "Please install xcpretty: https://github.com/supermarin/xcpretty#installation"
fi

info "Installing xcpretty..."
gem install xcpretty --no-ri --no-rdoc || die "Executing \`gem install xcpretty\` failed"
fi

# Install sample app dependencies
info "Installing sample app dependencies..."

cd "Example" || die "Executing \`cd\` failed"
carthage bootstrap --platform iOS
carthage_exit_code="$?"
cd .. || die "Executing \`cd\` failed"

if [[ "${carthage_exit_code}" != 0 ]]; then
die "Executing carthage failed with status code: ${carthage_exit_code}"
fi

# Execute sample app builds (iPhone 6, iOS 11.x)
info "Executing sample app builds (iPhone 6, iOS 11.x)..."

xcodebuild build \
-workspace "Stripe.xcworkspace" \
-scheme "Standard Integration (Swift)" \
-sdk "iphonesimulator" \
-destination "platform=iOS Simulator,name=iPhone 6,OS=11.2" \
| xcpretty
Copy link
Contributor

Choose a reason for hiding this comment

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

Was it intentional to drop the -c flag that colorizes the output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, to me, the default behavior seems to works so why bother specifying it:

screen shot 2018-07-09 at 3 05 30 pm


exit_code="${PIPESTATUS[0]}"

if [[ "${exit_code}" != 0 ]]; then
die "xcodebuild exited with non-zero status code: ${exit_code}"
fi

xcodebuild build \
-workspace "Stripe.xcworkspace" \
-scheme "Custom Integration (ObjC)" \
-sdk "iphonesimulator" \
-destination "platform=iOS Simulator,name=iPhone 6,OS=11.2" \
| xcpretty

exit_code="${PIPESTATUS[0]}"

if [[ "${exit_code}" != 0 ]]; then
die "xcodebuild exited with non-zero status code: ${exit_code}"
fi

info "All good!"
83 changes: 75 additions & 8 deletions ci_scripts/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,77 @@
set -euf -o pipefail
#!/bin/bash

carthage bootstrap --platform ios --configuration Release --no-use-binaries
cd Example; carthage bootstrap --platform ios; cd ..
function info {
echo "[$(basename "${0}")] [INFO] ${1}"
}

gem install xcpretty --no-ri --no-rdoc
xcodebuild clean build build-for-testing -workspace Stripe.xcworkspace -scheme "StripeiOS" -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.2' | xcpretty -c
xcodebuild test-without-building -workspace Stripe.xcworkspace -scheme "StripeiOS" -configuration Debug -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.2' | xcpretty -c
xcodebuild build -workspace Stripe.xcworkspace -scheme "Standard Integration (Swift)" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.2' | xcpretty -c
xcodebuild build -workspace Stripe.xcworkspace -scheme "Custom Integration (ObjC)" -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.2' | xcpretty -c
function die {
echo "[$(basename "${0}")] [ERROR] ${1}"
exit 1
}

# Verify xcpretty is installed
if ! command -v xcpretty > /dev/null; then
if [[ "${CI}" != "true" ]]; then
die "Please install xcpretty: https://github.com/supermarin/xcpretty#installation"
fi

info "Installing xcpretty..."
gem install xcpretty --no-ri --no-rdoc || die "Executing \`gem install xcpretty\` failed"
fi

# Install test dependencies
info "Installing test dependencies..."

carthage bootstrap --platform iOS --configuration Release --no-use-binaries
carthage_exit_code="$?"

if [[ "${carthage_exit_code}" != 0 ]]; then
die "Executing carthage failed with status code: ${carthage_exit_code}"
fi

# Execute tests (iPhone 6 @ iOS 11.2)
info "Executing tests (iPhone 6 @ iOS 11.2)..."

xcodebuild clean test \
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you combine the build & test steps? They were intentionally separated last year: eb8009a

I know I've run into this problem in the past (and have the radar to prove it), but I don't know if it's still an issue in Xcode 9.

Copy link
Contributor Author

@joeydong-stripe joeydong-stripe Jul 9, 2018

Choose a reason for hiding this comment

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

i combined it to reduce code duplication, and it seems to work? i think if we need it again in the future, we should leave the reasoning as a comment in the code because a bum like me is going to miss the commit blame.

-workspace "Stripe.xcworkspace" \
-scheme "StripeiOS" \
-configuration "Debug" \
-sdk "iphonesimulator" \
-destination "platform=iOS Simulator,name=iPhone 6,OS=11.2" \
| xcpretty

exit_code="${PIPESTATUS[0]}"

if [[ "${exit_code}" != 0 ]]; then
die "xcodebuild exited with non-zero status code: ${exit_code}"
fi

# Execute tests on legacy devices (iPhone 6 @ iOS 10.x, iPhone 6 @ iOS 9.x, iPhone 4s @ iOS 9.x)
# - Skips snapshot tests because they're recorded for the iPhone 6 on the newest iOS version only
# - Not sure why tests STPImageLibraryTest fail on older iOS versions
# - Set `ONLY_ACTIVE_ARCH=NO` to build both 32-bit and 64-bit products
info "Executing tests on legacy devices (iPhone 6 @ iOS 10.x, iPhone 6 @ iOS 9.x, iPhone 4s @ iOS 9.x)..."

xcodebuild clean test \
-workspace "Stripe.xcworkspace" \
-scheme "StripeiOS" \
-configuration "Debug" \
-sdk "iphonesimulator" \
-destination "platform=iOS Simulator,name=iPhone 6,OS=10.3.1" \
-destination "platform=iOS Simulator,name=iPhone 6,OS=9.3" \
-destination "platform=iOS Simulator,name=iPhone 4s,OS=9.3" \
-skip-testing:"StripeiOS Tests/STPAddCardViewControllerLocalizationTests" \
-skip-testing:"StripeiOS Tests/STPPaymentMethodsViewControllerLocalizationTests" \
-skip-testing:"StripeiOS Tests/STPShippingAddressViewControllerLocalizationTests" \
-skip-testing:"StripeiOS Tests/STPShippingMethodsViewControllerLocalizationTests" \
-skip-testing:"StripeiOS Tests/STPImageLibraryTest" \
ONLY_ACTIVE_ARCH=NO \
| xcpretty

exit_code="${PIPESTATUS[0]}"

if [[ "${exit_code}" != 0 ]]; then
die "xcodebuild exited with non-zero status code: ${exit_code}"
fi

info "All good!"