Skip to content

Commit

Permalink
add test for variant groups
Browse files Browse the repository at this point in the history
  • Loading branch information
ryohey committed Oct 16, 2017
1 parent 2f2c89e commit bc9c007
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/>
</dependencies>
<scenes/>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

38 changes: 36 additions & 2 deletions Tests/XcodeGenKitTests/FixtureTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
}
}
}

0 comments on commit bc9c007

Please sign in to comment.