This repository was archived by the owner on May 27, 2021. It is now read-only.
forked from alunny/node-xcode
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpbxProject.js
More file actions
229 lines (195 loc) · 7.13 KB
/
pbxProject.js
File metadata and controls
229 lines (195 loc) · 7.13 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
var pbx = require('../lib/pbxProject'),
buildConfig = require('./fixtures/buildFiles'),
jsonProject = require('./fixtures/full-project'),
fs = require('fs'),
project;
exports['creation'] = {
'should create a pbxProject with the new operator': function (test) {
var myProj = new pbx('test/parser/projects/hash.pbxproj');
test.ok(myProj instanceof pbx);
test.done();
},
'should create a pbxProject without the new operator': function (test) {
var myProj = pbx('test/parser/projects/hash.pbxproj');
test.ok(myProj instanceof pbx);
test.done();
}
}
exports['parseSync function'] = {
'should return the hash object': function (test) {
var myProj = new pbx('test/parser/projects/hash.pbxproj')
, projHash = myProj.parseSync();
test.ok(projHash);
test.done();
},
'should contain valid data in the returned objects hash': function (test) {
var myProj = new pbx('test/parser/projects/hash.pbxproj')
, projHash = myProj.parseSync();
test.ok(projHash);
test.equal(projHash.hash.project.archiveVersion, 1);
test.equal(projHash.hash.project.objectVersion, 45);
test.equal(projHash.hash.project.nonObject, '29B97313FDCFA39411CA2CEF');
test.done();
},
}
exports['parse function'] = {
'should emit an "end" event': function (test) {
var myProj = new pbx('test/parser/projects/hash.pbxproj');
myProj.parse().on('end', function (err, projHash) {
test.done();
})
},
'should take the end callback as a parameter': function (test) {
var myProj = new pbx('test/parser/projects/hash.pbxproj');
myProj.parse(function (err, projHash) {
test.done();
})
},
'should allow evented error handling': function (test) {
var myProj = new pbx('NotARealPath.pbxproj');
myProj.parse().on('error', function (err) {
test.equal(typeof err, "object");
test.done();
})
},
'should pass the hash object to the callback function': function (test) {
var myProj = new pbx('test/parser/projects/hash.pbxproj');
myProj.parse(function (err, projHash) {
test.ok(projHash);
test.done();
})
},
'should handle projects with comments in the header': function (test) {
var myProj = new pbx('test/parser/projects/comments.pbxproj');
myProj.parse(function (err, projHash) {
test.ok(projHash);
test.done();
})
},
'should attach the hash object to the pbx object': function (test) {
var myProj = new pbx('test/parser/projects/hash.pbxproj');
myProj.parse(function (err, projHash) {
test.ok(myProj.hash);
test.done();
})
},
'it should pass an error object back when the parsing fails': function (test) {
var myProj = new pbx('test/parser/projects/fail.pbxproj');
myProj.parse(function (err, projHash) {
test.ok(err);
test.done();
})
}
}
exports['allUuids function'] = {
'should return the right amount of uuids': function (test) {
var project = new pbx('.'),
uuids;
project.hash = buildConfig;
uuids = project.allUuids();
test.equal(uuids.length, 4);
test.done();
}
}
exports['generateUuid function'] = {
'should return a 24 character string': function (test) {
var project = new pbx('.'),
newUUID;
project.hash = buildConfig;
newUUID = project.generateUuid();
test.equal(newUUID.length, 24);
test.done();
},
'should be an uppercase hex string': function (test) {
var project = new pbx('.'),
uHex = /^[A-F0-9]{24}$/,
newUUID;
project.hash = buildConfig;
newUUID = project.generateUuid();
test.ok(uHex.test(newUUID));
test.done();
}
}
var bcpbx = 'test/parser/projects/build-config.pbxproj';
var original_pbx = fs.readFileSync(bcpbx, 'utf-8');
exports['updateProductName function'] = {
setUp:function(callback) {
callback();
},
tearDown:function(callback) {
fs.writeFileSync(bcpbx, original_pbx, 'utf-8');
callback();
},
'should change the PRODUCT_NAME field in the .pbxproj file': function (test) {
var myProj = new pbx('test/parser/projects/build-config.pbxproj');
myProj.parse(function(err, hash) {
myProj.updateProductName('furious anger');
var newContents = myProj.writeSync();
test.ok(newContents.match(/PRODUCT_NAME\s*=\s*"furious anger"/));
test.done();
});
}
}
exports['updateBuildProperty function'] = {
setUp:function(callback) {
callback();
},
tearDown:function(callback) {
fs.writeFileSync(bcpbx, original_pbx, 'utf-8');
callback();
},
'should change build properties in the .pbxproj file': function (test) {
var myProj = new pbx('test/parser/projects/build-config.pbxproj');
myProj.parse(function(err, hash) {
myProj.updateBuildProperty('TARGETED_DEVICE_FAMILY', '"arm"');
var newContents = myProj.writeSync();
test.ok(newContents.match(/TARGETED_DEVICE_FAMILY\s*=\s*"arm"/));
myProj.updateBuildProperty('OTHER_LDFLAGS', ['T','E','S','T']);
newContents = myProj.writeSync();
test.ok(newContents.match(/OTHER_LDFLAGS\s*=\s*\(\s*T,\s*E,\s*S,\s*T,\s*\)/))
test.done();
});
}
}
exports['productName field'] = {
'should return the product name': function (test) {
var newProj = new pbx('.');
newProj.hash = jsonProject;
test.equal(newProj.productName, 'KitchenSinktablet');
test.done();
}
}
exports['addPluginFile function'] = {
'should strip the Plugin path prefix': function (test) {
var myProj = new pbx('test/parser/projects/full.pbxproj');
myProj.parse(function (err, hash) {
test.equal(myProj.addPluginFile('Plugins/testMac.m').path, 'testMac.m');
test.equal(myProj.addPluginFile('Plugins\\testWin.m').path, 'testWin.m');
test.done();
});
},
'should add files to the .pbxproj file using the / path seperator': function (test) {
var myProj = new pbx('test/parser/projects/full.pbxproj');
myProj.parse(function (err, hash) {
var file = myProj.addPluginFile('myPlugin\\newFile.m');
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].path, '"myPlugin/newFile.m"');
test.done();
});
}
}
exports['hasFile'] = {
'should return true if the file is in the project': function (test) {
var newProj = new pbx('.');
newProj.hash = jsonProject;
// sourceTree: '"<group>"'
test.ok(newProj.hasFile('AppDelegate.m'))
test.done()
},
'should return false if the file is not in the project': function (test) {
var newProj = new pbx('.');
newProj.hash = jsonProject;
// sourceTree: '"<group>"'
test.ok(!newProj.hasFile('NotTheAppDelegate.m'))
test.done()
}
}