-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathPackagingPlannerTests.swift
111 lines (104 loc) · 4.12 KB
/
PackagingPlannerTests.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import Foundation
import Testing
@testable import PackageToJS
@Suite struct PackagingPlannerTests {
struct BuildSnapshot: Codable, Equatable {
let npmInstalls: [String]
}
class TestPackagingSystem: PackagingSystem {
var npmInstallCalls: [String] = []
func npmInstall(packageDir: String) throws {
npmInstallCalls.append(packageDir)
}
func wasmOpt(_ arguments: [String], input: String, output: String) throws {
try FileManager.default.copyItem(
at: URL(fileURLWithPath: input),
to: URL(fileURLWithPath: output)
)
}
}
func snapshotBuildPlan(
filePath: String = #filePath,
function: String = #function,
sourceLocation: SourceLocation = #_sourceLocation,
variant: String? = nil,
body: (inout MiniMake) throws -> MiniMake.TaskKey
) throws {
var make = MiniMake(explain: false, printProgress: { _, _ in })
let rootKey = try body(&make)
let fingerprint = try make.computeFingerprint(root: rootKey, prettyPrint: true)
try assertSnapshot(
filePath: filePath,
function: function,
sourceLocation: sourceLocation,
variant: variant,
input: fingerprint
)
}
typealias DebugInfoFormat = PackageToJS.DebugInfoFormat
@Test(arguments: [
(variant: "debug", configuration: "debug", noOptimize: false, debugInfoFormat: DebugInfoFormat.none),
(variant: "release", configuration: "release", noOptimize: false, debugInfoFormat: DebugInfoFormat.none),
(
variant: "release_no_optimize", configuration: "release", noOptimize: true,
debugInfoFormat: DebugInfoFormat.none
),
(variant: "release_dwarf", configuration: "release", noOptimize: false, debugInfoFormat: DebugInfoFormat.dwarf),
(variant: "release_name", configuration: "release", noOptimize: false, debugInfoFormat: DebugInfoFormat.name),
])
func planBuild(
variant: String,
configuration: String,
noOptimize: Bool,
debugInfoFormat: PackageToJS.DebugInfoFormat
) throws {
let options = PackageToJS.PackageOptions()
let system = TestPackagingSystem()
let planner = PackagingPlanner(
options: options,
packageId: "test",
intermediatesDir: BuildPath(prefix: "INTERMEDIATES"),
selfPackageDir: BuildPath(prefix: "SELF_PACKAGE"),
outputDir: BuildPath(prefix: "OUTPUT"),
wasmProductArtifact: BuildPath(prefix: "WASM_PRODUCT_ARTIFACT"),
wasmFilename: "main.wasm",
configuration: configuration,
triple: "wasm32-unknown-wasi",
selfPath: BuildPath(prefix: "PLANNER_SOURCE_PATH"),
system: system
)
try snapshotBuildPlan(variant: variant) { make in
try planner.planBuild(
make: &make,
buildOptions: PackageToJS.BuildOptions(
product: "test",
noOptimize: noOptimize,
debugInfoFormat: debugInfoFormat,
packageOptions: options
)
)
}
}
@Test func planTestBuild() throws {
let options = PackageToJS.PackageOptions()
let system = TestPackagingSystem()
let planner = PackagingPlanner(
options: options,
packageId: "test",
intermediatesDir: BuildPath(prefix: "INTERMEDIATES"),
selfPackageDir: BuildPath(prefix: "SELF_PACKAGE"),
outputDir: BuildPath(prefix: "OUTPUT"),
wasmProductArtifact: BuildPath(prefix: "WASM_PRODUCT_ARTIFACT"),
wasmFilename: "main.wasm",
configuration: "debug",
triple: "wasm32-unknown-wasi",
selfPath: BuildPath(prefix: "PLANNER_SOURCE_PATH"),
system: system
)
try snapshotBuildPlan { make in
let (root, binDir) = try planner.planTestBuild(make: &make)
#expect(binDir.description == "$OUTPUT/bin")
return root
}
}
}