-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Fixup several warnings #9009
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
base: main
Are you sure you want to change the base?
Fixup several warnings #9009
Changes from 3 commits
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 |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import SourceControl | ||
|
||
import class Basics.AsyncProcess | ||
import class TSCBasic.Process | ||
|
||
import enum TSCUtility.Git | ||
|
||
|
@@ -21,7 +22,7 @@ import enum TSCUtility.Git | |
package extension GitRepository { | ||
/// Create the repository using git init. | ||
func create() throws { | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "init"]) | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "init") | ||
} | ||
|
||
/// Returns current branch name. If HEAD is on a detached state, this returns HEAD. | ||
|
@@ -38,36 +39,36 @@ package extension GitRepository { | |
|
||
/// Stage a file. | ||
func stage(file: String) throws { | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "add", file]) | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "add", file) | ||
} | ||
|
||
/// Stage multiple files. | ||
func stage(files: String...) throws { | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "add"] + files) | ||
try Process.checkNonZeroExit(arguments: [Git.tool, "-C", self.path.pathString, "add"] + files) | ||
} | ||
|
||
/// Stage entire unstaged changes. | ||
func stageEverything() throws { | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "add", "."]) | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "add", ".") | ||
} | ||
|
||
/// Commit the staged changes. If the message is not provided a dummy message will be used for the commit. | ||
func commit(message: String? = nil) throws { | ||
// FIXME: We don't need to set these every time but we usually only commit once or twice for a test repo. | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "config", "user.email", "[email protected]"]) | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "config", "user.name", "Example Example"]) | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "config", "commit.gpgsign", "false"]) | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "config", "tag.gpgsign", "false"]) | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "commit", "-m", message ?? "Add some files."]) | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "config", "user.email", "[email protected]") | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "config", "user.name", "Example Example") | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "config", "commit.gpgsign", "false") | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "config", "tag.gpgsign", "false") | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "commit", "-m", message ?? "Add some files.") | ||
} | ||
|
||
/// Tag the git repo. | ||
func tag(name: String) throws { | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "tag", name]) | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "tag", name) | ||
} | ||
|
||
/// Push the changes to specified remote and branch. | ||
func push(remote: String, branch: String) throws { | ||
try systemQuietly([Git.tool, "-C", self.path.pathString, "push", remote, branch]) | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", self.path.pathString, "push", remote, branch) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,12 +32,12 @@ import Testing | |
import func XCTest.XCTFail | ||
import struct XCTest.XCTSkip | ||
|
||
import class TSCBasic.Process | ||
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. issue: Can we use 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. That would require marking the utility method as async and then cascading that across all its usages. Probably worth doing, but in a separate patch |
||
import struct TSCBasic.ByteString | ||
import struct Basics.AsyncProcessResult | ||
|
||
import enum TSCUtility.Git | ||
|
||
@_exported import func TSCTestSupport.systemQuietly | ||
@_exported import enum TSCTestSupport.StringPattern | ||
|
||
@available(*, deprecated, message: "Use CiEnvironment.runningInSmokeTestPipeline") | ||
|
@@ -193,7 +193,6 @@ public enum TestError: Error { | |
case platformNotSupported | ||
} | ||
|
||
@available(*, deprecated, message: "Migrate test to Swift Testing and use 'fixture' instead") | ||
plemarquand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@discardableResult public func fixtureXCTest<T>( | ||
name: String, | ||
createGitRepo: Bool = true, | ||
|
@@ -305,7 +304,7 @@ fileprivate func setup( | |
#if os(Windows) | ||
try localFileSystem.copy(from: srcDir, to: dstDir) | ||
#else | ||
try systemQuietly("cp", "-R", "-H", srcDir.pathString, dstDir.pathString) | ||
try Process.checkNonZeroExit(args: "cp", "-R", "-H", srcDir.pathString, dstDir.pathString) | ||
#endif | ||
|
||
// Ensure we get a clean test fixture. | ||
|
@@ -361,17 +360,17 @@ public func initGitRepo( | |
try localFileSystem.writeFileContents(file, bytes: "") | ||
} | ||
|
||
try systemQuietly([Git.tool, "-C", dir.pathString, "init"]) | ||
try systemQuietly([Git.tool, "-C", dir.pathString, "config", "user.email", "[email protected]"]) | ||
try systemQuietly([Git.tool, "-C", dir.pathString, "config", "user.name", "Example Example"]) | ||
try systemQuietly([Git.tool, "-C", dir.pathString, "config", "commit.gpgsign", "false"]) | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "init") | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "config", "user.email", "[email protected]") | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "config", "user.name", "Example Example") | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "config", "commit.gpgsign", "false") | ||
let repo = GitRepository(path: dir) | ||
try repo.stageEverything() | ||
try repo.commit(message: "msg") | ||
for tag in tags { | ||
try repo.tag(name: tag) | ||
} | ||
try systemQuietly([Git.tool, "-C", dir.pathString, "branch", "-m", "main"]) | ||
try Process.checkNonZeroExit(args: Git.tool, "-C", dir.pathString, "branch", "-m", "main") | ||
} catch { | ||
XCTFail("\(error.interpolationDescription)", file: file, line: line) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,8 +277,8 @@ final class MiscellaneousTestCase: XCTestCase { | |
// Create a shared library. | ||
let input = systemModule.appending(components: "Sources", "SystemModule.c") | ||
let triple = try UserToolchain.default.targetTriple | ||
let output = systemModule.appending("libSystemModule\(triple.dynamicLibraryExtension)") | ||
try systemQuietly([executableName("clang"), "-shared", input.pathString, "-o", output.pathString]) | ||
let output = systemModule.appending("libSystemModule\(triple.dynamicLibraryExtension)") | ||
try await AsyncProcess.checkNonZeroExit(args: executableName("clang"), "-shared", input.pathString, "-o", output.pathString) | ||
|
||
let pcFile = fixturePath.appending("libSystemModule.pc") | ||
|
||
|
@@ -686,7 +686,7 @@ final class MiscellaneousTestCase: XCTestCase { | |
guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { | ||
return XCTFail("invalid error \(error)") | ||
} | ||
XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error. stderr: '\(stderr)'") | ||
XCTAssert(stderr.contains("error: You don’t have permission") || stderr.contains("invalid access"), "expected permissions error. stderr: '\(stderr)'") | ||
plemarquand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
XCTAssertNoSuchPath(customCachePath) | ||
} | ||
|
@@ -721,7 +721,7 @@ final class MiscellaneousTestCase: XCTestCase { | |
guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { | ||
return XCTFail("invalid error \(error)") | ||
} | ||
XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error. stderr: '\(stderr)'") | ||
XCTAssert(stderr.contains("error: You don’t have permission") || stderr.contains("invalid access"), "expected permissions error. stderr: '\(stderr)'") | ||
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. issue (possibly-blocking): I this is also update a test case. do we know if this new expectation is expected, or whether it's a regression? 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. This change is unrelated to my patch, but its because this test is failing on 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. I understand it's failing on main, but could this mean a regression was introduced somewhere? That is, test is there for a reason and may have actually served its purpose. 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. I wasn't able to track down what specifically caused this to change, but this failure stems from the underlying API moving from the Foundation based file system APIs to the tools-support-core FileSystem. 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. It would be ideal to understand the root cause and determine whether the is the expected behaviour or a regression, instead of simply updating the test to reflect the current behaviour - which may be a regression. 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. Its likely this change: https://github.com/swiftlang/swift-tools-support-core/pull/521/files#diff-4a8cbeddae09f50e3bf71a7b4f098244ee50dad510e6359a24f2678a5bca10d5R506, converting the NSError's produced inside various FileSystem functions into FileSystemErrors. |
||
} | ||
XCTAssertNoSuchPath(customConfigPath) | ||
} | ||
|
@@ -756,7 +756,7 @@ final class MiscellaneousTestCase: XCTestCase { | |
guard case SwiftPMError.executionFailure(_, _, let stderr) = error else { | ||
return XCTFail("invalid error \(error)") | ||
} | ||
XCTAssert(stderr.contains("error: You don’t have permission"), "expected permissions error. stderr: '\(stderr)'") | ||
XCTAssert(stderr.contains("error: You don’t have permission") || stderr.contains("invalid access"), "expected permissions error. stderr: '\(stderr)'") | ||
plemarquand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
#endif | ||
|
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: can we use
AsyncProcess
that is located in SwiftPM instead of having to rely on a TSC API?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.
Switching from
Process.checkNonZeroExit
toAsyncProcess.checkNonZeroExit
would require many methods to be converted toasync
. While probably worthwhile, it would would be best addressed in a standalone PR.