diff --git a/Fixtures/TestProject/TestProject/Base.lproj/LocalizedStoryboard.storyboard b/Fixtures/TestProject/TestProject/Base.lproj/LocalizedStoryboard.storyboard new file mode 100644 index 000000000..f9a048edf --- /dev/null +++ b/Fixtures/TestProject/TestProject/Base.lproj/LocalizedStoryboard.storyboard @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Fixtures/TestProject/TestProject/en.lproj/LocalizedStoryboard.strings b/Fixtures/TestProject/TestProject/en.lproj/LocalizedStoryboard.strings new file mode 100644 index 000000000..8b1378917 --- /dev/null +++ b/Fixtures/TestProject/TestProject/en.lproj/LocalizedStoryboard.strings @@ -0,0 +1 @@ + diff --git a/Tests/XcodeGenKitTests/FixtureTests.swift b/Tests/XcodeGenKitTests/FixtureTests.swift index 644319afe..8fad85429 100644 --- a/Tests/XcodeGenKitTests/FixtureTests.swift +++ b/Tests/XcodeGenKitTests/FixtureTests.swift @@ -6,7 +6,7 @@ import ProjectSpec let fixturePath = Path(#file).parent().parent().parent() + "Fixtures" -func generate(specPath: Path, projectPath: Path) throws { +func generate(specPath: Path, projectPath: Path) throws -> XcodeProj { let spec = try ProjectSpec(path: specPath) let generator = ProjectGenerator(spec: spec, path: specPath.parent()) let project = try generator.generateProject() @@ -17,13 +17,47 @@ func generate(specPath: Path, projectPath: Path) throws { if newProject != oldProject { throw failure("\(projectPath.string) has changed. If change is legitimate commit the change and run test again") } + + return newProject } func fixtureTests() { describe("Test Project") { + var project: XcodeProj? + $0.it("generates") { - try generate(specPath: fixturePath + "TestProject/spec.yml", projectPath: fixturePath + "TestProject/GeneratedProject.xcodeproj") + project = try generate(specPath: fixturePath + "TestProject/spec.yml", projectPath: fixturePath + "TestProject/GeneratedProject.xcodeproj") + } + + $0.it("generates variant group") { + guard let project = project else { throw failure("Project is not generated") } + + func getFileReferences(_ path: String) -> [PBXFileReference] { + return project.pbxproj.fileReferences.filter { $0.path == path } + } + + func getVariableGroups(_ name: String?) -> [PBXVariantGroup] { + return project.pbxproj.variantGroups.filter { $0.name == name } + } + + let resourceName = "LocalizedStoryboard.storyboard" + let baseResource = "Base.lproj/LocalizedStoryboard.storyboard" + let localizedResource = "en.lproj/LocalizedStoryboard.strings" + + guard let variableGroup = getVariableGroups(resourceName).first else { throw failure("Couldn't find the variable group") } + + do { + let refs = getFileReferences(baseResource) + try expect(refs.count) == 1 + try expect(variableGroup.children.filter { $0 == refs.first?.reference }.count) == 1 + } + + do { + let refs = getFileReferences(localizedResource) + try expect(refs.count) == 1 + try expect(variableGroup.children.filter { $0 == refs.first?.reference }.count) == 1 + } } } }