Skip to content

Commit

Permalink
Updating GHUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriel committed Feb 8, 2010
1 parent 49bf67f commit e0280b5
Show file tree
Hide file tree
Showing 32 changed files with 219 additions and 57 deletions.
Binary file not shown.
Expand Up @@ -39,13 +39,26 @@ typedef enum {
GHTestStatusErrored, // Test finished and errored GHTestStatusErrored, // Test finished and errored
} GHTestStatus; } GHTestStatus;


enum {
GHTestOptionReraiseExceptions = 1 << 0, // Allows exceptions to be raised (so you can trigger the debugger)
GHTestOptionForceSetUpTearDownClass = 1 << 1, // Runs setUpClass/tearDownClass for this (each) test; Used when re-running a single test in a group
};
typedef NSInteger GHTestOptions;

/*! /*!
Generate string from GHTestStatus Generate string from GHTestStatus
@param status @param status
*/ */
extern NSString* NSStringFromGHTestStatus(GHTestStatus status); extern NSString* NSStringFromGHTestStatus(GHTestStatus status);


/*!
Check if test is running (or trying to cancel).
*/
extern BOOL GHTestStatusIsRunning(GHTestStatus status); extern BOOL GHTestStatusIsRunning(GHTestStatus status);

/*!
Check if test has succeeded, errored or cancelled.
*/
extern BOOL GHTestStatusEnded(GHTestStatus status); extern BOOL GHTestStatusEnded(GHTestStatus status);


/*! /*!
Expand Down Expand Up @@ -73,29 +86,25 @@ extern NSString *NSStringFromGHTestStats(GHTestStats stats);
The base interface for a runnable test. The base interface for a runnable test.
A runnable with a unique identifier, display name, stats, timer, delegate, log and error handling. A runnable with a unique identifier, display name, stats, timer, delegate, log and error handling.
*/ */
@protocol GHTest <NSObject> @protocol GHTest <NSObject, NSCoding, NSCopying>

- (void)run;

- (NSString *)identifier;
- (NSString *)name;


- (NSTimeInterval)interval; - (void)run:(GHTestOptions)options;
- (GHTestStatus)status;
- (GHTestStats)stats;


- (void)setDelegate:(id<GHTestDelegate>)delegate; @property (readonly, nonatomic) NSString *identifier; // Unique identifier for test

@property (readonly, nonatomic) NSString *name;
- (NSException *)exception; @property (assign, nonatomic) NSTimeInterval interval;
- (void)setException:(NSException *)exception; @property (assign, nonatomic) GHTestStatus status;
@property (readonly, nonatomic) GHTestStats stats;
@property (retain, nonatomic) NSException *exception;
@property (assign, nonatomic, getter=isDisabled) BOOL disabled;
@property (assign, nonatomic, getter=isHidden) BOOL hidden;
@property (assign, nonatomic) id<GHTestDelegate> delegate; // weak


- (NSArray *)log; - (NSArray *)log;


- (void)reset; - (void)reset;
- (void)cancel; - (void)cancel;


- (void)setDisabled:(BOOL)disabled;
- (BOOL)isDisabled;
- (NSInteger)disabledCount; - (NSInteger)disabledCount;


@end @end
Expand All @@ -119,12 +128,16 @@ extern NSString *NSStringFromGHTestStats(GHTestStats stats);


@interface GHTestOperation : NSOperation { @interface GHTestOperation : NSOperation {
id<GHTest> test_; id<GHTest> test_;
GHTestOptions options_;
} }

- (id)initWithTest:(id<GHTest>)test options:(GHTestOptions)options;

@end @end


/*! /*!
Default test implementation with a target/selector pair. Default test implementation with a target/selector pair.
- Consists of a target/selector - Tests a target and selector
- Notifies a test delegate - Notifies a test delegate
- Keeps track of status, running time and failures - Keeps track of status, running time and failures
- Stores any test specific logging - Stores any test specific logging
Expand All @@ -141,22 +154,23 @@ extern NSString *NSStringFromGHTestStats(GHTestStats stats);
GHTestStatus status_; GHTestStatus status_;
NSTimeInterval interval_; NSTimeInterval interval_;
BOOL disabled_; BOOL disabled_;
BOOL hidden_;
NSException *exception_; // If failed NSException *exception_; // If failed


NSMutableArray *log_; NSMutableArray *log_;

} }


@property (readonly, nonatomic) id target; @property (readonly, nonatomic) id target;
@property (readonly, nonatomic) SEL selector; @property (readonly, nonatomic) SEL selector;
@property (readonly, nonatomic) NSString *identifier; // Unique identifier for test
@property (readonly, nonatomic) NSString *name;
@property (readonly, nonatomic) NSTimeInterval interval;
@property (retain, nonatomic) NSException *exception;
@property (readonly, nonatomic) GHTestStatus status;
@property (assign, nonatomic, getter=isDisabled) BOOL disabled;
@property (readonly, nonatomic) NSArray *log; @property (readonly, nonatomic) NSArray *log;


@property (assign, nonatomic) NSObject<GHTestDelegate> *delegate; /*!
Creat test with identifier, name.
@param identifier Unique identifier
@param name Name
*/
- (id)initWithIdentifier:(NSString *)identifier name:(NSString *)name;


/*! /*!
Create test with target/selector. Create test with target/selector.
Expand Down
Expand Up @@ -84,14 +84,16 @@
NSObject<GHTestDelegate> *delegate_; // weak NSObject<GHTestDelegate> *delegate_; // weak
id<GHTestGroup> parent_; // weak id<GHTestGroup> parent_; // weak


NSMutableArray *children_; // of id<GHTest> NSMutableArray */*of id<GHTest>*/children_;


NSString *name_; // The name of the test group (usually the class name of the test case NSString *name_; // The name of the test group (usually the class name of the test case
NSTimeInterval interval_; // Total time of child tests NSTimeInterval interval_; // Total time of child tests
GHTestStatus status_; // Current status of the group (current status of running or completed child tests) GHTestStatus status_; // Current status of the group (current status of running or completed child tests)
GHTestStats stats_; // Current stats for the group (aggregate of child test stats) GHTestStats stats_; // Current stats for the group (aggregate of child test stats)


BOOL didSetUpClass_; BOOL didSetUpClass_;

GHTestOptions options_;


// Set if test is created from initWithTestCase:delegate: // Set if test is created from initWithTestCase:delegate:
// Allows use to perform setUpClass and tearDownClass (once per test case run) // Allows use to perform setUpClass and tearDownClass (once per test case run)
Expand All @@ -101,17 +103,9 @@
} }


@property (readonly, nonatomic) NSArray */*of id<GHTest>*/children; @property (readonly, nonatomic) NSArray */*of id<GHTest>*/children;
@property (assign, nonatomic) NSObject<GHTestDelegate> *delegate;
@property (assign, nonatomic) id<GHTestGroup> parent; @property (assign, nonatomic) id<GHTestGroup> parent;
@property (readonly, nonatomic) id testCase; @property (readonly, nonatomic) id testCase;

@property (assign, nonatomic) GHTestOptions options;
@property (readonly, nonatomic) NSString *identifier;
@property (readonly, nonatomic) NSString *name;
@property (readonly, nonatomic) GHTestStatus status;

@property (readonly, nonatomic) NSTimeInterval interval;
@property (readonly, nonatomic) GHTestStats stats;
@property (readonly, nonatomic) NSException *exception;


/*! /*!
Create an empty test group. Create an empty test group.
Expand Down Expand Up @@ -155,13 +149,24 @@


- (void)addTestGroup:(GHTestGroup *)testGroup; - (void)addTestGroup:(GHTestGroup *)testGroup;


- (void)addTests:(NSArray */*of id<GHTest>*/)tests;

- (void)addTest:(id<GHTest>)test;

- (BOOL)shouldRunOnMainThread; - (BOOL)shouldRunOnMainThread;


/*!
Get list of failed tests.
@result Failed tests
*/
- (NSArray */*of id<GHTest>*/)failedTests;

/*! /*!
Run in operation queue. Run in operation queue.
Tests from the group are added and will block until they have completed. Tests from the group are added and will block until they have completed.
@param operationQueue If nil, then runs as is @param operationQueue If nil, then runs as is
@param options Options
*/ */
- (void)runInOperationQueue:(NSOperationQueue *)operationQueue; - (void)runInOperationQueue:(NSOperationQueue *)operationQueue options:(GHTestOptions)options;


@end @end
Expand Up @@ -86,6 +86,9 @@ extern NSString *const GHTestFilenameKey;
extern NSString *const GHTestLineNumberKey; extern NSString *const GHTestLineNumberKey;
extern NSString *const GHTestFailureException; extern NSString *const GHTestFailureException;


#if defined(__cplusplus)
extern "C"
#endif
NSString *GHComposeString(NSString *, ...); NSString *GHComposeString(NSString *, ...);


// Generates a failure when a1 != noErr // Generates a failure when a1 != noErr
Expand Down
Expand Up @@ -74,24 +74,27 @@
id<GHTest> test_; // The test to run; Could be a GHTestGroup (suite), GHTestGroup (test case), or GHTest (target/selector) id<GHTest> test_; // The test to run; Could be a GHTestGroup (suite), GHTestGroup (test case), or GHTest (target/selector)


NSObject<GHTestRunnerDelegate> *delegate_; // weak NSObject<GHTestRunnerDelegate> *delegate_; // weak


// If YES, will allow exceptions to be raised (so you can trigger the debugger) GHTestOptions options_;
BOOL raiseExceptions_;


BOOL running_; BOOL running_;
BOOL cancelling_; BOOL cancelling_;


NSTimeInterval startInterval_;

NSOperationQueue *operationQueue_; //! If running a suite in operation queue NSOperationQueue *operationQueue_; //! If running a suite in operation queue
} }


@property (retain) id<GHTest> test; @property (retain) id<GHTest> test;
@property (assign) NSObject<GHTestRunnerDelegate> *delegate; @property (assign) NSObject<GHTestRunnerDelegate> *delegate;
@property (assign) BOOL raiseExceptions; @property (assign) GHTestOptions options;
@property (readonly) GHTestStats stats; @property (readonly) GHTestStats stats;
@property (readonly, getter=isRunning) BOOL running; @property (readonly, getter=isRunning) BOOL running;
@property (readonly, getter=isCancelling) BOOL cancelling; @property (readonly, getter=isCancelling) BOOL cancelling;
@property (readonly) NSTimeInterval interval;
@property (retain, nonatomic) NSOperationQueue *operationQueue; @property (retain, nonatomic) NSOperationQueue *operationQueue;



/*! /*!
Create runner for test. Create runner for test.
@param test @param test
Expand Down Expand Up @@ -136,13 +139,16 @@
- (void)runInBackground; - (void)runInBackground;


/*! /*!
Start the test runner. Start the test runner with the default test.
@result 0 is success, otherwise the failure count @result 0 is success, otherwise the failure count
*/ */
- (int)runTests; - (int)runTests;


- (void)cancel; - (void)cancel;


- (void)setInParallel:(BOOL)inParallel;
- (BOOL)isInParallel;

/*! /*!
Write message to console. Write message to console.
*/ */
Expand Down
Expand Up @@ -96,11 +96,42 @@ BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass);
*/ */
- (void)registerClassName:(NSString *)className; - (void)registerClassName:(NSString *)className;


/*!
Format test exception.
@param exception
@result Description
*/
+ (NSString *)descriptionForException:(NSException *)exception;

/*!
Filename for cause of test exception.
@param test
@result Filename
*/
+ (NSString *)exceptionFilenameForTest:(id<GHTest>)test;

/*!
Line number for cause of test exception.
@param test
@result Line number
*/
+ (NSInteger)exceptionLineNumberForTest:(id<GHTest>)test;

/*! /*!
Run test. Run test.
Exception if set is retained and should be released by the caller. @param target
@param selector
@param exception Exception, if set, is retained and should be released by the caller.
@param interval Time to run the test
@param reraiseExceptions If YES, will re-raise exceptions
*/
+ (BOOL)runTestWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception
interval:(NSTimeInterval *)interval reraiseExceptions:(BOOL)reraiseExceptions;

/*!
Same as normal runTest without catching exceptions.
*/ */
+ (BOOL)runTest:(id)target selector:(SEL)selector withObject:(id)obj exception:(NSException **)exception interval:(NSTimeInterval *)interval; + (BOOL)runTestOrRaiseWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception interval:(NSTimeInterval *)interval;


@end @end


Expand Down
15 changes: 15 additions & 0 deletions Project-IPhone/Libraries/libGHUnitIPhone3_0-0.4.19/Makefile
@@ -0,0 +1,15 @@

TEST_TARGET=Tests
SDK=iphonesimulator3.0
COMMAND=xcodebuild

default:
# Set default make action here

# If you need to clean a specific target/configuration: $(COMMAND) -target $(TARGET) -configuration DebugOrRelease -sdk $(SDK) clean
clean:
-rm -rf build/*

test:
GHUNIT_CLI=1 $(COMMAND) -target $(TEST_TARGET) -configuration Debug -sdk $(SDK) build

Expand Up @@ -45,6 +45,11 @@
// the License. // the License.
// //


extern NSString *const GHTestFilenameKey;
extern NSString *const GHTestLineNumberKey;
extern NSString *const GHTestFailureException;


// GTM_BEGIN // GTM_BEGIN


#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
Expand Down
Binary file not shown.
Binary file modified Project/Frameworks/GHUnit.framework/Versions/A/GHUnit
Binary file not shown.
22 changes: 20 additions & 2 deletions Project/Frameworks/GHUnit.framework/Versions/A/Headers/GHTest.h
Expand Up @@ -39,13 +39,26 @@ typedef enum {
GHTestStatusErrored, // Test finished and errored GHTestStatusErrored, // Test finished and errored
} GHTestStatus; } GHTestStatus;


enum {
GHTestOptionReraiseExceptions = 1 << 0, // Allows exceptions to be raised (so you can trigger the debugger)
GHTestOptionForceSetUpTearDownClass = 1 << 1, // Runs setUpClass/tearDownClass for this (each) test; Used when re-running a single test in a group
};
typedef NSInteger GHTestOptions;

/*! /*!
Generate string from GHTestStatus Generate string from GHTestStatus
@param status @param status
*/ */
extern NSString* NSStringFromGHTestStatus(GHTestStatus status); extern NSString* NSStringFromGHTestStatus(GHTestStatus status);


/*!
Check if test is running (or trying to cancel).
*/
extern BOOL GHTestStatusIsRunning(GHTestStatus status); extern BOOL GHTestStatusIsRunning(GHTestStatus status);

/*!
Check if test has succeeded, errored or cancelled.
*/
extern BOOL GHTestStatusEnded(GHTestStatus status); extern BOOL GHTestStatusEnded(GHTestStatus status);


/*! /*!
Expand Down Expand Up @@ -73,9 +86,9 @@ extern NSString *NSStringFromGHTestStats(GHTestStats stats);
The base interface for a runnable test. The base interface for a runnable test.
A runnable with a unique identifier, display name, stats, timer, delegate, log and error handling. A runnable with a unique identifier, display name, stats, timer, delegate, log and error handling.
*/ */
@protocol GHTest <NSObject, NSCoding> @protocol GHTest <NSObject, NSCoding, NSCopying>


- (void)run; - (void)run:(GHTestOptions)options;


@property (readonly, nonatomic) NSString *identifier; // Unique identifier for test @property (readonly, nonatomic) NSString *identifier; // Unique identifier for test
@property (readonly, nonatomic) NSString *name; @property (readonly, nonatomic) NSString *name;
Expand Down Expand Up @@ -115,7 +128,11 @@ extern NSString *NSStringFromGHTestStats(GHTestStats stats);


@interface GHTestOperation : NSOperation { @interface GHTestOperation : NSOperation {
id<GHTest> test_; id<GHTest> test_;
GHTestOptions options_;
} }

- (id)initWithTest:(id<GHTest>)test options:(GHTestOptions)options;

@end @end


/*! /*!
Expand All @@ -141,6 +158,7 @@ extern NSString *NSStringFromGHTestStats(GHTestStats stats);
NSException *exception_; // If failed NSException *exception_; // If failed


NSMutableArray *log_; NSMutableArray *log_;

} }


@property (readonly, nonatomic) id target; @property (readonly, nonatomic) id target;
Expand Down
Expand Up @@ -8,8 +8,6 @@


#import "GHTestWindowController.h" #import "GHTestWindowController.h"


#import "GHTestRunner.h"

@interface GHTestApp : NSObject { @interface GHTestApp : NSObject {
NSMutableArray *topLevelObjects_; NSMutableArray *topLevelObjects_;


Expand Down

0 comments on commit e0280b5

Please sign in to comment.