Skip to content

Commit

Permalink
Upgrading the code to a more Swift 3-like API (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
plivesey authored Oct 3, 2016
1 parent 9ac2fa3 commit 38dbc8d
Show file tree
Hide file tree
Showing 22 changed files with 217 additions and 135 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0
9 changes: 5 additions & 4 deletions LayoutTest.podspec
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
Pod::Spec.new do |spec|
spec.name = 'LayoutTest'
spec.version = '1.3.0'
spec.version = '2.0.0'
spec.license = { :type => 'Apache License, Version 2.0' }
spec.homepage = 'https://linkedin.github.io/LayoutTest-iOS'
spec.authors = 'LinkedIn'
spec.summary = 'LayoutTest enables you to write unit tests which test the layout of a view in multiple configurations.'
spec.source = { :git => 'https://github.com/linkedin/LayoutTest-iOS.git', :tag => '1.3.0' }
spec.source = { :git => 'https://github.com/linkedin/LayoutTest-iOS.git', :tag => spec.version }
spec.platform = :ios, '7.0'
spec.default_subspecs = 'TestCase'
spec.dependency 'LayoutTestBase', '1.3.0'
spec.dependency 'LayoutTestBase', '2.0.0'

spec.subspec 'Swift' do |sp|
sp.dependency 'LayoutTestBase/Core'
Expand All @@ -32,7 +32,8 @@ Pod::Spec.new do |spec|
spec.subspec 'SwiftSubspec' do |sp|
sp.source_files = 'LayoutTest/Swift'
sp.dependency 'LayoutTest/TestCase'
sp.dependency 'LayoutTest/ModuleHeader'
sp.dependency 'LayoutTest/ModuleHeader'
sp.dependency 'LayoutTestBase/Swift'
end

spec.subspec 'ModuleHeader' do |sp|
Expand Down
22 changes: 18 additions & 4 deletions LayoutTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
61ADE1E81C0CA81600585946 /* LayoutTestCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61ADE1C41C0CA81600585946 /* LayoutTestCase.swift */; };
61ADE2491C0CAFE900585946 /* LYTLayoutTestCase.h in Headers */ = {isa = PBXBuildFile; fileRef = 61ADE2341C0CAFE900585946 /* LYTLayoutTestCase.h */; settings = {ATTRIBUTES = (Public, ); }; };
61ADE24A1C0CAFE900585946 /* LYTLayoutTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 61ADE2351C0CAFE900585946 /* LYTLayoutTestCase.m */; };
61BCF9E31D930B010034F8BA /* DeviceConstants.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61BCF9E21D930B010034F8BA /* DeviceConstants.swift */; };
61CACFAD1C1A4F7300369461 /* LYTViewSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 61CACFA91C1A4F7300369461 /* LYTViewSize.h */; settings = {ATTRIBUTES = (Public, ); }; };
61CACFAE1C1A4F7300369461 /* LYTViewSize.m in Sources */ = {isa = PBXBuildFile; fileRef = 61CACFAA1C1A4F7300369461 /* LYTViewSize.m */; };
61CACFAF1C1A4F7300369461 /* UIView+LYTViewSize.h in Headers */ = {isa = PBXBuildFile; fileRef = 61CACFAB1C1A4F7300369461 /* UIView+LYTViewSize.h */; settings = {ATTRIBUTES = (Public, ); }; };
Expand All @@ -77,6 +76,8 @@
61CACFB41C1A4FF500369461 /* LYTDeviceConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61CACFB21C1A4FF500369461 /* LYTDeviceConstants.m */; };
61CACFB61C1A560000369461 /* LayoutTestCaseViewSizesTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 61CACFB51C1A560000369461 /* LayoutTestCaseViewSizesTests.m */; };
61CACFB81C1A592000369461 /* LayoutTestCaseViewSizesConfigTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 61CACFB71C1A592000369461 /* LayoutTestCaseViewSizesConfigTests.m */; };
61DDA8DD1D9EF2D80066FF64 /* LYTDataValues+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61DDA8DB1D9EF2D80066FF64 /* LYTDataValues+Swift.swift */; };
61DDA8DE1D9EF2D80066FF64 /* LYTViewSize+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 61DDA8DC1D9EF2D80066FF64 /* LYTViewSize+Swift.swift */; };
C56317F11C6373FE00A8E8BA /* LayoutTestCaseMultipleDataOverlapTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C56317F01C6373FE00A8E8BA /* LayoutTestCaseMultipleDataOverlapTests.m */; };
C56317F41C63746C00A8E8BA /* UIViewWithLabel.m in Sources */ = {isa = PBXBuildFile; fileRef = C56317F31C63746C00A8E8BA /* UIViewWithLabel.m */; };
C59A16451C6A2C20002AC07C /* LayoutReportSnapshotLocationsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = C59A16441C6A2C20002AC07C /* LayoutReportSnapshotLocationsTests.m */; };
Expand Down Expand Up @@ -170,7 +171,6 @@
61ADE1C41C0CA81600585946 /* LayoutTestCase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LayoutTestCase.swift; sourceTree = "<group>"; };
61ADE2341C0CAFE900585946 /* LYTLayoutTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LYTLayoutTestCase.h; sourceTree = "<group>"; };
61ADE2351C0CAFE900585946 /* LYTLayoutTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LYTLayoutTestCase.m; sourceTree = "<group>"; };
61BCF9E21D930B010034F8BA /* DeviceConstants.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DeviceConstants.swift; sourceTree = "<group>"; };
61CACFA91C1A4F7300369461 /* LYTViewSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LYTViewSize.h; sourceTree = "<group>"; };
61CACFAA1C1A4F7300369461 /* LYTViewSize.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LYTViewSize.m; sourceTree = "<group>"; };
61CACFAB1C1A4F7300369461 /* UIView+LYTViewSize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIView+LYTViewSize.h"; sourceTree = "<group>"; };
Expand All @@ -179,6 +179,8 @@
61CACFB21C1A4FF500369461 /* LYTDeviceConstants.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LYTDeviceConstants.m; sourceTree = "<group>"; };
61CACFB51C1A560000369461 /* LayoutTestCaseViewSizesTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LayoutTestCaseViewSizesTests.m; sourceTree = "<group>"; };
61CACFB71C1A592000369461 /* LayoutTestCaseViewSizesConfigTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LayoutTestCaseViewSizesConfigTests.m; sourceTree = "<group>"; };
61DDA8DB1D9EF2D80066FF64 /* LYTDataValues+Swift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "LYTDataValues+Swift.swift"; sourceTree = "<group>"; };
61DDA8DC1D9EF2D80066FF64 /* LYTViewSize+Swift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "LYTViewSize+Swift.swift"; sourceTree = "<group>"; };
C56317F01C6373FE00A8E8BA /* LayoutTestCaseMultipleDataOverlapTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LayoutTestCaseMultipleDataOverlapTests.m; sourceTree = "<group>"; };
C56317F21C63746C00A8E8BA /* UIViewWithLabel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIViewWithLabel.h; sourceTree = "<group>"; };
C56317F31C63746C00A8E8BA /* UIViewWithLabel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIViewWithLabel.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -315,6 +317,7 @@
61A3061F1C125A6F00CB3FEC /* Catalog */,
61A306251C125A6F00CB3FEC /* Config */,
61A306281C125A6F00CB3FEC /* Core */,
61DDA8DA1D9EF2D80066FF64 /* Swift */,
61A3063F1C125A6F00CB3FEC /* UIViewHelpers */,
61A306161C125A1C00CB3FEC /* Info.plist */,
);
Expand Down Expand Up @@ -426,7 +429,6 @@
isa = PBXGroup;
children = (
61ADE1C41C0CA81600585946 /* LayoutTestCase.swift */,
61BCF9E21D930B010034F8BA /* DeviceConstants.swift */,
);
path = Swift;
sourceTree = "<group>";
Expand Down Expand Up @@ -455,6 +457,15 @@
path = ViewSizing;
sourceTree = "<group>";
};
61DDA8DA1D9EF2D80066FF64 /* Swift */ = {
isa = PBXGroup;
children = (
61DDA8DB1D9EF2D80066FF64 /* LYTDataValues+Swift.swift */,
61DDA8DC1D9EF2D80066FF64 /* LYTViewSize+Swift.swift */,
);
path = Swift;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -630,7 +641,6 @@
files = (
61ADE24A1C0CAFE900585946 /* LYTLayoutTestCase.m in Sources */,
5667F66C1C65FCE50042C3BB /* LYTLayoutFailingTestSnapshotRecorder.m in Sources */,
61BCF9E31D930B010034F8BA /* DeviceConstants.swift in Sources */,
61ADE1E81C0CA81600585946 /* LayoutTestCase.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -670,6 +680,7 @@
buildActionMask = 2147483647;
files = (
61A3065C1C125A6F00CB3FEC /* LYTMutableCopier.m in Sources */,
61DDA8DE1D9EF2D80066FF64 /* LYTViewSize+Swift.swift in Sources */,
61CACFAE1C1A4F7300369461 /* LYTViewSize.m in Sources */,
61CACFB01C1A4F7300369461 /* UIView+LYTViewSize.m in Sources */,
61A306581C125A6F00CB3FEC /* LYTDataValues.m in Sources */,
Expand All @@ -687,6 +698,7 @@
61A306471C125A6F00CB3FEC /* LYTAutolayoutFailureIntercepter.m in Sources */,
61A3065A1C125A6F00CB3FEC /* LYTValuesIterator.m in Sources */,
61CACFB41C1A4FF500369461 /* LYTDeviceConstants.m in Sources */,
61DDA8DD1D9EF2D80066FF64 /* LYTDataValues+Swift.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -924,6 +936,7 @@
PRODUCT_BUNDLE_IDENTIFIER = LinkedIn.LayoutTestBase;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -957,6 +970,7 @@
PRODUCT_BUNDLE_IDENTIFIER = LinkedIn.LayoutTestBase;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OBJC_BRIDGING_HEADER = "";
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2";
VERSIONING_SYSTEM = "apple-generic";
Expand Down
31 changes: 0 additions & 31 deletions LayoutTest/Swift/DeviceConstants.swift

This file was deleted.

28 changes: 14 additions & 14 deletions LayoutTest/Swift/LayoutTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ open class LayoutTestCase: LYTLayoutTestCase {
validation(view, data, context)
} else {
self.failTest("The view wasn't of the expected type. Change your method signature to declare the view in the validation closure " +
"of the correct type. Expected: \(TestableView.self) Actual: \(type(of: (view) as AnyObject))", view: view as? UIView)
"of the correct type. Expected: \(TestableView.self) Actual: \(type(of: (view) as AnyObject))", view: view)
}
}
}
Expand All @@ -71,24 +71,24 @@ open class LayoutTestCase: LYTLayoutTestCase {
- Tests that that no sibling subviews are overlapping.
- Tests that that no subview is out of the bounds of its parent view.
- Tests that that autolayout is not ambiguous.
- Tests that autolayout doesn't throw any errors.
- Performs some accessibility sanity checks.
- Verifies that all UIControl elements have an accessibilityLabel.
- Verifies that no accessibility elements are nested (otherwise they aren't available to accessibility users).
- Verifies that all views with accessibility identifiers have accessibility labels. If a view has an identifier and does not have a label, voice over
- Tests that autolayout doesn't throw any errors.
- Performs some accessibility sanity checks.
- Verifies that all UIControl elements have an accessibilityLabel.
- Verifies that no accessibility elements are nested (otherwise they aren't available to accessibility users).
- Verifies that all views with accessibility identifiers have accessibility labels. If a view has an identifier and does not have a label, voice over
will read out the identifier to the user.

All of these automatic tests can be turned off using the properties in LYTLayoutTestCase or globally with LYTConfig.
All of these automatic tests can be turned off using the properties in LYTLayoutTestCase or globally with LYTConfig.

- Parameter viewProvider: Class to test. Must conform to LYTViewProvider.
- Parameter limitResults: Use this parameter to run less combinations. This is useful if you're running into performance problems. See
- Parameter viewProvider: Class to test. Must conform to LYTViewProvider.
- Parameter limitResults: Use this parameter to run less combinations. This is useful if you're running into performance problems. See
LYTTesterLimitResults docs for more info.
- Parameter validation: (view, data, context) Block to validate the view given the data. The data here will not contain any LYTDataValues subclasses.
- Parameter validation: (view, data, context) Block to validate the view given the data. The data here will not contain any LYTDataValues subclasses.
Here you should assert on the properties of the view. If you set a context in your viewForData: method, it will be passed back here.
*/
open func runLayoutTestsWithViewProvider<TestableView: UIView, ViewProvider: LYTViewProvider>(_ viewProvider: ViewProvider.Type,
limitResults: LYTTesterLimitResults = LYTTesterLimitResults(),
validation: (TestableView, [AnyHashable: Any], Any?) -> Void) {
*/
open func runLayoutTests<TestableView: UIView, ViewProvider: LYTViewProvider>(withViewProvider viewProvider: ViewProvider.Type,
limitResults: LYTTesterLimitResults = LYTTesterLimitResults(),
validation: (TestableView, [AnyHashable: Any], Any?) -> Void) {
self.runLayoutTests(withViewProvider: viewProvider, limitResults: limitResults) { (view: Any, data, context) in
if let view = view as? TestableView {
validation(view, data, context)
Expand Down
4 changes: 1 addition & 3 deletions LayoutTest/TestCase/LYTLayoutFailingTestSnapshotRecorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,7 @@ - (UIImage *)renderLayer:(CALayer *)layer {
CGContextRef context = UIGraphicsGetCurrentContext();

CGContextSaveGState(context);
{
[layer renderInContext:context];
}
[layer renderInContext:context];
CGContextRestoreGState(context);

snapshot = UIGraphicsGetImageFromCurrentImageContext();
Expand Down
23 changes: 21 additions & 2 deletions LayoutTestBase.podspec
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
Pod::Spec.new do |spec|
spec.name = 'LayoutTestBase'
spec.version = '1.3.0'
spec.version = '2.0.0'
spec.license = { :type => 'Apache License, Version 2.0' }
spec.homepage = 'https://linkedin.github.io/LayoutTest-iOS'
spec.authors = 'LinkedIn'
spec.summary = 'Base library for LayoutTest without XCTest dependency. LayoutTest enables you to write unit tests which test the layout of views.'
spec.source = { :git => 'https://github.com/linkedin/LayoutTest-iOS.git', :tag => '1.3.0' }
spec.source = { :git => 'https://github.com/linkedin/LayoutTest-iOS.git', :tag => '2.0.0' }
spec.platform = :ios, '7.0'
spec.frameworks = 'Foundation', 'UIKit'
spec.default_subspecs = 'Core', 'Autolayout', 'Catalog', 'Config', 'UIViewHelpers'

spec.subspec 'Swift' do |sp|
sp.dependency 'LayoutTestBase/Core'
sp.dependency 'LayoutTestBase/Autolayout'
sp.dependency 'LayoutTestBase/Catalog'
sp.dependency 'LayoutTestBase/Config'
sp.dependency 'LayoutTestBase/UIViewHelpers'
sp.dependency 'LayoutTestBase/SwiftSubspec'
end

spec.subspec 'SwiftSubspec' do |sp|
sp.source_files = 'LayoutTestBase/Swift/**/*'
sp.dependency 'LayoutTestBase/Core'
sp.dependency 'LayoutTestBase/ModuleHeader'
end

spec.subspec 'Core' do |sp|
sp.source_files = 'LayoutTestBase/Core/**/*'
sp.dependency 'LayoutTestBase/Config'
Expand All @@ -32,4 +47,8 @@ Pod::Spec.new do |spec|
sp.source_files = 'LayoutTestBase/UIViewHelpers'
sp.dependency 'LayoutTestBase/Config'
end

spec.subspec 'ModuleHeader' do |sp|
sp.source_files = 'LayoutTestBase/LayoutTestBase.h'
end
end
1 change: 0 additions & 1 deletion LayoutTestBase/Config/LYTConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ NS_ASSUME_NONNULL_BEGIN
/**
Default snapshots to save per method.
*/

extern NSUInteger const LYTSaveUnlimitedSnapshotsPerMethod;

/**
Expand Down
8 changes: 4 additions & 4 deletions LayoutTestBase/Core/Generators/LYTDataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ NS_ASSUME_NONNULL_BEGIN
/**
Returns LYTDataValues with all values.
*/
- (id)init;
- (instancetype)init;

/**
Returns LYTDataValues with all values except nil. Use this for required fields.
*/
- (id)initWithRequired:(BOOL)required;
- (instancetype)initWithRequired:(BOOL)required;

/**
Returns LYTDataValues with these specific values and overrides any subclass's behavior.
*/
- (id)initWithValues:(NSArray *)values;
- (instancetype)initWithValues:(NSArray *)values NS_REFINED_FOR_SWIFT;

/**
Returns LYTDataValues with all the values that return true from the filter block.
*/
- (id)initWithFilter:(BOOL(^ _Nullable)(id value))filter;
- (instancetype)initWithFilter:(BOOL(^ _Nullable)(id value))filter;

/**
Returns the number of values this object contains.
Expand Down
10 changes: 5 additions & 5 deletions LayoutTestBase/Core/ViewSizing/LYTViewSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ NS_ASSUME_NONNULL_BEGIN
/**
The width for the view. If nil, do not edit the width.
*/
@property (nonatomic, strong, readonly, nullable) NSNumber *width;
@property (nonatomic, strong, readonly, nullable) NSNumber *width NS_REFINED_FOR_SWIFT;
/**
The height for the view. If nil, do not edit the height.
*/
@property (nonatomic, strong, readonly, nullable) NSNumber *height;
@property (nonatomic, strong, readonly, nullable) NSNumber *height NS_REFINED_FOR_SWIFT;

/**
Creates a view size which will change both the width and the height of the view.
*/
- (instancetype)initWithWidth:(nullable NSNumber *)width height:(nullable NSNumber *)height;
- (instancetype)initWithWidth:(nullable NSNumber *)width height:(nullable NSNumber *)height NS_REFINED_FOR_SWIFT;

/**
Creates a view size which will only change the width of the view.
*/
- (instancetype)initWithWidth:(NSNumber *)width;
- (instancetype)initWithWidth:(NSNumber *)width NS_SWIFT_UNAVAILABLE("init(width:height:) takes optional arguments instead");

/**
Creates a view size which will only change the height of the view.
*/

- (instancetype)initWithHeight:(NSNumber *)height;
- (instancetype)initWithHeight:(NSNumber *)height NS_SWIFT_UNAVAILABLE("init(width:height:) takes optional arguments instead");

@end

Expand Down
2 changes: 1 addition & 1 deletion LayoutTestBase/Core/ViewSizing/UIView+LYTViewSize.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface UIView (LYTViewSize)

- (void)lyt_setSize:(nullable LYTViewSize *)size;
- (void)lyt_setSize:(nullable LYTViewSize *)size NS_SWIFT_NAME(setSize(_:));

@end

Expand Down
4 changes: 4 additions & 0 deletions LayoutTestBase/LayoutTestBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

/**
This file is included in cocoapods because without it, XCode refuses to build the project. It shouldn't cause any harm.
*/

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

Expand Down
Loading

0 comments on commit 38dbc8d

Please sign in to comment.