Browse files

Turn the main application into a test suite app

  • Loading branch information...
1 parent 1e78ad6 commit ce98fbe18ab21b974d36fb48613f35654ae6266a @hiddenmemory committed Apr 9, 2012
Showing with 44 additions and 37 deletions.
  1. +44 −37 Tipi/main.m
View
81 Tipi/main.m
@@ -11,48 +11,55 @@
#import "Tipi.h"
int main(int argc, const char * argv[]) {
-
+
@autoreleasepool {
- NSMutableDictionary *environment = [NSMutableDictionary dictionary];
-
- [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];
+ if( argc > 1 ) {
+ NSString *path = [NSString stringWithFormat:@"%s/Tests/", argv[1]];
- return [node.childNodes tp_templateNodesExpandedUsingEnvironment:invokeEnvironment];
- } 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];
+ NSLog(@"Scanning %@ for test suites...", path);
- 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];
+ [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil] enumerateObjectsUsingBlock:^(NSString *suiteName, NSUInteger idx, BOOL *stop) {
+ BOOL isDirectory = NO;
+ NSString *testPath = [NSString stringWithFormat:@"%@%@/", path, suiteName];
- if( [goldenExpansion isEqualToString:expansion] ) {
- NSLog(@"Test %d passed", i);
+ if( [[NSFileManager defaultManager] fileExistsAtPath:testPath isDirectory:&isDirectory] && isDirectory ) {
+ 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(@"Expansion:\nSTART:\n%@:END", expansion);
- [expansion writeToFile:outputPath
- atomically:NO
- encoding:NSUTF8StringEncoding
- error:nil];
- }
+ }];
+ }
+ else {
+ NSLog(@"Please provide a path to the Tipi test suite");
}
}
return 0;

0 comments on commit ce98fbe

Please sign in to comment.