Files
XcodeGen/Tests/ProjectSpecTests/InvalidConfigsFormatTests.swift
Ryu 53cb43cb66 Add validation to ensure that settings.configs values are dictionaries, in order to prevent misuse (#1547)
* Add validation to ensure settings.configs values are dictionaries to prevent misuse

* Add tests for invalid settings.configs value formats

* Replaced with filter and split into a function

* Rename invalidConfigsFormat to invalidConfigsMappingFormat

* Add comments to explain invalid  fixture

* Rename test fixture

* Update CHANGELOG.md

* Correct grammer

* Use KeyPath instead of closure

* Rename validateMappingStyleInConfig to extractValidConfigs

* Add a document comment for extractValidConfigs(from:)

* Use old testing api and remove EquatableErrorBox

* Rename test case to use "mapping" instead of "dictionary"

* Add ValidSettingsExtractor to encapsulate the logic for converting a dictionary to Settings

* Add settings validation for both Target and AggregateTarget

* Add tests for invalid settings.configs in Target and AggregateTarget

* Add document comments for ValidSettingsExtractor

* Rename ValidSettingsExtractor to BuildSettingsExtractor

* Add settings validation for settingGroups

* Add tests for settingGroups

* Rename extract to parse

* Refactor

* Update Tests/ProjectSpecTests/InvalidConfigsFormatTests.swift

---------

Co-authored-by: Yonas Kolb <yonaskolb@users.noreply.github.com>
2025-06-07 00:23:21 +10:00

44 lines
1.9 KiB
Swift

import ProjectSpec
import Testing
import TestSupport
import PathKit
struct InvalidConfigsMappingFormatTests {
struct InvalidConfigsTestArguments {
var fixturePath: Path
var expectedError: SpecParsingError
}
private static var testArguments: [InvalidConfigsTestArguments] {
let invalidConfigsFixturePath: Path = fixturePath + "invalid_configs"
return [
InvalidConfigsTestArguments(
fixturePath: invalidConfigsFixturePath + "invalid_configs_value_non_mapping_settings.yml",
expectedError: SpecParsingError.invalidConfigsMappingFormat(keys: ["invalid_key0", "invalid_key1"])
),
InvalidConfigsTestArguments(
fixturePath: invalidConfigsFixturePath + "invalid_configs_value_non_mapping_targets.yml",
expectedError: SpecParsingError.invalidConfigsMappingFormat(keys: ["invalid_key0", "invalid_key1"])
),
InvalidConfigsTestArguments(
fixturePath: invalidConfigsFixturePath + "invalid_configs_value_non_mapping_aggregate_targets.yml",
expectedError: SpecParsingError.invalidConfigsMappingFormat(keys: ["invalid_key0", "invalid_key1"])
),
InvalidConfigsTestArguments(
fixturePath: invalidConfigsFixturePath + "invalid_configs_value_non_mapping_setting_groups.yml",
expectedError: SpecParsingError.invalidConfigsMappingFormat(keys: ["invalid_key0", "invalid_key1"])
)
]
}
@Test("throws invalidConfigsMappingFormat for non-mapping configs entries", arguments: testArguments)
func testInvalidConfigsMappingFormat(_ arguments: InvalidConfigsTestArguments) throws {
#expect {
try Project(path: arguments.fixturePath)
} throws: { actualError in
(actualError as any CustomStringConvertible).description
== arguments.expectedError.description
}
}
}