forked from Brightify/Cuckoo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GenerateMocksForTests.swift
46 lines (40 loc) · 1.46 KB
/
GenerateMocksForTests.swift
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
import Foundation
@discardableResult
func shell(_ args: [String], inDir dir: String? = nil) -> Int32 {
let task = Process()
task.launchPath = "/usr/bin/env"
task.arguments = args
if let dir = dir {
task.currentDirectoryPath = dir
}
task.launch()
task.waitUntilExit()
return task.terminationStatus
}
let projectDir = ProcessInfo.processInfo.environment["PROJECT_DIR", default: "."]
let output = "\(projectDir)/Tests/Generated/GeneratedMocks.swift"
// Use seperate variables for each file.
let generatorArguments = [
"generate",
"--testable",
"Cuckoo",
"--exclude",
"ExcludedTestClass,ExcludedProtocol",
"--output",
output,
"\(projectDir)/Tests/Source/ClassForStubTesting.swift",
"\(projectDir)/Tests/Source/ClassWithOptionals.swift",
"\(projectDir)/Tests/Source/ObjcProtocol.swift",
"\(projectDir)/Tests/Source/UnicodeTestProtocol.swift",
"\(projectDir)/Tests/Source/TestedProtocol.swift",
"\(projectDir)/Tests/Source/TestedClass.swift",
"\(projectDir)/Tests/Source/TestedSubclass.swift",
"\(projectDir)/Tests/Source/TestedSubProtocol.swift",
"\(projectDir)/Tests/Source/ExcludedTestClass.swift",
]
let useRun = Bool(ProcessInfo.processInfo.environment["USE_RUN", default: "false"]) ?? false
if useRun {
shell(["\(projectDir)/run", "--clean"] + generatorArguments)
} else {
shell(["swift", "run", "cuckoo_generator"] + generatorArguments, inDir: "\(projectDir)/Generator/")
}