Skip to content

Commit

Permalink
Make ojunit more compatible with the build system in Cappuccino.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ross Boucher committed Apr 9, 2009
1 parent ebc2a8a commit d7ced3e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
28 changes: 27 additions & 1 deletion OJTestListenerText.j
@@ -1,17 +1,43 @@
@import <Foundation/Foundation.j>

@implementation OJTestListenerText : CPObject
{
CPArray _errors;
CPArray _failures;
}

- (id)init
{
self = [super init];

_errors = [];
_failures = [];

return self;
}

- (void)addError:(CPException)error forTest:(OJTest)aTest
{
_errors.push(error);
CPLog.error("addError test="+[aTest description]+" error="+error);
}

- (CPArray)errors
{
return _errors;
}

- (void)addFailure:(CPException)failure forTest:(OJTest)aTest
{
_failures.push(failure);
CPLog.warn("addFailure test="+[aTest description]+" failure="+failure);
}

- (CPArray)failures
{
return _failures;
}

- (void)startTest:(OJTest)aTest
{
CPLog.info("startTest test="+[aTest description]);
Expand All @@ -22,4 +48,4 @@
CPLog.info("endTest test="+[aTest description]);
}

@end
@end
15 changes: 14 additions & 1 deletion main.j
Expand Up @@ -6,7 +6,7 @@

@import "OJTestListenerText.j"

CPLogRegister(CPLogPrint);
CPLogRegister(CPLogPrint, "warn");

@implementation OJTestRunnerText : CPObject
{
Expand Down Expand Up @@ -41,7 +41,10 @@ CPLogRegister(CPLogPrint);
var testCaseFile = args.shift();

if (!testCaseFile)
{
[self report];
return;
}

var matches = testCaseFile.match(/([^\/]+)\.j$/)
print(matches[1]);
Expand Down Expand Up @@ -83,6 +86,16 @@ CPLogRegister(CPLogPrint);
[self runTest:[[OJTestSuite alloc] initWithClass:aClass]];
}

- (void)report
{
var totalErrors = [[_listener errors] count] + [[_listener failures] count];

if (!totalErrors)
return CPLog.info("End of all tests.");

CPLog.fatal("Test suite failed with "+[[_listener errors] count]+" errors and "+[[_listener failures] count]+" failures.");
}

@end

print(args);
Expand Down

0 comments on commit d7ced3e

Please sign in to comment.