forked from mxcl/ChuzzleKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests
executable file
·136 lines (114 loc) · 3.29 KB
/
tests
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/ruby
OBJC = <<-__EOBJC__
@import XCTest;
#import "Chuzzle.h"
int main() {
@autoreleasepool {
XCTSelfTestMain();
}
}
@interface ChuzzleKitTests : XCTestCase
@end
@implementation ChuzzleKitTests
- (void)test_everything {
id b = @[@{@"a": @"", @2: @"", @3: @[], @4: [NSNull null]}];
id a = @[NSNull.null, @"\t", @{@1: @" ", @2: b}, @1].chuzzle;
XCTAssertEqualObjects(a, @[@1]);
}
- (void)test_mutable_array {
NSMutableArray *mutableArray = [@[@1, @2, @""] mutableCopy];
id chuzzled = mutableArray.chuzzle;
XCTAssertTrue([chuzzled isKindOfClass:[NSMutableArray class]], @"Chuzzling a mutable array should return a mutable array");
XCTAssertEqual(mutableArray.count, 2ul);
XCTAssertEqual(chuzzled, mutableArray);
}
- (void)test_mutable_dict {
NSMutableDictionary *dict = @{@1: @"1", @2: @" "}.mutableCopy;
XCTAssertEqualObjects(dict[@1], @"1");
XCTAssertTrue([dict.chuzzle isKindOfClass:[NSMutableDictionary class]]);
}
- (void)test_no_chuzzle {
NSDictionary *a = @{@1: @"1", @2: @"2"};
id b = a.chuzzle;
XCTAssertEqualObjects(a, b);
}
- (void)test_mutable_string {
NSMutableString *a = [NSMutableString stringWithString:@" aa "];
a.chuzzle;
XCTAssertEqualObjects(a.copy, @"aa");
a = [@" bb ".mutableCopy chuzzle];
XCTAssertEqualObjects(a.copy, @"bb");
XCTAssertTrue([a isKindOfClass:[NSMutableString class]]);
}
@end
__EOBJC__
OUT = File.basename(Dir.pwd) + 'Tests'
FRAMEWORKS = "/Applications/Xcode.app/Contents/Developer/Library/Frameworks"
def bold(s); s; end
def red(s); "\e[31m#{s}\e[0m"; end
def green(s); "\e[32m#{s}\e[0m"; end
def tab(n, s); s.gsub(/^/, " " * n); end
def log(message); $stdout.puts(message); end
def each_test_line
require "stringio"
require "open3"
Open3.popen3("/tmp/#{OUT}") do |stdin, stdout, stderr, wait_thr|
while line = stderr.gets
yield line, stderr
end
end
end
def test!
test_method = nil
each_test_line do |line, stderr|
case line
when /Test Suite '(.*)' started/
log bold($1) unless $1 == 'tmp'
when /Test Suite '.*' finished/
when /\[(\w+) (\w+)\]' started.$/
test_method = $2
when /\s(passed|failed)\s\((.*)\)/
result = if $1 == "passed"
green("PASS")
else
red("FAIL")
end
result = tab(2, result)
time = $2.gsub(/\sseconds/, "s")
log "#{result} #{test_method} (#{time})"
when /^(Executed(.?)+)$/
if stderr.eof?
summary = $1
if /(\d) failures?/.match(summary)[1] == "0"
summary.gsub!(/(\d failures?)/, green('\1'))
else
summary.gsub!(/(\d failures?)/, red('\1'))
end
log summary
end
else
log line.strip
end
end
end
def compile!
File.open("/tmp/#{OUT}.m", 'w') do |f|
f.puts("\n\n") # make line numbers match compile errors
f.puts(OBJC)
end
abort unless system <<-EOS
clang -g -O0 -ObjC -F#{FRAMEWORKS} -I. -fmodules -fobjc-arc \
/tmp/#{OUT}.m Chuzzle.m \
-w -o /tmp/#{OUT}
EOS
abort unless system <<-EOS
install_name_tool -change \
@rpath/XCTest.framework/Versions/A/XCTest \
#{FRAMEWORKS}/XCTest.framework/XCTest \
/tmp/#{OUT}
EOS
end
compile!
test!
File.delete("/tmp/#{OUT}.m")
File.delete("/tmp/#{OUT}")