Skip to content

Commit e2a7eee

Browse files
author
Kristian D. Dimitrov
committed
fix: unit tests
1 parent 18fb390 commit e2a7eee

23 files changed

+67
-50
lines changed

lib/pbxProject.js

+22-10
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,7 @@ pbxProject.prototype.findMainPbxGroup = function () {
510510
}
511511

512512
pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceTree, opt) {
513-
513+
opt = opt || {};
514514
var oldGroup = this.pbxGroupByName(name);
515515
if (oldGroup) {
516516
this.removePbxGroup(name, path);
@@ -523,6 +523,7 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
523523
isa: 'PBXGroup',
524524
children: [],
525525
name: name,
526+
path: path,
526527
sourceTree: sourceTree ? sourceTree : '"<group>"'
527528
},//path is mandatory only for the main group
528529
fileReferenceSection = this.pbxFileReferenceSection(),
@@ -551,23 +552,29 @@ pbxProject.prototype.addPbxGroup = function (filePathsArray, name, path, sourceT
551552

552553
var srcRootPath = $path.dirname($path.dirname(this.filepath));
553554
var file = new pbxFile($path.relative(srcRootPath, filePath));
554-
if (fs.lstatSync(filePath).isDirectory()) {
555+
if (fs.existsSync(filePath) && fs.lstatSync(filePath).isDirectory()) {
555556
file.uuid = this.generateUuid();
556557
file.fileRef = file.uuid;
557558
this.addToPbxFileReferenceSection(file); // PBXFileReference
558559
this.addToPbxBuildFileSection(file);
559560
pbxGroup.children.push(pbxGroupChild(file));
560561
var files = fs.readdirSync(filePath).map(p => $path.join(filePath, p));
561562
this.addPbxGroup(files, $path.basename(filePath), filePath, null, {uuid: file.uuid});
562-
}else if (isSourceOrHeaderFileType(file.lastType)) {
563+
} else if (isSourceOrHeaderFileType(file.lastKnownFileType)) {
563564
file.uuid = this.generateUuid();
564565
file.fileRef = this.generateUuid();
565566
this.addToPbxFileReferenceSection(file); // PBXFileReference
566567
this.addToPbxBuildFileSection(file); // PBXBuildFile
567-
if (!isHeaderFileType(file.lastType)) {
568+
if (!isHeaderFileType(file.lastKnownFileType)) {
568569
this.addToPbxSourcesBuildPhase(file);
569570
}
570571
pbxGroup.children.push(pbxGroupChild(file));
572+
} else {
573+
file.uuid = this.generateUuid();
574+
file.fileRef = this.generateUuid();
575+
this.addToPbxFileReferenceSection(file); // PBXFileReference
576+
this.addToPbxBuildFileSection(file);
577+
pbxGroup.children.push(pbxGroupChild(file));
571578
}
572579

573580
}
@@ -594,6 +601,8 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
594601
if (!group) {
595602
return;
596603
}
604+
605+
path = path || $path.dirname(this.filepath);
597606

598607
var children = group.children;
599608

@@ -607,10 +616,13 @@ pbxProject.prototype.removePbxGroup = function(groupName, path) {
607616
this.removeFromPbxSourcesBuildPhase(file);
608617
}
609618

610-
var mainGroupChildren = this.findMainPbxGroup().children, i;
611-
for(i in mainGroupChildren) {
612-
if (mainGroupChildren[i].comment == name) {
613-
mainGroupChildren.splice(i, 1);
619+
var mainGroup = this.findMainPbxGroup();
620+
if(mainGroup) {
621+
var mainGroupChildren = this.findMainPbxGroup().children, i;
622+
for(i in mainGroupChildren) {
623+
if (mainGroupChildren[i].comment == name) {
624+
mainGroupChildren.splice(i, 1);
625+
}
614626
}
615627
}
616628

@@ -1592,12 +1604,12 @@ function pbxFileReferenceObj(file) {
15921604
includeInIndex: file.includeInIndex
15931605
};
15941606

1595-
if(fileObject.name.indexOf("\"") !== -1) {
1607+
if(fileObject.name && fileObject.name.indexOf("\"") !== -1) {
15961608
fileObject.name = fileObject.name.replace(/\"/g, "\\\"");
15971609
fileObject.path = fileObject.path.replace(/\"/g, "\\\"");
15981610
}
15991611

1600-
if(!file.basename.match(NO_SPECIAL_SYMBOLS)) {
1612+
if(file.basename && !file.basename.match(NO_SPECIAL_SYMBOLS)) {
16011613
fileObject.name = "\"" + fileObject.name + "\"";
16021614
}
16031615

test/BuildSettings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/FrameworkSearchPaths.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
var pbxFile = {

test/HeaderSearchPaths.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/LibrarySearchPaths.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/OtherLinkerFlags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/addFramework.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -98,7 +98,7 @@ exports.addFramework = {
9898

9999
test.equal(fileRefEntry.isa, 'PBXFileReference');
100100
test.equal(fileRefEntry.lastKnownFileType, 'compiled.mach-o.dylib');
101-
test.equal(fileRefEntry.name, '"libsqlite3.dylib"');
101+
test.equal(fileRefEntry.name, 'libsqlite3.dylib');
102102
test.equal(fileRefEntry.path, '"usr/lib/libsqlite3.dylib"');
103103
test.equal(fileRefEntry.sourceTree, 'SDKROOT');
104104

test/addHeaderFile.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -70,8 +70,8 @@ exports.addHeaderFile = {
7070
test.equal(fileRefEntry.isa, 'PBXFileReference');
7171
test.equal(fileRefEntry.fileEncoding, 4);
7272
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h');
73-
test.equal(fileRefEntry.name, '"file.h"');
74-
test.equal(fileRefEntry.path, '"file.h"');
73+
test.equal(fileRefEntry.name, 'file.h');
74+
test.equal(fileRefEntry.path, 'file.h');
7575
test.equal(fileRefEntry.sourceTree, '"<group>"');
7676

7777
test.done();

test/addRemovePbxGroup.js

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ exports.addRemovePbxGroup = {
169169
proj.removePbxGroup(groupName);
170170

171171
var pbxGroupInPbx = proj.pbxGroupByName(groupName);
172-
console.log(pbxGroupInPbx);
173172

174173
test.ok(!pbxGroupInPbx);
175174
test.done()

test/addResourceFile.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -108,7 +108,7 @@ exports.addResourceFile = {
108108
test.equal(fileRefEntry.isa, 'PBXFileReference');
109109
test.equal(fileRefEntry.fileEncoding, undefined);
110110
test.equal(fileRefEntry.lastKnownFileType, 'wrapper.plug-in');
111-
test.equal(fileRefEntry.name, '"assets.bundle"');
111+
test.equal(fileRefEntry.name, 'assets.bundle');
112112
test.equal(fileRefEntry.path, '"Resources/assets.bundle"');
113113
test.equal(fileRefEntry.sourceTree, '"<group>"');
114114

@@ -169,7 +169,7 @@ exports.addResourceFile = {
169169
test.equal(fileRefEntry.isa, 'PBXFileReference');
170170
test.equal(fileRefEntry.fileEncoding, undefined);
171171
test.equal(fileRefEntry.lastKnownFileType, 'wrapper.plug-in');
172-
test.equal(fileRefEntry.name, '"assets.bundle"');
172+
test.equal(fileRefEntry.name, 'assets.bundle');
173173
test.equal(fileRefEntry.path, '"Plugins/assets.bundle"');
174174
test.equal(fileRefEntry.sourceTree, '"<group>"');
175175
test.done();

test/addSourceFile.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -106,8 +106,8 @@ exports.addSourceFile = {
106106
test.equal(fileRefEntry.isa, 'PBXFileReference');
107107
test.equal(fileRefEntry.fileEncoding, 4);
108108
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.objc');
109-
test.equal(fileRefEntry.name, '"file.m"');
110-
test.equal(fileRefEntry.path, '"file.m"');
109+
test.equal(fileRefEntry.name, 'file.m');
110+
test.equal(fileRefEntry.path, 'file.m');
111111
test.equal(fileRefEntry.sourceTree, '"<group>"');
112112

113113
test.done();

test/addStaticLibrary.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -140,8 +140,8 @@ exports.addStaticLibrary = {
140140

141141
test.equal(fileRefEntry.isa, 'PBXFileReference');
142142
test.equal(fileRefEntry.lastKnownFileType, 'archive.ar');
143-
test.equal(fileRefEntry.name, '"libGoogleAnalytics.a"');
144-
test.equal(fileRefEntry.path, '"libGoogleAnalytics.a"');
143+
test.equal(fileRefEntry.name, 'libGoogleAnalytics.a');
144+
test.equal(fileRefEntry.path, 'libGoogleAnalytics.a');
145145
test.equal(fileRefEntry.sourceTree, '"<group>"');
146146

147147
test.done();

test/addToPbxFileReferenceSection.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var jsonProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(jsonProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
myProj = new pbx('.');
2323

2424
function cleanHash() {
@@ -39,8 +39,8 @@ exports['addToPbxFileReferenceSection function'] = {
3939

4040
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].isa, 'PBXFileReference');
4141
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].lastKnownFileType, 'sourcecode.c.objc');
42-
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].name, '"file.m"');
43-
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].path, '"file.m"');
42+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].name, 'file.m');
43+
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].path, 'file.m');
4444
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].sourceTree, '"<group>"');
4545
test.equal(myProj.pbxFileReferenceSection()[file.fileRef].fileEncoding, 4);
4646
test.equal(myProj.pbxFileReferenceSection()[file.fileRef + "_comment"], 'file.m');

test/dataModelDocument.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var jsonProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(jsonProject),
2020
path = require('path'),
2121
pbx = require('../lib/pbxProject'),
22-
pbxFile = require('../lib/pbxFile'),
22+
pbxFile = require('../lib/pbxFile').pbxFile,
2323
proj = new pbx('.'),
2424
singleDataModelFilePath = __dirname + '/fixtures/single-data-model.xcdatamodeld',
2525
multipleDataModelFilePath = __dirname + '/fixtures/multiple-data-model.xcdatamodeld';

test/group.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
var pbx = require('../lib/pbxProject'),
19-
pbxFile = require('../lib/pbxFile'),
19+
pbxFile = require('../lib/pbxFile').pbxFile,
2020
project,
2121
projectHash;
2222

test/multipleTargets.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/multiple-targets')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/pbxFile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
under the License.
1616
*/
1717

18-
var pbxFile = require('../lib/pbxFile');
18+
var pbxFile = require('../lib/pbxFile').pbxFile;
1919

2020
exports['lastKnownFileType'] = {
2121
'should detect that a .m path means sourcecode.c.objc': function (test) {

test/pbxProject.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,14 @@
1818
var pbx = require('../lib/pbxProject'),
1919
buildConfig = require('./fixtures/buildFiles'),
2020
jsonProject = require('./fixtures/full-project'),
21+
fullProjectStr = JSON.stringify(jsonProject),
2122
fs = require('fs'),
2223
project;
2324

25+
function getCleanHash() {
26+
return JSON.parse(fullProjectStr);
27+
}
28+
2429
exports['creation'] = {
2530
'should create a pbxProject with the new operator': function (test) {
2631
var myProj = new pbx('test/parser/projects/hash.pbxproj');
@@ -332,7 +337,7 @@ exports['hasFile'] = {
332337
exports['addToPbxFileReferenceSection'] = {
333338
'should not quote name when no special characters present in basename': function (test) {
334339
var newProj = new pbx('.');
335-
newProj.hash = jsonProject,
340+
newProj.hash = getCleanHash(),
336341
file = {
337342
uuid: newProj.generateUuid(),
338343
fileRef: newProj.generateUuid(),
@@ -351,7 +356,7 @@ exports['addToPbxFileReferenceSection'] = {
351356
},
352357
'should quote name when special characters present in basename': function (test) {
353358
var newProj = new pbx('.');
354-
newProj.hash = jsonProject,
359+
newProj.hash = getCleanHash(),
355360
file = {
356361
uuid: newProj.generateUuid(),
357362
fileRef: newProj.generateUuid(),
@@ -370,7 +375,7 @@ exports['addToPbxFileReferenceSection'] = {
370375
},
371376
'should not quote path when no special characters present in path': function (test) {
372377
var newProj = new pbx('.');
373-
newProj.hash = jsonProject,
378+
newProj.hash = getCleanHash(),
374379
file = {
375380
uuid: newProj.generateUuid(),
376381
fileRef: newProj.generateUuid(),
@@ -389,7 +394,7 @@ exports['addToPbxFileReferenceSection'] = {
389394
},
390395
'should quote path when special characters present in path': function (test) {
391396
var newProj = new pbx('.');
392-
newProj.hash = jsonProject,
397+
newProj.hash = getCleanHash(),
393398
file = {
394399
uuid: newProj.generateUuid(),
395400
fileRef: newProj.generateUuid(),
@@ -408,7 +413,7 @@ exports['addToPbxFileReferenceSection'] = {
408413
},
409414
'should quote path and name when special characters present in path and basename': function (test) {
410415
var newProj = new pbx('.');
411-
newProj.hash = jsonProject,
416+
newProj.hash = getCleanHash(),
412417
file = {
413418
uuid: newProj.generateUuid(),
414419
fileRef: newProj.generateUuid(),

test/removeFramework.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project'),
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {

test/removeHeaderFile.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
var fullProject = require('./fixtures/full-project')
1919
fullProjectStr = JSON.stringify(fullProject),
2020
pbx = require('../lib/pbxProject'),
21-
pbxFile = require('../lib/pbxFile'),
21+
pbxFile = require('../lib/pbxFile').pbxFile,
2222
proj = new pbx('.');
2323

2424
function cleanHash() {
@@ -94,8 +94,8 @@ exports.removeHeaderFile = {
9494
test.equal(fileRefEntry.isa, 'PBXFileReference');
9595
test.equal(fileRefEntry.fileEncoding, 4);
9696
test.equal(fileRefEntry.lastKnownFileType, 'sourcecode.c.h');
97-
test.equal(fileRefEntry.name, '"file.h"');
98-
test.equal(fileRefEntry.path, '"file.h"');
97+
test.equal(fileRefEntry.name, 'file.h');
98+
test.equal(fileRefEntry.path, 'file.h');
9999
test.equal(fileRefEntry.sourceTree, '"<group>"');
100100

101101
var deletedFile = proj.removeHeaderFile('Plugins/file.h'),

0 commit comments

Comments
 (0)