Skip to content

Instantly share code, notes, and snippets.

@kaizimmer
Created June 21, 2013 15:50
Show Gist options
  • Save kaizimmer/5832150 to your computer and use it in GitHub Desktop.
Save kaizimmer/5832150 to your computer and use it in GitHub Desktop.
Fixing Clang scan error (original method code commented out): Clang scan-build bug report: File /Pods/Typhoon/Source/Utils/TyphoonTestUtils.m Bug Type Branch condition evaluates to a garbage value Category Logic error Description Branch condition evaluates to a garbage value
////////////////////////////////////////////////////////////////////////////////
//
// JASPER BLUES
// Copyright 2013 Jasper Blues
// All Rights Reserved.
//
// NOTICE: Jasper Blues permits you to use, modify, and distribute this file
// in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
#import "TyphoonTestUtils.h"
@implementation TyphoonTestUtils
+ (void)waitForCondition:(BOOL (^)())condition
{
[self waitForCondition:condition andPerformTests:^
{
//No assertions - wait for condition only.
}];
}
+ (void)waitForCondition:(BOOL (^)())condition andPerformTests:(void (^)())assertions
{
[self wait:7 secondsForCondition:condition andPerformTests:assertions];
}
+ (void)wait:(NSTimeInterval)seconds secondsForCondition:(BOOL (^)())condition andPerformTests:(void (^)())assertions
{
for (int i = 0; i < seconds; i++)
{
if ( condition() )
{
assertions();
return;
}
else
{
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
}
}
[NSException raise:NSGenericException format:@"Condition didn't happen before timeout: %f", seconds];
}
/*/
+ (void)wait:(NSTimeInterval)seconds secondsForCondition:(BOOL (^)())condition andPerformTests:(void (^)())assertions
{
__block BOOL conditionMet;
for (int i = 0; i < seconds; i++)
{
conditionMet = condition();
if (conditionMet)
{
break;
}
else
{
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1]];
}
}
if (conditionMet)
{
assertions();
}
else
{
[NSException raise:NSGenericException format:@"Condition didn't happen before timeout: %f", seconds];
}
}
//*/
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment