Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 83 lines (65 sloc) 1.987 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
//
// KWExampleSuite.m
// Kiwi
//
// Created by Luke Redpath on 17/10/2011.
// Copyright (c) 2011 Allen Ding. All rights reserved.
//

#import "KWExampleSuite.h"
#import "KWExample.h"
#import "KWStringUtilities.h"
#import "KWBeforeAllNode.h"
#import "KWAfterAllNode.h"
#import "NSMethodSignature+KiwiAdditions.h"
#import <objc/runtime.h>

#define kKWINVOCATION_EXAMPLE_GROUP_KEY @"__KWExampleGroupKey"

@implementation KWExampleSuite

- (id)initWithRootNode:(KWContextNode *)contextNode
{
  if ((self = [super init])) {
    rootNode = [contextNode retain];
    examples = [[NSMutableArray alloc] init];
  }
  return self;
}

- (void)dealloc
{
  [examples release];
  [rootNode release];
  [super dealloc];
}

- (void)addExample:(KWExample *)example
{
  [examples addObject:example];
  [example setSuite:self];
}

- (void)markLastExampleAsLastInContext:(KWContextNode *)context
{
  [[examples objectAtIndex:examples.count-1] setLastInContext:context];
}

- (NSArray *)invocationsForTestCase;
{
  NSMutableArray *invocations = [NSMutableArray array];
  
  // Add a single dummy invocation for each example group
  
  for (KWExample *exampleGroup in examples) {
    NSMethodSignature *methodSignature = [NSMethodSignature signatureWithObjCTypes:[KWEncodingForVoidMethod() UTF8String]];
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
    [invocations addObject:invocation];
    [invocation kw_setExample:exampleGroup];
  }
  
  return invocations;
}

@end

#pragma mark -

// because SenTest will modify the invocation target, we'll have to store
// another reference to the example group so we can retrieve it later

@implementation NSInvocation (KWExampleGroup)

- (void)kw_setExample:(KWExample *)exampleGroup
{
  objc_setAssociatedObject(self, kKWINVOCATION_EXAMPLE_GROUP_KEY, exampleGroup, OBJC_ASSOCIATION_RETAIN);
}

- (KWExample *)kw_example
{
  return objc_getAssociatedObject(self, kKWINVOCATION_EXAMPLE_GROUP_KEY);
}

@end
Something went wrong with that request. Please try again.