/
main.m
67 lines (55 loc) · 2.25 KB
/
main.m
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
//
// main.m
// Tipi
//
// Created by Chris Ross on 05/04/2012.
// Copyright (c) 2012 hiddenMemory Ltd. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "Tipi.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
if( argc > 1 ) {
NSString *path = [NSString stringWithFormat:@"%s/Tests/", argv[1]];
NSLog(@"Scanning %@ for test suites...", path);
[[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil] enumerateObjectsUsingBlock:^(NSString *suiteName, NSUInteger idx, BOOL *stop) {
BOOL isDirectory = NO;
NSString *testPath = [NSString stringWithFormat:@"%@%@/", path, suiteName];
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(@"Please provide a path to the Tipi test suite");
}
}
return 0;
}