/* Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ const { describe, it, beforeEach } = require('node:test'); const assert = require('node:assert'); const fullProject = require('./fixtures/full-project'); const fullProjectStr = JSON.stringify(fullProject); const PBXProject = require('../lib/pbxProject'); const proj = new PBXProject('.'); const debugConfiguration = { isa: 'XCBuildConfiguration', buildSettings: { GCC_PREPROCESSOR_DEFINITIONS: [ '"DEBUG=1"', '"$(inherited)"' ], INFOPLIST_FILE: 'Info.Plist', LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', PRODUCT_NAME: '"${TARGET_NAME}"', // eslint-disable-line no-template-curly-in-string SKIP_INSTALL: 'YES' }, name: 'Debug' }; const releaseConfiguration = { isa: 'XCBuildConfiguration', buildSettings: { INFOPLIST_FILE: 'Info.Plist', LD_RUNPATH_SEARCH_PATHS: '"$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"', PRODUCT_NAME: '"${TARGET_NAME}"', // eslint-disable-line no-template-curly-in-string SKIP_INSTALL: 'YES' }, name: 'Release' }; function cleanHash () { return JSON.parse(fullProjectStr); } describe('addXCConfigurationList', () => { beforeEach(() => { proj.hash = cleanHash(); }); it('should return an XCConfigurationList', () => { const myProj = new PBXProject('test/parser/projects/full.pbxproj').parseSync(); const xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); assert.ok(typeof xcConfigurationList === 'object'); }); it('should set a uuid on the XCConfigurationList', () => { const myProj = new PBXProject('test/parser/projects/full.pbxproj').parseSync(); const xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); assert.ok(xcConfigurationList.uuid); }); it('should add configurations to pbxBuildConfigurationSection', () => { const myProj = new PBXProject('test/parser/projects/full.pbxproj').parseSync(); const pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(); const xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); const xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations; for (let index = 0; index < xcConfigurationListConfigurations.length; index++) { const configuration = xcConfigurationListConfigurations[index]; assert.ok(pbxBuildConfigurationSection[configuration.value]); } }); it('should add XCConfigurationList to pbxXCConfigurationListSection', () => { const myProj = new PBXProject('test/parser/projects/full.pbxproj').parseSync(); const pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); const xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); assert.ok(pbxXCConfigurationListSection[xcConfigurationList.uuid]); }); it('should add XCConfigurationList object correctly', () => { const myProj = new PBXProject('test/parser/projects/full.pbxproj').parseSync(); const pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); const xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); const xcConfigurationListInPbx = pbxXCConfigurationListSection[xcConfigurationList.uuid]; assert.deepEqual(xcConfigurationListInPbx, xcConfigurationList.xcConfigurationList); }); it('should add correct configurations to XCConfigurationList and to pbxBuildConfigurationSection', () => { const myProj = new PBXProject('test/parser/projects/full.pbxproj').parseSync(); const pbxXCConfigurationListSection = myProj.pbxXCConfigurationList(); const pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(); const xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); const xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations; const expectedConfigurations = []; const xcConfigurationListInPbx = pbxXCConfigurationListSection[xcConfigurationList.uuid]; for (let index = 0; index < xcConfigurationListConfigurations.length; index++) { const configuration = xcConfigurationListConfigurations[index]; expectedConfigurations.push(pbxBuildConfigurationSection[configuration.value]); } assert.deepEqual(expectedConfigurations, [debugConfiguration, releaseConfiguration]); assert.deepEqual(xcConfigurationListInPbx.buildConfigurations, xcConfigurationListConfigurations); }); it('should set comments for pbxBuildConfigurations', () => { const myProj = new PBXProject('test/parser/projects/full.pbxproj').parseSync(); const pbxBuildConfigurationSection = myProj.pbxXCBuildConfigurationSection(); const xcConfigurationList = myProj.addXCConfigurationList([debugConfiguration, releaseConfiguration], 'Release', 'XCConfigurationList Comment'); const xcConfigurationListConfigurations = xcConfigurationList.xcConfigurationList.buildConfigurations; for (let index = 0; index < xcConfigurationListConfigurations.length; index++) { const configuration = xcConfigurationListConfigurations[index]; assert.ok(pbxBuildConfigurationSection[configuration.value + '_comment']); } }); });