Add test for `carton sdk install` (#217)

* Added test for sdk install

* Removed commented out code

Co-authored-by: thecb4 <cavelle@tehcb4.io>
This commit is contained in:
thecb4 2021-01-29 16:01:36 -05:00 committed by GitHub
parent 4ef7b5339e
commit c9250c3b01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 87 additions and 44 deletions

View File

@ -28,6 +28,15 @@
"version": "4.2.5"
}
},
{
"package": "multipart-kit",
"repositoryURL": "https://github.com/vapor/multipart-kit.git",
"state": {
"branch": null,
"revision": "73706f1883f2ba950d41f18aec7e3a53766d4a6d",
"version": "4.0.0"
}
},
{
"package": "OpenCombine",
"repositoryURL": "https://github.com/OpenCombine/OpenCombine.git",
@ -168,7 +177,7 @@
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"state": {
"branch": "release/5.4",
"revision": "9c96dd770834d4b02c680cbf63949fab75fb6cca",
"revision": "48e477aec0a3856a6b7dfdc9c1c30117b0d91259",
"version": null
}
},
@ -177,7 +186,7 @@
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": "release/5.4",
"revision": "bc7961701fd94104528b017e969f63ea40bdb22b",
"revision": "e95add83fc1042a0a0e260d342f9fc5608df9a84",
"version": null
}
},
@ -186,8 +195,8 @@
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "53d15b27ad59b4c91f6ea5fa401b891bd998e202",
"version": "4.37.1"
"revision": "967c2d1f9c473dbb3a5ef8f2e2901f56e21ae79a",
"version": "4.38.0"
}
},
{

View File

@ -26,8 +26,8 @@ public extension StringProtocol {
var chromeStackTrace: [StackTraceItem] {
split(separator: "\n").dropFirst().compactMap {
if let webpackMatch = webpackRegex.matchGroups(in: String($0)).first,
let symbol = webpackMatch.first,
let location = webpackMatch.last
let symbol = webpackMatch.first,
let location = webpackMatch.last
{
return StackTraceItem(symbol: symbol, location: location, kind: .javaScript)
} else if

View File

@ -162,9 +162,9 @@ public struct DiagnosticsParser: ProcessOutputParser {
var groupedMessages = [[CustomDiagnostic]]()
for message in messages {
if let lastLineStr = groupedMessages.last?.last?.line,
let lastLine = Int(lastLineStr),
let line = Int(message.line),
lastLine == line - 1 || lastLine == line
let lastLine = Int(lastLineStr),
let line = Int(message.line),
lastLine == line - 1 || lastLine == line
{
groupedMessages[groupedMessages.count - 1].append(message)
} else {

View File

@ -26,8 +26,8 @@ public extension StringProtocol {
var firefoxStackTrace: [StackTraceItem] {
split(separator: "\n").compactMap {
if let webpackMatch = webpackRegex.matchGroups(in: String($0)).first,
let symbol = webpackMatch.first,
let location = webpackMatch.last
let symbol = webpackMatch.first,
let location = webpackMatch.last
{
return StackTraceItem(symbol: symbol, location: location, kind: .javaScript)
} else if

View File

@ -26,7 +26,7 @@ public extension StringProtocol {
var safariStackTrace: [StackTraceItem] {
split(separator: "\n").compactMap {
if let wasmMatch = wasmRegex.matchGroups(in: String($0)).first,
let symbol = wasmMatch.first
let symbol = wasmMatch.first
{
return StackTraceItem(
symbol: demangle(symbol),

View File

@ -19,7 +19,7 @@ extension StringProtocol {
func matches(regex: NSRegularExpression) -> String.SubSequence? {
let str = String(self)
guard let range = str.range(of: regex),
range.upperBound < str.endIndex
range.upperBound < str.endIndex
else { return nil }
return str[range.upperBound..<str.endIndex]
}
@ -29,7 +29,7 @@ extension StringProtocol {
let str = String(self)
let range = NSRange(location: 0, length: utf16.count)
guard let match = regex.firstMatch(in: str, options: [], range: range),
let matchRange = Range(match.range, in: str)
let matchRange = Range(match.range, in: str)
else {
return nil
}
@ -40,7 +40,7 @@ extension StringProtocol {
let str = String(self)
let range = NSRange(location: 0, length: utf16.count)
guard let matches = regex.matches(in: str, options: [], range: range).first,
let matchRange = Range(matches.range(withName: name), in: str)
let matchRange = Range(matches.range(withName: name), in: str)
else {
return nil
}
@ -50,7 +50,7 @@ extension StringProtocol {
func match(of regex: NSRegularExpression, named name: String) -> String.SubSequence? {
let str = String(self)
guard let range = str.range(of: regex, named: name),
range.upperBound < str.endIndex && range.lowerBound >= str.startIndex
range.upperBound < str.endIndex && range.lowerBound >= str.startIndex
else { return nil }
return str[range]
}

View File

@ -41,7 +41,7 @@ private extension StringProtocol {
_ labelB: TestsParser.Regex.Label
) -> (String.SubSequence, String.SubSequence)? {
guard let a = match(of: regex, named: labelA.rawValue),
let b = match(of: regex, named: labelB.rawValue)
let b = match(of: regex, named: labelB.rawValue)
else {
return nil
}
@ -93,10 +93,10 @@ public struct TestsParser: ProcessOutputParser {
enum Assertion: String, CaseIterable {
case equal = "Equal",
greaterThan = "GreaterThan",
lessThan = "LessThan",
greaterThanOrEqual = "GreaterThanOrEqual",
lessThanOrEqual = "LessThanOrEqual"
greaterThan = "GreaterThan",
lessThan = "LessThan",
greaterThanOrEqual = "GreaterThanOrEqual",
lessThanOrEqual = "LessThanOrEqual"
var funcName: String {
"XCTAssert\(rawValue)"
@ -178,20 +178,20 @@ public struct TestsParser: ProcessOutputParser {
if let suite = line.match(of: Regex.suiteStarted, labelled: .suite) {
suites.append(.init(name: suite, cases: []))
} else if let testCase = line.match(of: Regex.caseFinished, labelled: .testCase),
let suite = line.match(of: Regex.caseFinished, labelled: .suite),
let suiteIdx = suites.firstIndex(where: { $0.name == suite }),
let status = line.match(of: Regex.caseFinished, labelled: .status),
let duration = line.match(of: Regex.caseFinished, labelled: .duration)
let suite = line.match(of: Regex.caseFinished, labelled: .suite),
let suiteIdx = suites.firstIndex(where: { $0.name == suite }),
let status = line.match(of: Regex.caseFinished, labelled: .status),
let duration = line.match(of: Regex.caseFinished, labelled: .duration)
{
suites[suiteIdx].cases.append(
.init(name: testCase, passed: status == "passed", duration: duration, problems: [])
)
} else if let problem = line.matches(regex: Regex.problem),
let path = line.match(of: Regex.problem, labelled: .path),
let lineNum = line.match(of: Regex.problem, labelled: .line),
let status = line.match(of: Regex.problem, labelled: .status),
let suite = line.match(of: Regex.problem, labelled: .suite),
let testCase = line.match(of: Regex.problem, labelled: .testCase)
let path = line.match(of: Regex.problem, labelled: .path),
let lineNum = line.match(of: Regex.problem, labelled: .line),
let status = line.match(of: Regex.problem, labelled: .status),
let suite = line.match(of: Regex.problem, labelled: .suite),
let testCase = line.match(of: Regex.problem, labelled: .testCase)
{
let diag = DiagnosticsParser.CustomDiagnostic(
kind: DiagnosticsParser.CustomDiagnostic.Kind(rawValue: String(status)) ?? .note,
@ -202,7 +202,7 @@ public struct TestsParser: ProcessOutputParser {
message: String(problem)
)
if let suiteIdx = suites.firstIndex(where: { $0.name == suite }),
let caseIdx = suites[suiteIdx].cases.firstIndex(where: { $0.name == testCase })
let caseIdx = suites[suiteIdx].cases.firstIndex(where: { $0.name == testCase })
{
suites[suiteIdx].cases[caseIdx].problems.append(diag)
} else {
@ -212,7 +212,7 @@ public struct TestsParser: ProcessOutputParser {
}
for problem in unmappedProblems {
if let suiteIdx = suites.firstIndex(where: { $0.name == problem.suite }),
let caseIdx = suites[suiteIdx].cases.firstIndex(where: { $0.name == problem.testCase })
let caseIdx = suites[suiteIdx].cases.firstIndex(where: { $0.name == problem.testCase })
{
suites[suiteIdx].cases[caseIdx].problems.append(problem.problem)
}
@ -269,7 +269,7 @@ public struct TestsParser: ProcessOutputParser {
}
// Get the line of code from the file and output it for context.
if let lineNum = Int(problem.line),
lineNum > 0
lineNum > 0
{
var fileContents: String?
if let fileBuf = fileBufs.first(where: { $0.path == problem.file })?.contents {

View File

@ -94,9 +94,9 @@ struct DumpedManifest: Decodable {
private enum CodingKeys: CodingKey {
case name, toolsVersion,
pkgConfig, providers, cLanguageStandard, cxxLanguageStandard, swiftLanguageVersions,
dependencies, products, targets, platforms, packageKind, revision,
defaultLocalization
pkgConfig, providers, cLanguageStandard, cxxLanguageStandard, swiftLanguageVersions,
dependencies, products, targets, platforms, packageKind, revision,
defaultLocalization
}
init(from decoder: Decoder) throws {

View File

@ -214,7 +214,7 @@ public final class Toolchain {
let manifest = try self.manifest.get()
if let jsKit = manifest.dependencies.first(where: { $0.name == "JavaScriptKit" }),
!jsKit.requirement.isJavaScriptKitCompatible
!jsKit.requirement.isJavaScriptKitCompatible
{
let versionDescription = jsKit.requirement.versionDescription

View File

@ -115,7 +115,7 @@ extension ToolchainSystem {
path: path,
reportHead: {
guard $0.status == .ok,
let totalBytes = $0.headers.first(name: "Content-Length").flatMap(Int.init)
let totalBytes = $0.headers.first(name: "Content-Length").flatMap(Int.init)
else {
subject.send(completion: .failure(ToolchainError.invalidResponseCode($0.status.code)))
return

View File

@ -104,8 +104,8 @@ public class ToolchainSystem {
) throws -> String {
if let versionSpec = versionSpec {
if let url = URL(string: versionSpec),
let filename = url.pathComponents.last,
let match = versionRegEx.matchGroups(in: filename).first?.first
let filename = url.pathComponents.last,
let match = versionRegEx.matchGroups(in: filename).first?.first
{
terminal.logLookup("Inferred swift version: ", match)
return match
@ -267,10 +267,10 @@ public class ToolchainSystem {
public func fetchLocalSwiftVersion() throws -> String? {
guard fileSystem.isFile(swiftVersionPath),
let version = try fileSystem.readFileContents(swiftVersionPath)
.validDescription?
// get the first line of the file
.components(separatedBy: CharacterSet.newlines).first
let version = try fileSystem.readFileContents(swiftVersionPath)
.validDescription?
// get the first line of the file
.components(separatedBy: CharacterSet.newlines).first
else { return nil }
return version

View File

@ -0,0 +1,34 @@
// Copyright 2020 Carton contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Created by Cavelle Benjamin on Dec/25/20.
//
@testable import CartonCLI
import TSCBasic
import XCTest
extension SDKCommandTests: Testable {}
final class SDKCommandTests: XCTestCase {
func testInstall() throws {
AssertExecuteCommand(
command: "carton sdk install",
cwd: packageDirectory.url,
expected: "SDK successfully installed!",
expectedContains: true,
debug: true
)
}
}