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

Commit f27653d

Browse files
authored
Merge pull request #548 from kazk/fix/objc
Fix UnitKit with setup code
2 parents c622870 + e3f01f5 commit f27653d

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

lib/runners/objc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ function prepareUnitKit(opts) {
188188
}
189189
`;
190190

191-
codeWriteSync('objc', getCode(opts), opts.dir, 'solution.m');
191+
codeWriteSync('objc', opts.solution, opts.dir, 'solution.m');
192192
if (opts.setup) codeWriteSync('objc', opts.setup, opts.dir, 'setup.m');
193193
const fixtureFile = codeWriteSync('objc', fixture, opts.dir, 'fixture.m');
194194
const mainFile = codeWriteSync('objc', main, opts.dir, 'main.m');

test/runners/objc_spec.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,79 @@ describe('objc runner', function() {
631631
done();
632632
});
633633
});
634+
635+
it('should support setup code', function(done) {
636+
// https://github.com/Codewars/codewars.com/issues/1221
637+
runner.run({
638+
language: 'objc',
639+
testFramework: 'unitkit',
640+
setup: `
641+
#import <Foundation/Foundation.h>
642+
643+
@interface Node: NSObject
644+
{
645+
int data;
646+
Node *next;
647+
}
648+
@property (readonly) int data;
649+
@property (readonly) Node *next;
650+
- (id)initWithData: (int)d andNext: (Node *)n;
651+
- (id)initWithData: (int)d;
652+
+ (Node *)nodeWithData: (int)d andNext: (Node *)n;
653+
+ (Node *)nodeWithData: (int)d;
654+
@end
655+
656+
@implementation Node
657+
@synthesize data;
658+
@synthesize next;
659+
- (id)initWithData: (int)d andNext: (Node *)n
660+
{
661+
data = d;
662+
next = n;
663+
return self;
664+
}
665+
- (id)initWithData: (int)d
666+
{
667+
data = d;
668+
next = NULL;
669+
return self;
670+
}
671+
+ (Node *)nodeWithData: (int)d andNext: (Node *)n
672+
{
673+
return [[Node alloc] initWithData: d andNext: n];
674+
}
675+
+ (Node *)nodeWithData: (int)d
676+
{
677+
return [[Node alloc] initWithData: d];
678+
}
679+
@end
680+
`,
681+
solution: `
682+
#import <Foundation/Foundation.h>
683+
684+
NSString *stringify(Node *list) {
685+
// TODO: Return a string representation of the list passed in
686+
return @"";
687+
}
688+
`,
689+
fixture: `
690+
@implementation TestSuite
691+
- (void)testNULL
692+
{
693+
UKStringsEqual(@"", stringify(NULL));
694+
}
695+
- (void)testSingle
696+
{
697+
UKStringsEqual(@"1", stringify([Node nodeWithData: 1]));
698+
}
699+
@end
700+
`,
701+
}, function(buffer) {
702+
expect(buffer.stdout).to.contain('<PASSED::>');
703+
expect(buffer.stdout).to.contain('<FAILED::>');
704+
done();
705+
});
706+
});
634707
});
635708

636709
describe('CW', function() {

0 commit comments

Comments
 (0)