|
| 1 | +/* |
| 2 | + This source file is part of the Swift.org open source project |
| 3 | + |
| 4 | + Copyright 2015 - 2016 Apple Inc. and the Swift project authors |
| 5 | + Licensed under Apache License v2.0 with Runtime Library Exception |
| 6 | + |
| 7 | + See http://swift.org/LICENSE.txt for license information |
| 8 | + See http://swift.org/CONTRIBUTORS.txt for Swift project authors |
| 9 | + */ |
| 10 | + |
| 11 | +import func POSIX.mkdtemp |
| 12 | +import PackageType |
| 13 | +import Xcodeproj |
| 14 | +import Utility |
| 15 | +import XCTest |
| 16 | + |
| 17 | + |
| 18 | +// copy pasta |
| 19 | +func mktmpdir(file: StaticString = #file, line: UInt = #line, @noescape body: (String) throws -> Void) { |
| 20 | + do { |
| 21 | + try POSIX.mkdtemp("spm-tests") { dir in |
| 22 | + defer { _ = try? rmtree(dir) } |
| 23 | + try body(dir) |
| 24 | + } |
| 25 | + } catch { |
| 26 | + XCTFail("\(error)", file: file, line: line) |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +func XCTAssertDirectoryExists(paths: String..., file: StaticString = #file, line: UInt = #line) { |
| 31 | + let path = Path.join(paths) |
| 32 | + if !path.isDirectory { |
| 33 | + XCTFail("Expected directory doesn’t exist: \(path)", file: file, line: line) |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +#if os(OSX) |
| 39 | +class TestGeneration: XCTestCase { |
| 40 | + |
| 41 | + /// --> this comment is here <-- |
| 42 | + |
| 43 | + func testXcodeBuildCanParseIt() { |
| 44 | + mktmpdir { dstdir in |
| 45 | + func dummy() -> [SwiftModule] { |
| 46 | + return [SwiftModule(name: "DummyModuleName", sources: Sources(paths: [], root: dstdir))] |
| 47 | + } |
| 48 | + |
| 49 | + let projectName = "DummyProjectName" |
| 50 | + let srcroot = dstdir |
| 51 | + let modules = dummy() |
| 52 | + let products: [Product] = [] |
| 53 | + |
| 54 | + let outpath = try Xcodeproj.generate(dstdir: dstdir, projectName: projectName, srcroot: srcroot, modules: modules, products: products) |
| 55 | + |
| 56 | + XCTAssertDirectoryExists(outpath) |
| 57 | + XCTAssertEqual(outpath, Path.join(dstdir, "\(projectName).xcodeproj")) |
| 58 | + |
| 59 | + let output = try popen(["xcodebuild", "-list", "-project", outpath]) |
| 60 | + |
| 61 | + let expectedOutput = "Information about project \"DummyProjectName\":\n Targets:\n DummyModuleName\n\n Build Configurations:\n Debug\n\n If no build configuration is specified and -scheme is not passed then \"Debug\" is used.\n\n Schemes:\n DummyProjectName\n" |
| 62 | + |
| 63 | + XCTAssertEqual(output, expectedOutput) |
| 64 | + } |
| 65 | + } |
| 66 | +} |
| 67 | +#endif |
0 commit comments