Skip to content

Commit

Permalink
Enable and fix more warnings (#58)
Browse files Browse the repository at this point in the history
* Enable and fix more warnings

* Bump version and use int vs uint
  • Loading branch information
crleona authored Aug 22, 2019
1 parent 50e61d4 commit e44e868
Show file tree
Hide file tree
Showing 31 changed files with 347 additions and 243 deletions.
14 changes: 7 additions & 7 deletions LayoutTest.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'LayoutTest'
spec.version = '5.0.2'
spec.version = '5.0.3'
spec.license = { :type => 'Apache License, Version 2.0' }
spec.homepage = 'https://linkedin.github.io/LayoutTest-iOS'
spec.authors = 'LinkedIn'
Expand All @@ -16,18 +16,18 @@ Pod::Spec.new do |spec|

spec.subspec 'TestCase' do |sp|
sp.source_files = 'LayoutTest/TestCase'
sp.dependency 'LayoutTestBase/Autolayout', '5.0.2'
sp.dependency 'LayoutTestBase/Catalog', '5.0.2'
sp.dependency 'LayoutTestBase/Config', '5.0.2'
sp.dependency 'LayoutTestBase/Core', '5.0.2'
sp.dependency 'LayoutTestBase/UIViewHelpers', '5.0.2'
sp.dependency 'LayoutTestBase/Autolayout', '5.0.3'
sp.dependency 'LayoutTestBase/Catalog', '5.0.3'
sp.dependency 'LayoutTestBase/Config', '5.0.3'
sp.dependency 'LayoutTestBase/Core', '5.0.3'
sp.dependency 'LayoutTestBase/UIViewHelpers', '5.0.3'
sp.framework = 'XCTest'
end

spec.subspec 'SwiftSubspec' do |sp|
sp.source_files = 'LayoutTest/Swift', 'LayoutTest/LayoutTest.h'
sp.dependency 'LayoutTest/TestCase'
sp.dependency 'LayoutTestBase/Swift', '5.0.2'
sp.dependency 'LayoutTestBase/Swift', '5.0.3'
end
end

20 changes: 20 additions & 0 deletions LayoutTest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
Expand All @@ -849,14 +850,19 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_FLOAT_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -874,9 +880,13 @@
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_MISSING_PARENTHESES = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
ONLY_ACTIVE_ARCH = YES;
Expand All @@ -895,6 +905,7 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_UNDEFINED_BEHAVIOR_SANITIZER_NULLABILITY = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
Expand All @@ -903,14 +914,19 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_FLOAT_CONVERSION = YES;
CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES;
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand All @@ -921,9 +937,13 @@
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_MISSING_PARENTHESES = YES;
GCC_WARN_SHADOW = YES;
GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_LABEL = YES;
GCC_WARN_UNUSED_PARAMETER = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
OTHER_LDFLAGS = "-ObjC";
Expand Down
26 changes: 18 additions & 8 deletions LayoutTest/TestCase/LYTLayoutFailingTestSnapshotRecorder.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ void SimpleLog(NSString *format, ...) {
NSString *formattedString = [[NSString alloc] initWithFormat:format
arguments:args];
va_end(args);
[[NSFileHandle fileHandleWithStandardOutput] writeData:[formattedString dataUsingEncoding:NSNEXTSTEPStringEncoding]];

NSData *data = [formattedString dataUsingEncoding:NSNEXTSTEPStringEncoding];
if (data) {
[[NSFileHandle fileHandleWithStandardOutput] writeData:data];
}
}

@interface NSString (XMLEscape)
Expand Down Expand Up @@ -74,11 +78,11 @@ - (instancetype)init {
return self;
}

- (void)testSuiteWillStart:(XCTestSuite *)testSuite {
- (void)testSuiteWillStart:(__unused XCTestSuite *)testSuite {
self.failedTestsDuringTestSuite = 0;
}

- (void)testSuiteDidFinish:(XCTestSuite *)testSuite {
- (void)testSuiteDidFinish:(__unused XCTestSuite *)testSuite {
if (self.failedTestsDuringTestSuite > 0 && self.failingTestsSnapshotFolders.count > 0) {
SimpleLog(@"\nSnapshots of failing tests can be found in:\n");
for (NSString *path in self.failingTestsSnapshotFolders) {
Expand All @@ -88,7 +92,7 @@ - (void)testSuiteDidFinish:(XCTestSuite *)testSuite {
}
}

- (void)testBundleDidFinish:(NSBundle *)testBundle {
- (void)testBundleDidFinish:(__unused NSBundle *)testBundle {
// NOTE: For some reason, this never gets called
// See #28 on Github
if (self.failingTestsSnapshotFolders.count > 0) {
Expand All @@ -101,7 +105,7 @@ - (void)testBundleDidFinish:(NSBundle *)testBundle {
}
}

- (void)testCase:(XCTestCase *)testCase didFailWithDescription:(NSString *)description inFile:(nullable NSString *)filePath atLine:(NSUInteger)lineNumber {
- (void)testCase:(XCTestCase *)testCase didFailWithDescription:(__unused NSString *)description inFile:(nullable __unused NSString *)filePath atLine:(__unused NSUInteger)lineNumber {
if ([testCase isKindOfClass:[LYTLayoutTestCase class]]) {
NSString *pathForSnapshots = [self commonRootPathForInvocationClass:[testCase class]];
pathForSnapshots = [pathForSnapshots stringByAppendingString:@"/index.html"];
Expand Down Expand Up @@ -133,7 +137,7 @@ - (void)saveImageOfView:(UIView *)view withData:(NSDictionary *)data fromInvocat
- (BOOL)shouldSaveImageOfViewAtPath:(NSString *)imagePath withInvocation:(NSInvocation *)invocation {
if ([[NSFileManager defaultManager] fileExistsAtPath:imagePath]) {
return NO;
} else if ([LYTConfig sharedInstance].snapshotsToSavePerMethod != LYTSaveUnlimitedSnapshotsPerMethod &&
} else if ([LYTConfig sharedInstance].snapshotsToSavePerMethod >= 0 &&
[self numberOfImagesSavedForInvocation:invocation] >= [LYTConfig sharedInstance].snapshotsToSavePerMethod) {
return NO;
}
Expand Down Expand Up @@ -166,7 +170,10 @@ - (void)finishLog {
NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath:filePath];

[fileHandler seekToEndOfFile];
[fileHandler writeData:[footer dataUsingEncoding:NSUTF8StringEncoding]];
NSData *footerData = [footer dataUsingEncoding:NSUTF8StringEncoding];
if (footerData) {
[fileHandler writeData:footerData];
}
[fileHandler closeFile];
}

Expand Down Expand Up @@ -197,7 +204,10 @@ - (void)appendViewWithWidth:(CGFloat)width
NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath:filePath];

[fileHandler seekToEndOfFile];
[fileHandler writeData:[errorHTML dataUsingEncoding:NSUTF8StringEncoding]];
NSData *errorData = [errorHTML dataUsingEncoding:NSUTF8StringEncoding];
if (errorData) {
[fileHandler writeData:errorData];
}
[fileHandler closeFile];
}

Expand Down
11 changes: 6 additions & 5 deletions LayoutTest/TestCase/LYTLayoutTestCase.m
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ - (void)runAmbiguousLayoutTestsWithSubview:(UIView *)subview view:(UIView *)view

#pragma mark - Testing

- (void)failTest:(NSString *)errorMessage view:(nullable UIView *)view {
- (void)failTest:(NSString *)errorMessage view:(nullable __unused UIView *)view {
XCTFail(@"%@", errorMessage);
}

Expand Down Expand Up @@ -264,12 +264,13 @@ + (BOOL)class:(Class)aClass includedInSet:(NSSet *)set {
}

+ (nullable UIView *)firstSuperviewWithAccessibilityLabel:(UIView *)view {
if (view.superview == nil) {
UIView *superview = view.superview;
if (superview == nil) {
return nil;
} else if (view.superview.accessibilityLabel != nil) {
return view.superview;
} else if (superview.accessibilityLabel != nil) {
return superview;
} else {
return [self firstSuperviewWithAccessibilityLabel:view.superview];
return [self firstSuperviewWithAccessibilityLabel:superview];
}
}

Expand Down
2 changes: 1 addition & 1 deletion LayoutTestBase.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'LayoutTestBase'
spec.version = '5.0.2'
spec.version = '5.0.3'
spec.license = { :type => 'Apache License, Version 2.0' }
spec.homepage = 'https://linkedin.github.io/LayoutTest-iOS'
spec.authors = 'LinkedIn'
Expand Down
38 changes: 24 additions & 14 deletions LayoutTestBase/Catalog/LYTCatalogCollectionViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,39 +34,49 @@ - (instancetype)init {
- (void)viewDidLoad {
[super viewDidLoad];

[self.ViewProviderClass registerClassOnCollectionView:self.collectionView];
Class<LYTViewCatalogProvider> viewProviderClass = self.ViewProviderClass;
if (!viewProviderClass) {
NSAssert(NO, @"No ViewProviderClass set");
return;
}

[viewProviderClass registerClassOnCollectionView:self.collectionView];

NSMutableArray *dataArray = [NSMutableArray array];

LYTTesterLimitResults limitResults = LYTTesterLimitResultsNoSizes;
if ([(id)self.ViewProviderClass respondsToSelector:@selector(limitResultsForCatalogByAssumingDataValueIndependence)]) {
if ([self.ViewProviderClass limitResultsForCatalogByAssumingDataValueIndependence]) {
if ([viewProviderClass respondsToSelector:@selector(limitResultsForCatalogByAssumingDataValueIndependence)]) {
if ([viewProviderClass limitResultsForCatalogByAssumingDataValueIndependence]) {
limitResults &= LYTTesterLimitResultsLimitDataCombinations;
}
}
[LYTLayoutPropertyTester runPropertyTestsWithViewProvider:self.ViewProviderClass
limitResults:limitResults
validation:^(UIView *view, NSDictionary *data, id context) {
[dataArray addObject:data];
}];
[LYTLayoutPropertyTester runPropertyTestsWithViewProvider:viewProviderClass
limitResults:limitResults
validation:^(__unused UIView *view, NSDictionary *data, __unused id context) {
[dataArray addObject:data];
}];
self.dataArray = dataArray;
}

#pragma mark - Table view data source

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return [self.ViewProviderClass sizeForCollectionViewCellForCatalogFromData:self.dataArray[indexPath.row] viewWidth:self.view.frame.size.width];
- (CGSize)collectionView:(__unused UICollectionView *)collectionView
layout:(__unused UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
return [self.ViewProviderClass sizeForCollectionViewCellForCatalogFromData:self.dataArray[(NSUInteger)indexPath.row] viewWidth:self.view.frame.size.width];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.dataArray.count;
- (NSInteger)collectionView:(__unused UICollectionView *)collectionView
numberOfItemsInSection:(__unused NSInteger)section {
return (NSInteger)self.dataArray.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- (UICollectionViewCell *)collectionView:(__unused UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:[self.ViewProviderClass reuseIdentifier] forIndexPath:indexPath];

id context = nil;
cell = (UICollectionViewCell *)[self.ViewProviderClass viewForData:self.dataArray[indexPath.row] reuseView:cell size:nil context:&context];
cell = (UICollectionViewCell *)[self.ViewProviderClass viewForData:self.dataArray[(NSUInteger)indexPath.row] reuseView:cell size:nil context:&context];

return cell;
}
Expand Down
36 changes: 20 additions & 16 deletions LayoutTestBase/Catalog/LYTCatalogTableViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,49 @@ @implementation LYTCatalogTableViewController
- (void)viewDidLoad {
[super viewDidLoad];

Class<LYTViewCatalogProvider> viewProviderClass = self.ViewProviderClass;
if (!viewProviderClass) {
NSAssert(NO, @"No ViewProviderClass set");
return;
}

[self.ViewProviderClass registerClassOnTableView:self.tableView];

NSMutableArray *dataArray = [NSMutableArray array];

LYTTesterLimitResults limitResults = LYTTesterLimitResultsNoSizes;
if ([(id)self.ViewProviderClass respondsToSelector:@selector(limitResultsForCatalogByAssumingDataValueIndependence)]) {
if ([self.ViewProviderClass limitResultsForCatalogByAssumingDataValueIndependence]) {
if ([viewProviderClass respondsToSelector:@selector(limitResultsForCatalogByAssumingDataValueIndependence)]) {
if ([viewProviderClass limitResultsForCatalogByAssumingDataValueIndependence]) {
limitResults &= LYTTesterLimitResultsLimitDataCombinations;
}
}
[LYTLayoutPropertyTester runPropertyTestsWithViewProvider:self.ViewProviderClass
limitResults:limitResults
validation:^(UIView *view, NSDictionary *data, id context) {
[dataArray addObject:data];
}];
[LYTLayoutPropertyTester runPropertyTestsWithViewProvider:viewProviderClass
limitResults:limitResults
validation:^(__unused UIView *view, NSDictionary *data, __unused id context) {
[dataArray addObject:data];
}];
self.dataArray = dataArray;

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
}

#pragma mark - Table view data source

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [self.ViewProviderClass heightForTableViewCellForCatalogFromData:self.dataArray[indexPath.row]];
- (CGFloat)tableView:(__unused UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return [self.ViewProviderClass heightForTableViewCellForCatalogFromData:self.dataArray[(NSUInteger)indexPath.row]];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self.dataArray count];
- (NSInteger)tableView:(__unused UITableView *)tableView numberOfRowsInSection:(__unused NSInteger)section {
return (NSInteger)self.dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:[self.ViewProviderClass reuseIdentifier] forIndexPath:indexPath];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:[self.ViewProviderClass reuseIdentifier] forIndexPath:indexPath];

if ([(id)self.ViewProviderClass respondsToSelector:@selector(tableViewCellForCatalogFromData:reuseCell:)]) {
cell = [self.ViewProviderClass tableViewCellForCatalogFromData:self.dataArray[indexPath.row] reuseCell:cell];
cell = [self.ViewProviderClass tableViewCellForCatalogFromData:self.dataArray[(NSUInteger)indexPath.row] reuseCell:cell];
} else {
cell = (UITableViewCell *)[self.ViewProviderClass viewForData:self.dataArray[indexPath.row] reuseView:cell size:nil context:nil];
cell = (UITableViewCell *)[self.ViewProviderClass viewForData:self.dataArray[(NSUInteger)indexPath.row] reuseView:cell size:nil context:nil];
NSAssert([cell isKindOfClass:[UITableViewCell class]], @"If your view is not a UITableViewCell, you must implement cellForCatalogFromData:reuseCell:");
}

Expand Down
4 changes: 2 additions & 2 deletions LayoutTestBase/Config/LYTConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ NS_SWIFT_NAME(Config)
/**
Default snapshots to save per method.
*/
extern NSUInteger const LYTSaveUnlimitedSnapshotsPerMethod;
extern NSInteger const LYTSaveUnlimitedSnapshotsPerMethod;

/**
Limits the number of snapshots that will be saved for each method in a LYTLayoutTestCase. If a test has multiple XCTAsserts which can fail for each size/data iteration there is the possiblity that hundreds of snapshots will be produced. Setting this to a value of 0 or greater will limit the number of images saved.
Expand All @@ -139,7 +139,7 @@ extern NSUInteger const LYTSaveUnlimitedSnapshotsPerMethod;
Default: SaveUnlimitedSnapshotsPerMethod(-1) (Representing unlimited)
*/
@property (nonatomic) NSUInteger snapshotsToSavePerMethod;
@property (nonatomic) NSInteger snapshotsToSavePerMethod;

/**
Singleton accessor.
Expand Down
2 changes: 1 addition & 1 deletion LayoutTestBase/Config/LYTConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

@implementation LYTConfig

NSUInteger const LYTSaveUnlimitedSnapshotsPerMethod = -1;
NSInteger const LYTSaveUnlimitedSnapshotsPerMethod = -1;

+ (instancetype)sharedInstance {
static LYTConfig *sharedInstance = nil;
Expand Down
Loading

0 comments on commit e44e868

Please sign in to comment.