Skip to content

Internal pbxProject.prototype.addTarget function not properly tested #75

@brody4hire

Description

@brody4hire

Through Stryker mutation testing (see PR #61) of watch2 support (PR #56), I discovered that the internal pbxProject.prototype.addTarget function is not properly tested. Here are some possible mutations that would not be detected by the existing test suite:

diff --git a/lib/pbxProject.js b/lib/pbxProject.js
index be9f473..1693b74 100644
--- a/lib/pbxProject.js
+++ b/lib/pbxProject.js
@@ -1393,54 +1393,22 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
         targetSubfolder = subfolder || name,
         targetName = name.trim();
 
-    // Check type against list of allowed target types
-    if (!targetName) {
-        throw new Error("Target name missing.");
-    }
-
     // Check type against list of allowed target types
     if (!targetType) {
         throw new Error("Target type missing.");
     }
 
-    // Check type against list of allowed target types
-    if (!producttypeForTargettype(targetType)) {
-        throw new Error("Target type invalid: " + targetType);
-    }
-
     // Build Configuration: Create
-    var buildConfigurationsList = [
-        {
-            name: 'Debug',
-            isa: 'XCBuildConfiguration',
-            buildSettings: {
-                GCC_PREPROCESSOR_DEFINITIONS: ['"DEBUG=1"', '"$(inherited)"'],
-                INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'),
-                LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"',
-                PRODUCT_NAME: '"' + targetName + '"',
-                SKIP_INSTALL: 'YES'
-            }
-        },
-        {
-            name: 'Release',
-            isa: 'XCBuildConfiguration',
-            buildSettings: {
-                INFOPLIST_FILE: '"' + path.join(targetSubfolder, targetSubfolder + '-Info.plist' + '"'),
-                LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"',
-                PRODUCT_NAME: '"' + targetName + '"',
-                SKIP_INSTALL: 'YES'
-            }
-        }
-    ];
+    var buildConfigurationsList = [];
 
     // Build Configuration: Add
-    var buildConfigurations = this.addXCConfigurationList(buildConfigurationsList, 'Release', 'Build configuration list for PBXNativeTarget "' + targetName +'"');
+    var buildConfigurations = this.addXCConfigurationList(buildConfigurationsList, '', '');
 
     // Product: Create
     var productName = targetName,
         productType = producttypeForTargettype(targetType),
         productFileType = filetypeForProducttype(productType),
-        productFile = this.addProductFile(productName, { group: 'Copy Files', 'target': targetUuid, 'explicitFileType': productFileType}),
+        productFile = this.addProductFile(productName, { group: '', 'explicitFileType': productFileType}),
         productFileName = productFile.basename;
 
 
@@ -1452,8 +1420,8 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
             uuid: targetUuid,
             pbxNativeTarget: {
                 isa: 'PBXNativeTarget',
-                name: '"' + targetName + '"',
-                productName: '"' + targetName + '"',
+                name: '"',
+                productName: '"',
                 productReference: productFile.fileRef,
                 productType: '"' + producttypeForTargettype(targetType) + '"',
                 buildConfigurationList: buildConfigurations.uuid,
@@ -1483,7 +1451,7 @@ pbxProject.prototype.addTarget = function(name, type, subfolder) {
     this.addToPbxProjectSection(target);
 
     // Target: Add dependency for this target to first (main) target
-    this.addTargetDependency(this.getFirstTarget().uuid, [target.uuid]);
+    this.addTargetDependency(this.getFirstTarget().uuid, []);
 
 
     // Return target on success

Note that this diff includes the untested mutation that I reported in #73.

Considering that this function seems to play an important role in of the watch2 support, I would like to see it properly tested in the near future. However, I do not think that this should block merge of PR #56.

/cc @l3ender

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions