|
1 | 1 | /*
|
2 | 2 | This source file is part of the Swift.org open source project
|
3 | 3 |
|
4 |
| - Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors |
| 4 | + Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors |
5 | 5 | Licensed under Apache License v2.0 with Runtime Library Exception
|
6 | 6 |
|
7 | 7 | See http://swift.org/LICENSE.txt for license information
|
@@ -29,15 +29,18 @@ class GenerateXcodeprojTests: XCTestCase {
|
29 | 29 | func testXcodebuildCanParseIt() {
|
30 | 30 | #if os(macOS)
|
31 | 31 | mktmpdir { dstdir in
|
32 |
| - let fileSystem = InMemoryFileSystem(emptyFiles: "/Sources/DummyModuleName/source.swift") |
| 32 | + let packagePath = dstdir.appending(component: "foo") |
| 33 | + let modulePath = packagePath.appending(components: "Sources", "DummyModuleName") |
| 34 | + try makeDirectories(modulePath) |
| 35 | + try localFileSystem.writeFileContents(modulePath.appending(component: "source.swift"), bytes: "") |
33 | 36 |
|
34 | 37 | let diagnostics = DiagnosticsEngine()
|
35 |
| - let graph = loadPackageGraph(fs: fileSystem, diagnostics: diagnostics, |
| 38 | + let graph = loadPackageGraph(fs: localFileSystem, diagnostics: diagnostics, |
36 | 39 | manifests: [
|
37 | 40 | Manifest.createV4Manifest(
|
38 | 41 | name: "Foo",
|
39 |
| - path: "/", |
40 |
| - url: "/foo", |
| 42 | + path: packagePath.pathString, |
| 43 | + url: packagePath.pathString, |
41 | 44 | packageKind: .root,
|
42 | 45 | targets: [
|
43 | 46 | TargetDescription(name: "DummyModuleName"),
|
@@ -77,63 +80,72 @@ class GenerateXcodeprojTests: XCTestCase {
|
77 | 80 | }
|
78 | 81 |
|
79 | 82 | func testXcconfigOverrideValidatesPath() throws {
|
80 |
| - let fileSystem = InMemoryFileSystem(emptyFiles: "/Bar/Sources/Bar/bar.swift") |
81 |
| - let diagnostics = DiagnosticsEngine() |
82 |
| - let graph = loadPackageGraph(fs: fileSystem, diagnostics: diagnostics, |
83 |
| - manifests: [ |
84 |
| - Manifest.createV4Manifest( |
85 |
| - name: "Bar", |
86 |
| - path: "/Bar", |
87 |
| - url: "/Bar", |
88 |
| - packageKind: .root, |
89 |
| - targets: [ |
90 |
| - TargetDescription(name: "Bar"), |
91 |
| - ]) |
92 |
| - ] |
93 |
| - ) |
94 |
| - XCTAssertNoDiagnostics(diagnostics) |
95 |
| - |
96 |
| - let options = XcodeprojOptions(xcconfigOverrides: AbsolutePath("/doesntexist")) |
97 |
| - do { |
98 |
| - _ = try xcodeProject(xcodeprojPath: AbsolutePath.root.appending(component: "xcodeproj"), |
99 |
| - graph: graph, extraDirs: [], extraFiles: [], options: options, fileSystem: fileSystem, diagnostics: diagnostics) |
100 |
| - XCTFail("Project generation should have failed") |
101 |
| - } catch ProjectGenerationError.xcconfigOverrideNotFound(let path) { |
102 |
| - XCTAssertEqual(options.xcconfigOverrides, path) |
103 |
| - } catch { |
104 |
| - XCTFail("Project generation shouldn't have had another error") |
| 83 | + mktmpdir { dstdir in |
| 84 | + let packagePath = dstdir.appending(component: "Bar") |
| 85 | + let modulePath = packagePath.appending(components: "Sources", "Bar") |
| 86 | + try makeDirectories(modulePath) |
| 87 | + try localFileSystem.writeFileContents(modulePath.appending(component: "bar.swift"), bytes: "") |
| 88 | + |
| 89 | + let diagnostics = DiagnosticsEngine() |
| 90 | + let graph = loadPackageGraph(fs: localFileSystem, diagnostics: diagnostics, |
| 91 | + manifests: [ |
| 92 | + Manifest.createV4Manifest( |
| 93 | + name: "Bar", |
| 94 | + path: packagePath.pathString, |
| 95 | + url: packagePath.pathString, |
| 96 | + packageKind: .root, |
| 97 | + targets: [ |
| 98 | + TargetDescription(name: "Bar"), |
| 99 | + ]) |
| 100 | + ] |
| 101 | + ) |
| 102 | + XCTAssertNoDiagnostics(diagnostics) |
| 103 | + |
| 104 | + let options = XcodeprojOptions(xcconfigOverrides: AbsolutePath("/doesntexist")) |
| 105 | + do { |
| 106 | + _ = try xcodeProject(xcodeprojPath: AbsolutePath.root.appending(component: "xcodeproj"), |
| 107 | + graph: graph, extraDirs: [], extraFiles: [], options: options, fileSystem: localFileSystem, diagnostics: diagnostics) |
| 108 | + XCTFail("Project generation should have failed") |
| 109 | + } catch ProjectGenerationError.xcconfigOverrideNotFound(let path) { |
| 110 | + XCTAssertEqual(options.xcconfigOverrides, path) |
| 111 | + } catch { |
| 112 | + XCTFail("Project generation shouldn't have had another error") |
| 113 | + } |
105 | 114 | }
|
106 | 115 | }
|
107 | 116 |
|
108 | 117 | func testGenerateXcodeprojWithInvalidModuleNames() throws {
|
109 |
| - let warningStream = BufferedOutputByteStream() |
110 |
| - let fileSystem = InMemoryFileSystem( |
111 |
| - emptyFiles: "/Bar/Sources/Modules/example.swift" |
112 |
| - ) |
113 |
| - |
114 |
| - let diagnostics = DiagnosticsEngine() |
115 |
| - let graph = loadPackageGraph(fs: fileSystem, diagnostics: diagnostics, |
116 |
| - manifests: [ |
117 |
| - Manifest.createV4Manifest( |
118 |
| - name: "Modules", |
119 |
| - path: "/Bar", |
120 |
| - url: "/Bar", |
121 |
| - packageKind: .root, |
122 |
| - targets: [ |
123 |
| - TargetDescription(name: "Modules"), |
124 |
| - ]) |
125 |
| - ] |
126 |
| - ) |
127 |
| - XCTAssertNoDiagnostics(diagnostics) |
128 |
| - |
129 |
| - _ = try xcodeProject( |
130 |
| - xcodeprojPath: AbsolutePath.root.appending(component: "xcodeproj"), |
131 |
| - graph: graph, extraDirs: [], extraFiles: [], |
132 |
| - options: XcodeprojOptions(), fileSystem: fileSystem, |
133 |
| - diagnostics: diagnostics, warningStream: warningStream) |
134 |
| - |
135 |
| - let warnings = warningStream.bytes.description |
136 |
| - XCTAssertMatch(warnings, .contains("warning: Target 'Modules' conflicts with required framework filenames, rename this target to avoid conflicts.")) |
| 118 | + mktmpdir { dstdir in |
| 119 | + let packagePath = dstdir.appending(component: "Bar") |
| 120 | + let modulePath = packagePath.appending(components: "Sources", "Modules") |
| 121 | + try makeDirectories(modulePath) |
| 122 | + try localFileSystem.writeFileContents(modulePath.appending(component: "example.swift"), bytes: "") |
| 123 | + |
| 124 | + let diagnostics = DiagnosticsEngine() |
| 125 | + let graph = loadPackageGraph(fs: localFileSystem, diagnostics: diagnostics, |
| 126 | + manifests: [ |
| 127 | + Manifest.createV4Manifest( |
| 128 | + name: "Modules", |
| 129 | + path: packagePath.pathString, |
| 130 | + url: packagePath.pathString, |
| 131 | + packageKind: .root, |
| 132 | + targets: [ |
| 133 | + TargetDescription(name: "Modules"), |
| 134 | + ]) |
| 135 | + ] |
| 136 | + ) |
| 137 | + XCTAssertNoDiagnostics(diagnostics) |
| 138 | + |
| 139 | + let warningStream = BufferedOutputByteStream() |
| 140 | + _ = try xcodeProject( |
| 141 | + xcodeprojPath: AbsolutePath.root.appending(component: "xcodeproj"), |
| 142 | + graph: graph, extraDirs: [], extraFiles: [], |
| 143 | + options: XcodeprojOptions(), fileSystem: localFileSystem, |
| 144 | + diagnostics: diagnostics, warningStream: warningStream) |
| 145 | + |
| 146 | + let warnings = warningStream.bytes.description |
| 147 | + XCTAssertMatch(warnings, .contains("warning: Target 'Modules' conflicts with required framework filenames, rename this target to avoid conflicts.")) |
| 148 | + } |
137 | 149 | }
|
138 | 150 |
|
139 | 151 | func testGenerateXcodeprojWithoutGitRepo() {
|
|
0 commit comments