Skip to content

Commit

Permalink
Turn the main application into a test suite app
Browse files Browse the repository at this point in the history
  • Loading branch information
hiddenmemory committed Apr 9, 2012
1 parent 1e78ad6 commit ce98fbe
Showing 1 changed file with 44 additions and 37 deletions.
81 changes: 44 additions & 37 deletions Tipi/main.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,48 +11,55 @@
#import "Tipi.h" #import "Tipi.h"


int main(int argc, const char * argv[]) { int main(int argc, const char * argv[]) {

@autoreleasepool { @autoreleasepool {
NSMutableDictionary *environment = [NSMutableDictionary dictionary]; if( argc > 1 ) {

NSString *path = [NSString stringWithFormat:@"%s/Tests/", argv[1]];
[environment setObject:[^NSString*( TPTemplateNode *node, NSMutableDictionary *environment ) {
TPMarkdownDataParser *parser = [TPMarkdownDataParser parserForFile:[node.values objectAtIndex:0]];

// Duplicate the environment for implementing the child nodes
NSMutableDictionary *invokeEnvironment = [NSMutableDictionary dictionaryWithDictionary:environment];

// Add the key-values from the data file
[invokeEnvironment addEntriesFromDictionary:parser.values];


return [node.childNodes tp_templateNodesExpandedUsingEnvironment:invokeEnvironment]; NSLog(@"Scanning %@ for test suites...", path);
} copy] forKey:@"include"];

for( int i = 1; i <= 6; i++ ) {
NSString *inputPath = [NSString stringWithFormat:@"/Users/chris/Repositories/git/hiddenMemory/Tipi/Tests/basic/Test0%d.input", i];
NSString *outputPath = [NSString stringWithFormat:@"/Users/chris/Repositories/git/hiddenMemory/Tipi/Tests/basic/Test0%d.output", i];


TPTemplateParser *q = [TPTemplateParser parserForFile:inputPath]; [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil] enumerateObjectsUsingBlock:^(NSString *suiteName, NSUInteger idx, BOOL *stop) {
NSString *expansion = [q expansionUsingEnvironment:[NSDictionary dictionary]]; BOOL isDirectory = NO;

NSString *testPath = [NSString stringWithFormat:@"%@%@/", path, suiteName];
if( [[NSFileManager defaultManager] fileExistsAtPath:outputPath] ) {
NSString *goldenExpansion = [NSString stringWithContentsOfFile:outputPath
encoding:NSUTF8StringEncoding
error:nil];


if( [goldenExpansion isEqualToString:expansion] ) { if( [[NSFileManager defaultManager] fileExistsAtPath:testPath isDirectory:&isDirectory] && isDirectory ) {
NSLog(@"Test %d passed", i); NSLog(@"Test suite: %@ (path: %@)", suiteName, testPath);

[[[NSFileManager defaultManager] contentsOfDirectoryAtPath:testPath error:nil] enumerateObjectsUsingBlock:^(NSString *item, NSUInteger idx, BOOL *stop) {
if( [item hasSuffix:@".input"] ) {
NSString *inputPath = [NSString stringWithFormat:@"%@%@", testPath, item];
NSString *outputPath = [NSString stringWithFormat:@"%@%@", testPath, [item stringByReplacingOccurrencesOfString:@".input"
withString:@".output"]];

TPTemplateParser *q = [TPTemplateParser parserForFile:inputPath];
NSString *expansion = [q expansionUsingEnvironment:[NSDictionary dictionary]];

if( [[NSFileManager defaultManager] fileExistsAtPath:outputPath] ) {
NSString *goldenExpansion = [NSString stringWithContentsOfFile:outputPath
encoding:NSUTF8StringEncoding
error:nil];

if( [goldenExpansion isEqualToString:expansion] ) {
NSLog(@"[%@] Test Passed", item);
}
else {
NSLog(@"[%@] >>>> Test failed <<<<", item);
}
}
else {
NSLog(@"[%@] Creating new test output:\n%@", item, expansion);
[expansion writeToFile:outputPath
atomically:NO
encoding:NSUTF8StringEncoding
error:nil];
}
}
}];
} }
else { }];
NSLog(@">>>> Test %d failed <<<<", i); }
} else {
} NSLog(@"Please provide a path to the Tipi test suite");
else {
NSLog(@"Expansion:\nSTART:\n%@:END", expansion);
[expansion writeToFile:outputPath
atomically:NO
encoding:NSUTF8StringEncoding
error:nil];
}
} }
} }
return 0; return 0;
Expand Down

0 comments on commit ce98fbe

Please sign in to comment.