Skip to content
This repository has been archived by the owner on Oct 14, 2020. It is now read-only.

Commit

Permalink
Merge pull request #548 from kazk/fix/objc
Browse files Browse the repository at this point in the history
Fix UnitKit with setup code
  • Loading branch information
jhoffner authored Feb 17, 2018
2 parents c622870 + e3f01f5 commit f27653d
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/runners/objc.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ function prepareUnitKit(opts) {
}
`;

codeWriteSync('objc', getCode(opts), opts.dir, 'solution.m');
codeWriteSync('objc', opts.solution, opts.dir, 'solution.m');
if (opts.setup) codeWriteSync('objc', opts.setup, opts.dir, 'setup.m');
const fixtureFile = codeWriteSync('objc', fixture, opts.dir, 'fixture.m');
const mainFile = codeWriteSync('objc', main, opts.dir, 'main.m');
Expand Down
73 changes: 73 additions & 0 deletions test/runners/objc_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,79 @@ describe('objc runner', function() {
done();
});
});

it('should support setup code', function(done) {
// https://github.com/Codewars/codewars.com/issues/1221
runner.run({
language: 'objc',
testFramework: 'unitkit',
setup: `
#import <Foundation/Foundation.h>
@interface Node: NSObject
{
int data;
Node *next;
}
@property (readonly) int data;
@property (readonly) Node *next;
- (id)initWithData: (int)d andNext: (Node *)n;
- (id)initWithData: (int)d;
+ (Node *)nodeWithData: (int)d andNext: (Node *)n;
+ (Node *)nodeWithData: (int)d;
@end
@implementation Node
@synthesize data;
@synthesize next;
- (id)initWithData: (int)d andNext: (Node *)n
{
data = d;
next = n;
return self;
}
- (id)initWithData: (int)d
{
data = d;
next = NULL;
return self;
}
+ (Node *)nodeWithData: (int)d andNext: (Node *)n
{
return [[Node alloc] initWithData: d andNext: n];
}
+ (Node *)nodeWithData: (int)d
{
return [[Node alloc] initWithData: d];
}
@end
`,
solution: `
#import <Foundation/Foundation.h>
NSString *stringify(Node *list) {
// TODO: Return a string representation of the list passed in
return @"";
}
`,
fixture: `
@implementation TestSuite
- (void)testNULL
{
UKStringsEqual(@"", stringify(NULL));
}
- (void)testSingle
{
UKStringsEqual(@"1", stringify([Node nodeWithData: 1]));
}
@end
`,
}, function(buffer) {
expect(buffer.stdout).to.contain('<PASSED::>');
expect(buffer.stdout).to.contain('<FAILED::>');
done();
});
});
});

describe('CW', function() {
Expand Down

0 comments on commit f27653d

Please sign in to comment.