Remove Playground generator.

This commit is contained in:
Marek Fořt 2020-03-03 16:26:38 +01:00
parent db24a79e0f
commit ee38f21d6a
3 changed files with 0 additions and 179 deletions

View File

@ -1,78 +0,0 @@
import Basic
import Foundation
import TuistCore
import TuistGenerator
import TuistSupport
enum PlaygroundGenerationError: FatalError, Equatable {
case alreadyExisting(AbsolutePath)
var description: String {
switch self {
case let .alreadyExisting(path):
return "A playground already exists at path \(path.pathString)"
}
}
var type: ErrorType {
switch self {
case .alreadyExisting: return .abort
}
}
static func == (lhs: PlaygroundGenerationError, rhs: PlaygroundGenerationError) -> Bool {
switch (lhs, rhs) {
case let (.alreadyExisting(lhsPath), .alreadyExisting(rhsPath)):
return lhsPath == rhsPath
}
}
}
protocol PlaygroundGenerating: AnyObject {
func generate(path: AbsolutePath,
name: String,
platform: Platform,
content: String) throws
}
final class PlaygroundGenerator: PlaygroundGenerating {
func generate(path: AbsolutePath,
name: String,
platform: Platform,
content: String = PlaygroundGenerator.defaultContent()) throws {
let playgroundPath = path.appending(component: "\(name).playground")
if FileHandler.shared.exists(playgroundPath) {
throw PlaygroundGenerationError.alreadyExisting(playgroundPath)
}
try FileHandler.shared.createFolder(playgroundPath)
let xcplaygroundPath = playgroundPath.appending(component: "contents.xcplayground")
let contentsPath = playgroundPath.appending(component: "Contents.swift")
try content.write(to: contentsPath.url, atomically: true, encoding: .utf8)
try PlaygroundGenerator.xcplaygroundContent(platform: platform)
.write(to: xcplaygroundPath.url,
atomically: true,
encoding: .utf8)
}
static func defaultContent() -> String {
"""
//: Playground - noun: a place where people can play
import Foundation
"""
}
static func xcplaygroundContent(platform: TuistCore.Platform) -> String {
"""
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='\(platform.rawValue.lowercased())'>
<timeline fileName='timeline.xctimeline'/>
</playground>
"""
}
}

View File

@ -1,19 +0,0 @@
import Basic
import Foundation
import TuistCore
import TuistGenerator
@testable import TuistKit
final class MockPlaygroundGenerator: PlaygroundGenerating {
var generateCallCount: UInt = 0
var generateStub: Error?
var generateArgs: [(AbsolutePath, String, Platform, String)] = []
func generate(path: AbsolutePath, name: String, platform: Platform, content: String) throws {
generateCallCount += 1
generateArgs.append((path, name, platform, content))
if let generateStub = generateStub {
throw generateStub
}
}
}

View File

@ -1,82 +0,0 @@
import Basic
import Foundation
import TuistSupport
import XCTest
@testable import TuistKit
@testable import TuistSupportTesting
final class PlaygroundGenerationErrorTests: XCTestCase {
func test_description() {
XCTAssertEqual(PlaygroundGenerationError.alreadyExisting(AbsolutePath("/test.playground")).description, "A playground already exists at path /test.playground")
}
func test_type() {
XCTAssertEqual(PlaygroundGenerationError.alreadyExisting(AbsolutePath("/test.playground")).type, .abort)
}
}
final class PlaygroundGeneratorTests: TuistUnitTestCase {
var subject: PlaygroundGenerator!
override func setUp() {
super.setUp()
subject = PlaygroundGenerator()
}
override func tearDown() {
subject = nil
super.tearDown()
}
func test_generate_throws_when_playground_exists() throws {
let temporaryPath = try self.temporaryPath()
let playgroundPath = temporaryPath.appending(component: "Test.playground")
try FileHandler.shared.createFolder(playgroundPath)
XCTAssertThrowsSpecific(try subject.generate(path: temporaryPath,
name: "Test",
platform: .iOS),
PlaygroundGenerationError.alreadyExisting(playgroundPath))
}
func test_generate_writes_content() throws {
let temporaryPath = try self.temporaryPath()
let playgroundPath = temporaryPath.appending(component: "Test.playground")
try subject.generate(path: temporaryPath,
name: "Test",
platform: .iOS,
content: "Test")
let contentsPath = playgroundPath.appending(component: "Contents.swift")
let content = try String(contentsOf: contentsPath.url,
encoding: .utf8)
XCTAssertEqual(content, "Test")
}
func test_generate_writes_default_content() throws {
let temporaryPath = try self.temporaryPath()
let playgroundPath = temporaryPath.appending(component: "Test.playground")
try subject.generate(path: temporaryPath,
name: "Test",
platform: .iOS)
let contentsPath = playgroundPath.appending(component: "Contents.swift")
let content = try String(contentsOf: contentsPath.url,
encoding: .utf8)
XCTAssertEqual(content, PlaygroundGenerator.defaultContent())
}
func test_generate_writes_xcplayground() throws {
let temporaryPath = try self.temporaryPath()
let playgroundPath = temporaryPath.appending(component: "Test.playground")
try subject.generate(path: temporaryPath,
name: "Test",
platform: .iOS)
let xcplaygroundPath = playgroundPath.appending(component: "contents.xcplayground")
let xcplayground = try String(contentsOf: xcplaygroundPath.url,
encoding: .utf8)
XCTAssertEqual(xcplayground, PlaygroundGenerator.xcplaygroundContent(platform: .iOS))
}
}