Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Context generator #14

Merged
merged 14 commits into from
May 7, 2017
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ _None_
[David Jennes](https://github.com/djbe)
[#10](https://github.com/SwiftGen/SwiftGenKit/issues/10)
[#28](https://github.com/SwiftGen/SwiftGenKit/issues/28)
* We can now re-generate the contexts used for testing by using the "Generate Contexts" Xcode scheme.
[David Jennes](https://github.com/djbe)
[#14](https://github.com/SwiftGen/SwiftGenKit/issues/14)

## 1.0.1

Expand Down
6 changes: 6 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ CONFIGURATION = 'Debug'
POD_NAME = 'SwiftGenKit'


desc 'Generate Test Contexts'
task :generate_tasks => "xcode:build" do |task|
Utils.print_header 'Generating contexts...'
Utils.run(%Q(xcodebuild -workspace "#{WORKSPACE}.xcworkspace" -scheme "Generate Contexts" -configuration "#{CONFIGURATION}" test-without-building), task, xcrun: true, formatter: :xcpretty)
end

task :default => 'xcode:test'
2 changes: 1 addition & 1 deletion Sources/Parsers/AssetsCatalogParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ extension AssetsCatalogParser {
- Returns: An array of dictionaries, representing the tree of nodes in the catalog.
*/
fileprivate func loadAssetCatalog(at path: Path) -> [[String: Any]]? {
let command = Command("xcrun", arguments: "actool", "--print-contents", path.description)
let command = Command("xcrun", arguments: "actool", "--print-contents", path.string)
let output = command.execute() as Data

// try to parse plist
Expand Down
2 changes: 1 addition & 1 deletion Sources/Parsers/ColorsFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public final class ColorsCLRFileParser: ColorsFileParser {
public init() {}

public func parseFile(at path: Path) throws {
if let colorsList = NSColorList(name: "UserColors", fromFile: path.description) {
if let colorsList = NSColorList(name: "UserColors", fromFile: path.string) {
for colorName in colorsList.allKeys {
colors[colorName] = colorsList.color(withKey: colorName)?.rgbColor?.hexValue
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/Parsers/StringsFileParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import Foundation
import PathKit

public enum StringsFileParserError: Error, CustomStringConvertible {
case FailureOnLoading(path: String)
case InvalidFormat
case failureOnLoading(path: String)
case invalidFormat

public var description: String {
switch self {
case .FailureOnLoading(let path):
case .failureOnLoading(let path):
return "Failed to load a file at \"\(path)\""
case .InvalidFormat:
case .invalidFormat:
return "Invalid strings file"
}
}
Expand All @@ -33,14 +33,14 @@ public final class StringsFileParser {
// Localizable.strings files are generally UTF16, not UTF8!
public func parseFile(at path: Path) throws {
guard let data = try? path.read() else {
throw StringsFileParserError.FailureOnLoading(path: path.description)
throw StringsFileParserError.failureOnLoading(path: path.string)
}

let plist = try PropertyListSerialization
.propertyList(from: data, format: nil)

guard let dict = plist as? [String: String] else {
throw StringsFileParserError.InvalidFormat
throw StringsFileParserError.invalidFormat
}

for (key, translation) in dict {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0820"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "09A87B4F1BCCA2C600D9B9F5"
BuildableName = "Tests.xctest"
BlueprintName = "Tests"
ReferencedContainer = "container:SwiftGenKit.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<EnvironmentVariables>
<EnvironmentVariable
key = "GENERATE_CONTEXTS"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
12 changes: 3 additions & 9 deletions Tests/SwiftGenKitTests/ColorsCLRFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,23 @@ class ColorsCLRFileTests: XCTestCase {
let parser = ColorsCLRFileParser()

let result = parser.stencilContext()
let expected = Fixtures.context(for: "empty.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "empty.plist", sub: .colors)
}

func testFileWithDefaults() throws {
let parser = ColorsCLRFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.clr", sub: .colors))

let result = parser.stencilContext()
let expected = Fixtures.context(for: "defaults.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "defaults.plist", sub: .colors)
}

func testFileWithCustomName() throws {
let parser = ColorsCLRFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.clr", sub: .colors))

let result = parser.stencilContext(enumName: "XCTColors")
let expected = Fixtures.context(for: "customname.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "customname.plist", sub: .colors)
}

func testFileWithBadFile() {
Expand Down
12 changes: 3 additions & 9 deletions Tests/SwiftGenKitTests/ColorsJSONFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,23 @@ class ColorsJSONFileTests: XCTestCase {
let parser = ColorsJSONFileParser()

let result = parser.stencilContext()
let expected = Fixtures.context(for: "empty.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "empty.plist", sub: .colors)
}

func testFileWithDefaults() throws {
let parser = ColorsJSONFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.json", sub: .colors))

let result = parser.stencilContext()
let expected = Fixtures.context(for: "defaults.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "defaults.plist", sub: .colors)
}

func testFileWithCustomName() throws {
let parser = ColorsJSONFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.json", sub: .colors))

let result = parser.stencilContext(enumName: "XCTColors")
let expected = Fixtures.context(for: "customname.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "customname.plist", sub: .colors)
}

func testFileWithBadSyntax() {
Expand Down
16 changes: 4 additions & 12 deletions Tests/SwiftGenKitTests/ColorsTextFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ class ColorsTextFileTests: XCTestCase {
let parser = ColorsTextFileParser()

let result = parser.stencilContext()
let expected = Fixtures.context(for: "empty.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "empty.plist", sub: .colors)
}

func testListWithDefaults() throws {
Expand All @@ -26,29 +24,23 @@ class ColorsTextFileTests: XCTestCase {
try parser.addColor(named: "ArticleBackground", value: "#ffcc0099")

let result = parser.stencilContext()
let expected = Fixtures.context(for: "entries.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "entries.plist", sub: .colors)
}

func testFileWithDefaults() throws {
let parser = ColorsTextFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.txt", sub: .colors))

let result = parser.stencilContext()
let expected = Fixtures.context(for: "text-defaults.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "text-defaults.plist", sub: .colors)
}

func testFileWithCustomName() throws {
let parser = ColorsTextFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.txt", sub: .colors))

let result = parser.stencilContext(enumName: "XCTColors")
let expected = Fixtures.context(for: "text-customname.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "text-customname.plist", sub: .colors)
}

func testFileWithBadSyntax() {
Expand Down
12 changes: 3 additions & 9 deletions Tests/SwiftGenKitTests/ColorsXMLFileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,23 @@ class ColorsXMLFileTests: XCTestCase {
let parser = ColorsXMLFileParser()

let result = parser.stencilContext()
let expected = Fixtures.context(for: "empty.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "empty.plist", sub: .colors)
}

func testFileWithDefaults() throws {
let parser = ColorsXMLFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.xml", sub: .colors))

let result = parser.stencilContext()
let expected = Fixtures.context(for: "defaults.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "defaults.plist", sub: .colors)
}

func testFileWithCustomName() throws {
let parser = ColorsXMLFileParser()
try parser.parseFile(at: Fixtures.path(for: "colors.xml", sub: .colors))

let result = parser.stencilContext(enumName: "XCTColors")
let expected = Fixtures.context(for: "customname.plist", sub: .colors)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "customname.plist", sub: .colors)
}

func testFileWithBadSyntax() {
Expand Down
12 changes: 3 additions & 9 deletions Tests/SwiftGenKitTests/FontsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,22 @@ class FontsTests: XCTestCase {
let parser = FontsFileParser()

let result = parser.stencilContext()
let expected = Fixtures.context(for: "empty.plist", sub: .fonts)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "empty.plist", sub: .fonts)
}

func testDefaults() {
let parser = FontsFileParser()
parser.parseFile(at: Fixtures.directory(sub: .fonts))

let result = parser.stencilContext()
let expected = Fixtures.context(for: "defaults.plist", sub: .fonts)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "defaults.plist", sub: .fonts)
}

func testCustomName() {
let parser = FontsFileParser()
parser.parseFile(at: Fixtures.directory(sub: .fonts))

let result = parser.stencilContext(enumName: "CustomFamily")
let expected = Fixtures.context(for: "customname.plist", sub: .fonts)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "customname.plist", sub: .fonts)
}
}
12 changes: 3 additions & 9 deletions Tests/SwiftGenKitTests/ImagesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,22 @@ class ImagesTests: XCTestCase {
let parser = AssetsCatalogParser()

let result = parser.stencilContext()
let expected = Fixtures.context(for: "empty.plist", sub: .images)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "empty.plist", sub: .images)
}

func testFileWithDefaults() {
let parser = AssetsCatalogParser()
parser.parseCatalog(at: Fixtures.path(for: "Images.xcassets", sub: .images))

let result = parser.stencilContext()
let expected = Fixtures.context(for: "defaults.plist", sub: .images)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "defaults.plist", sub: .images)
}

func testFileWithCustomName() {
let parser = AssetsCatalogParser()
parser.parseCatalog(at: Fixtures.path(for: "Images.xcassets", sub: .images))

let result = parser.stencilContext(enumName: "XCTImages")
let expected = Fixtures.context(for: "customname.plist", sub: .images)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "customname.plist", sub: .images)
}
}
20 changes: 5 additions & 15 deletions Tests/SwiftGenKitTests/StoryboardsMacOSTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class StoryboardsMacOSTests: XCTestCase {
let parser = StoryboardParser()

let result = parser.stencilContext()
let expected = Fixtures.context(for: "empty.plist", sub: .storyboardsMacOS)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "empty.plist", sub: .storyboardsMacOS)
}

func testMessageStoryboardWithDefaults() {
Expand All @@ -32,9 +30,7 @@ class StoryboardsMacOSTests: XCTestCase {
}

let result = parser.stencilContext()
let expected = Fixtures.context(for: "messages.plist", sub: .storyboardsMacOS)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "messages.plist", sub: .storyboardsMacOS)
}

func testAnonymousStoryboardWithDefaults() {
Expand All @@ -46,9 +42,7 @@ class StoryboardsMacOSTests: XCTestCase {
}

let result = parser.stencilContext()
let expected = Fixtures.context(for: "anonymous.plist", sub: .storyboardsMacOS)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "anonymous.plist", sub: .storyboardsMacOS)
}

func testAllStoryboardsWithDefaults() {
Expand All @@ -60,9 +54,7 @@ class StoryboardsMacOSTests: XCTestCase {
}

let result = parser.stencilContext()
let expected = Fixtures.context(for: "all.plist", sub: .storyboardsMacOS)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "all.plist", sub: .storyboardsMacOS)
}

func testAllStoryboardsWithCustomName() {
Expand All @@ -74,8 +66,6 @@ class StoryboardsMacOSTests: XCTestCase {
}

let result = parser.stencilContext(sceneEnumName: "XCTStoryboardsScene", segueEnumName: "XCTStoryboardsSegue")
let expected = Fixtures.context(for: "customname.plist", sub: .storyboardsMacOS)

XCTDiffContexts(result, expected)
XCTDiffContexts(result, expected: "customname.plist", sub: .storyboardsMacOS)
}
}
Loading