-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSelectiveTestingPlugin.swift
More file actions
82 lines (65 loc) · 2.67 KB
/
SelectiveTestingPlugin.swift
File metadata and controls
82 lines (65 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// Created by Mike Gerasymenko <mike@gera.cx>
//
import Foundation
import PackagePlugin
@main
struct SelectiveTestingPlugin: CommandPlugin {
private func run(_ executable: String, arguments: [String] = []) throws {
let executableURL = URL(fileURLWithPath: executable)
let process = Process()
process.executableURL = executableURL
process.arguments = arguments
try process.run()
process.waitUntilExit()
let gracefulExit = process.terminationReason == .exit && process.terminationStatus == 0
if !gracefulExit {
throw "[ERROR] The plugin execution failed: \(process.terminationReason.rawValue) (\(process.terminationStatus))"
}
}
func performCommand(context: PluginContext, arguments: [String]) async throws {
FileManager().changeCurrentDirectoryPath(context.package.directory.string)
let tool = try context.tool(named: "xcode-selective-test")
try run(tool.path.string, arguments: arguments)
}
}
#if canImport(XcodeProjectPlugin)
import XcodeProjectPlugin
extension SelectiveTestingPlugin: XcodeCommandPlugin {
func performCommand(context: XcodePluginContext, arguments: [String]) throws {
FileManager().changeCurrentDirectoryPath(context.xcodeProject.directory.string)
let tool = try context.tool(named: "xcode-selective-test")
var toolArguments = arguments
if let indexOfTarget = toolArguments.firstIndex(of: "--target"),
indexOfTarget != (toolArguments.count - 1) {
toolArguments.remove(at: indexOfTarget + 1)
toolArguments.remove(at: indexOfTarget)
}
if !toolArguments.contains(where: { $0 == "--test-plan" }) {
let testPlans = context.xcodeProject.filePaths.filter {
$0.extension == "xctestplan"
}
if !testPlans.isEmpty {
if testPlans.count == 1 {
print("Using \(testPlans[0].string) test plan")
} else {
print("Using \(testPlans.count) test plans")
}
for testPlan in testPlans {
toolArguments.append(contentsOf: ["--test-plan", testPlan.string])
}
}
}
try run(tool.path.string, arguments: toolArguments)
}
}
#endif
#if compiler(>=6)
extension String: @retroactive LocalizedError {
public var errorDescription: String? { return self }
}
#else
extension String: LocalizedError {
public var errorDescription: String? { return self }
}
#endif