-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Move files when using package add-target
on single target package
#8413
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
866fe2d
2b8699a
656c36b
b2a8c2a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1120,7 +1120,6 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { | |
} | ||
} | ||
|
||
|
||
func testPackageAddTarget() async throws { | ||
try await testWithTemporaryDirectory { tmpPath in | ||
let fs = localFileSystem | ||
|
@@ -1152,6 +1151,58 @@ class PackageCommandTestCase: CommandsBuildProviderTestCase { | |
} | ||
} | ||
|
||
func testPackageAddTargetWithoutModuleSourcesFolder() async throws { | ||
try await testWithTemporaryDirectory { tmpPath in | ||
let fs = localFileSystem | ||
let manifest = tmpPath.appending("Package.swift") | ||
try fs.writeFileContents(manifest, string: | ||
""" | ||
// swift-tools-version: 5.9 | ||
import PackageDescription | ||
let package = Package( | ||
name: "SimpleExecutable", | ||
targets: [ | ||
.executableTarget(name: "SimpleExecutable"), | ||
] | ||
) | ||
""" | ||
) | ||
|
||
let sourcesFolder = tmpPath.appending("Sources") | ||
try fs.createDirectory(sourcesFolder) | ||
|
||
try fs.writeFileContents(sourcesFolder.appending("main.swift"), string: | ||
""" | ||
print("Hello World") | ||
""" | ||
) | ||
|
||
_ = try await execute(["add-target", "client"], packagePath: tmpPath) | ||
|
||
XCTAssertFileExists(manifest) | ||
let contents: String = try fs.readFileContents(manifest) | ||
|
||
XCTAssertMatch(contents, .contains(#"targets:"#)) | ||
XCTAssertMatch(contents, .contains(#".executableTarget"#)) | ||
XCTAssertMatch(contents, .contains(#"name: "client""#)) | ||
|
||
let fileStructure = try fs.getDirectoryContents(sourcesFolder) | ||
XCTAssertEqual(fileStructure, ["SimpleExecutable", "client"]) | ||
XCTAssertTrue(fs.isDirectory(sourcesFolder.appending("SimpleExecutable"))) | ||
XCTAssertTrue(fs.isDirectory(sourcesFolder.appending("client"))) | ||
XCTAssertEqual(try fs.getDirectoryContents(sourcesFolder.appending("SimpleExecutable")), ["main.swift"]) | ||
XCTAssertEqual(try fs.getDirectoryContents(sourcesFolder.appending("client")), ["client.swift"]) | ||
} | ||
} | ||
|
||
func testAddTargetWithoutManifestThrows() async throws { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (possibly-blocking): Although the current tests are great in validating the file system structure, can we add a test that validate the Package can still be built, and maybe even ensure the tests pass, if we run |
||
try await testWithTemporaryDirectory { tmpPath in | ||
await XCTAssertThrowsCommandExecutionError(try await execute(["add-target", "client"], packagePath: tmpPath)) { error in | ||
XCTAssertMatch(error.stderr, .contains("error: Could not find Package.swift in this directory or any of its parent directories.")) | ||
} | ||
} | ||
} | ||
|
||
func testPackageAddTargetDependency() async throws { | ||
try await testWithTemporaryDirectory { tmpPath in | ||
let fs = localFileSystem | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (possibly-blocking): can we write automated test that validate this function in isolation, where we can test various code paths?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added some unit tests to cover off this function