Objective-J Test API 0.1.0
Frameworks/OJUnit/OJTestFailure.j
Go to the documentation of this file.
00001 @import <Foundation/Foundation.j>
00002 
00003 function convertRhinoBacktrace(javaException) {
00004     var s = new Packages.java.io.StringWriter();
00005     javaException.printStackTrace(new Packages.java.io.PrintWriter(s));
00006     return String(s.toString()).split("\n").filter(function(s) { return (/^\s*at script/).test(s); }).join("\n");
00007 }
00008 
00009 function getBacktrace(e) {
00010     if (!e) {
00011         return "";
00012     }
00013     else if (e.rhinoException) {
00014         return convertRhinoBacktrace(e.rhinoException);
00015     }
00016     else if (e.javaException) {
00017         return convertRhinoBacktrace(e.javaException);
00018     }
00019     return "";
00020 }
00021 
00022 @implementation OJTestFailure : CPObject
00023 {
00024     OJTest      _failedTest                     @accessors(readonly, property=failedTest);
00025     CPException _thrownException        @accessors(readonly, property=thrownException);
00026 }
00027 
00028 - (id)initWithTest:(OJTest)failedTest exception:(CPException)thrownException
00029 {
00030     if (self = [super init])
00031     {
00032         _failedTest = failedTest;
00033         _thrownException = thrownException;
00034     }
00035     return self;
00036 }
00037 
00038 - (CPString)description
00039 {
00040     return [_failedTest description] + ": " + [self exceptionMessage];
00041 }
00042 
00043 - (CPString)trace
00044 {
00045     return getBacktrace(_thrownException) ? getBacktrace(_thrownException) : "Trace not implemented";
00046 }
00047 
00048 - (CPString)exceptionMessage
00049 {
00050     return [_thrownException description];
00051 }
00052 
00053 - (BOOL)isFailure
00054 {
00055     return [_thrownException name] == AssertionFailedError; // should AssertionFailedError be a subclass of CPException?
00056 }
00057 
00058 @end
 All Classes Files Functions Variables