-
-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathVariantComputerTest.groovy
More file actions
295 lines (236 loc) · 13.1 KB
/
VariantComputerTest.groovy
File metadata and controls
295 lines (236 loc) · 13.1 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
package com.github.gradle.node.variant
import com.github.gradle.node.NodeExtension
import com.github.gradle.node.util.Platform
import com.github.gradle.node.util.PlatformHelperKt
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification
import spock.lang.Unroll
class VariantComputerTest extends Specification {
/* OS dependant line separator */
static final String PS = File.separator
/* Relative base path for nodejs installation */
static final String NODE_BASE_PATH = "${PS}.gradle${PS}node${PS}"
@Unroll
def "test variant on windows (#version #osArch)"() {
given:
def project = ProjectBuilder.builder().build()
def platform = getPlatform("Windows 8", osArch)
def nodeExtension = new NodeExtension(project)
nodeExtension.resolvedPlatform.set(platform)
nodeExtension.download.set(true)
nodeExtension.version.set(version)
nodeExtension.workDir.set(project.layout.projectDirectory.dir(".gradle/node"))
def nodeDir = "node-v${version}-win-${osArch}".toString()
def depName = "org.nodejs:node:${version}:win-${osArch}@zip".toString()
def variantComputer = new VariantComputer()
when:
def isWindows = platform.isWindows()
def computedArchiveDependency = VariantComputerKt.computeNodeArchiveDependency(nodeExtension)
def resolvedNodeDir = VariantComputerKt.computeNodeDir(nodeExtension)
def computedNodeBinDir = variantComputer.computeNodeBinDir(resolvedNodeDir, nodeExtension.resolvedPlatform)
def computedNodeExec = VariantComputerKt.computeNodeExec(nodeExtension, computedNodeBinDir)
def computedNpmScriptFile = VariantComputerKt.computeNpmScriptFile(resolvedNodeDir, "npm", isWindows)
def computedNpxScriptFile = VariantComputerKt.computeNpmScriptFile(resolvedNodeDir, "npx", isWindows)
then:
computedArchiveDependency.get() == depName
resolvedNodeDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir)
computedNodeBinDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir)
computedNodeExec.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "node.exe")
computedNpmScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "node_modules${PS}npm${PS}bin${PS}npm-cli.js")
computedNpxScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "node_modules${PS}npm${PS}bin${PS}npx-cli.js")
where:
version | osArch
"4.5.0" | "x86"
"6.2.1" | "x86"
"7.0.0" | "x86"
"4.5.0" | "x64"
"6.2.1" | "x64"
"7.0.0" | "x64"
}
@Unroll
def "test variant on non-windows (#osName, #osArch)"() {
given:
def platform = getPlatform(osName, osArch)
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.resolvedPlatform.set(platform)
nodeExtension.download.set(true)
nodeExtension.version.set('5.12.0')
nodeExtension.workDir.set(project.layout.projectDirectory.dir(".gradle/node"))
def variantComputer = new VariantComputer()
when:
def isWindows = platform.isWindows()
def computedArchiveDependency = VariantComputerKt.computeNodeArchiveDependency(nodeExtension)
def resolvedNodeDir = VariantComputerKt.computeNodeDir(nodeExtension)
def computedNodeBinDir = variantComputer.computeNodeBinDir(resolvedNodeDir, nodeExtension.resolvedPlatform)
def computedNodeExec = VariantComputerKt.computeNodeExec(nodeExtension, computedNodeBinDir)
def computedNpmScriptFile = VariantComputerKt.computeNpmScriptFile(resolvedNodeDir, "npm", isWindows)
def computedNpxScriptFile = VariantComputerKt.computeNpmScriptFile(resolvedNodeDir, "npx", isWindows)
then:
computedArchiveDependency.get() == depName
resolvedNodeDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir)
computedNodeBinDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + 'bin')
computedNodeExec.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "bin${PS}node")
computedNpmScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "lib${PS}node_modules${PS}npm${PS}bin${PS}npm-cli.js")
computedNpxScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "lib${PS}node_modules${PS}npm${PS}bin${PS}npx-cli.js")
where:
osName | osArch | nodeDir | depName
'Linux' | 'x86' | 'node-v5.12.0-linux-x86' | 'org.nodejs:node:5.12.0:linux-x86@tar.gz'
'Linux' | 'x86_64' | 'node-v5.12.0-linux-x64' | 'org.nodejs:node:5.12.0:linux-x64@tar.gz'
'Linux' | 'ppc64le' | 'node-v5.12.0-linux-ppc64le' | 'org.nodejs:node:5.12.0:linux-ppc64le@tar.gz'
'Mac OS X' | 'x86' | 'node-v5.12.0-darwin-x86' | 'org.nodejs:node:5.12.0:darwin-x86@tar.gz'
'Mac OS X' | 'x86_64' | 'node-v5.12.0-darwin-x64' | 'org.nodejs:node:5.12.0:darwin-x64@tar.gz'
'FreeBSD' | 'x86' | 'node-v5.12.0-linux-x86' | 'org.nodejs:node:5.12.0:linux-x86@tar.gz'
'FreeBSD' | 'x86_64' | 'node-v5.12.0-linux-x64' | 'org.nodejs:node:5.12.0:linux-x64@tar.gz'
'SunOS' | 'x86' | 'node-v5.12.0-sunos-x86' | 'org.nodejs:node:5.12.0:sunos-x86@tar.gz'
'SunOS' | 'x86_64' | 'node-v5.12.0-sunos-x64' | 'org.nodejs:node:5.12.0:sunos-x64@tar.gz'
}
@Unroll
def "test variant on ARM (#osName, #osArch, #sysOsArch)"() {
given:
def platform = getPlatform(osName, osArch, sysOsArch)
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.resolvedPlatform.set(platform)
nodeExtension.download.set(true)
nodeExtension.version.set('5.12.0')
nodeExtension.workDir.set(project.layout.projectDirectory.dir(".gradle/node"))
def variantComputer = new VariantComputer()
when:
def isWindows = platform.isWindows()
def computedArchiveDependency = VariantComputerKt.computeNodeArchiveDependency(nodeExtension)
def resolvedNodeDir = VariantComputerKt.computeNodeDir(nodeExtension)
def computedNodeBinDir = variantComputer.computeNodeBinDir(resolvedNodeDir, nodeExtension.resolvedPlatform)
def computedNodeExec = VariantComputerKt.computeNodeExec(nodeExtension, computedNodeBinDir)
def computedNpmScriptFile = VariantComputerKt.computeNpmScriptFile(resolvedNodeDir, "npm", isWindows)
def computedNpxScriptFile = VariantComputerKt.computeNpmScriptFile(resolvedNodeDir, "npx", isWindows)
then:
computedArchiveDependency.get() == depName
resolvedNodeDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir)
computedNodeBinDir.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + 'bin')
computedNodeExec.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "bin${PS}node")
computedNpmScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "lib${PS}node_modules${PS}npm${PS}bin${PS}npm-cli.js")
computedNpxScriptFile.get().toString().endsWith(NODE_BASE_PATH + nodeDir + PS + "lib${PS}node_modules${PS}npm${PS}bin${PS}npx-cli.js")
where:
osName | osArch | sysOsArch | nodeDir | depName
'Linux' | 'arm' | 'armv6l' | 'node-v5.12.0-linux-armv6l' | 'org.nodejs:node:5.12.0:linux-armv6l@tar.gz'
'Linux' | 'arm' | 'armv7l' | 'node-v5.12.0-linux-armv7l' | 'org.nodejs:node:5.12.0:linux-armv7l@tar.gz'
'Linux' | 'arm' | 'arm64' | 'node-v5.12.0-linux-arm64' | 'org.nodejs:node:5.12.0:linux-arm64@tar.gz'
'Linux' | 'ppc64le' | 'ppc64le' | 'node-v5.12.0-linux-ppc64le' | 'org.nodejs:node:5.12.0:linux-ppc64le@tar.gz'
}
@Unroll
def "test npm paths on windows (npm: #npmVersion, download: #download)"() {
given:
def platform = getPlatform("Windows 8", "x86")
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.resolvedPlatform.set(platform)
nodeExtension.download.set(download)
nodeExtension.npmVersion.set(npmVersion)
nodeExtension.environment.set([:])
def variantComputer = new VariantComputer()
when:
def resolvedNodeDir = VariantComputerKt.computeNodeDir(nodeExtension)
def computedNpmDir = variantComputer.computeNpmDir(nodeExtension, resolvedNodeDir)
def computedNodeBinDir = variantComputer.computeNodeBinDir(resolvedNodeDir, nodeExtension.resolvedPlatform)
def computedNpmBinDir = variantComputer.computeNpmBinDir(computedNpmDir, nodeExtension.resolvedPlatform)
def computedNpmExec = variantComputer.computeNpmExec(nodeExtension, computedNpmBinDir)
def computedNpxExec = variantComputer.computeNpxExec(nodeExtension, computedNpmBinDir)
def npmDir = resolvedNodeDir.get()
def npm = nodeExtension.npmCommand.get() + ".cmd"
def npx = nodeExtension.npxCommand.get() + ".cmd"
if (npmVersion != "") {
npmDir = nodeExtension.npmWorkDir.get().dir("npm-v${npmVersion}")
}
if (download) {
npm = npmDir.dir(npm).asFile.toString()
npx = npmDir.dir(npx).asFile.toString()
}
then:
computedNpmDir.get() == npmDir
computedNpmExec.get() == npm
computedNpxExec.get() == npx
// if no version use node paths
npmVersion != "" || computedNpmDir.get() == resolvedNodeDir.get()
npmVersion != "" || computedNpmBinDir.get() == computedNodeBinDir.get()
where:
download | npmVersion
true | "4.0.2"
true | ""
false | "4.0.2"
false | ""
}
@Unroll
def "test npm paths on non-windows (npm: #npmVersion, download: #download)"() {
given:
def platform = getPlatform("Linux", "x86")
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.resolvedPlatform.set(platform)
nodeExtension.download.set(download)
nodeExtension.npmVersion.set(npmVersion)
nodeExtension.environment.set([:])
def variantComputer = new VariantComputer()
when:
def resolvedNodeDir = VariantComputerKt.computeNodeDir(nodeExtension)
def computedNpmDir = variantComputer.computeNpmDir(nodeExtension, resolvedNodeDir)
def computedNodeBinDir = variantComputer.computeNodeBinDir(resolvedNodeDir, nodeExtension.resolvedPlatform)
def computedNpmBinDir = variantComputer.computeNpmBinDir(computedNpmDir, nodeExtension.resolvedPlatform)
def computedNpmExec = variantComputer.computeNpmExec(nodeExtension, computedNpmBinDir)
def computedNpxExec = variantComputer.computeNpxExec(nodeExtension, computedNpmBinDir)
def npmDir = resolvedNodeDir.get()
def npm = nodeExtension.npmCommand.get()
def npx = nodeExtension.npxCommand.get()
if (npmVersion != "") {
npmDir = nodeExtension.npmWorkDir.get().dir("npm-v${npmVersion}".toString())
}
def npmBinDir = npmDir.dir("bin")
if (download) {
npm = npmBinDir.file(npm).toString()
npx = npmBinDir.file(npx).toString()
}
then:
computedNpmDir.get() == npmDir
computedNpmExec.get() == npm
computedNpxExec.get() == npx
// if no version use node paths
npmVersion != "" || computedNpmDir.get() == resolvedNodeDir.get()
npmVersion != "" || computedNpmBinDir.get() == computedNodeBinDir.get()
where:
download | npmVersion
true | "4.0.2"
true | ""
false | "4.0.2"
false | ""
}
@Unroll
def "test bun paths on non-windows (download: #download)"() {
given:
def platform = getPlatform("Linux", "x86")
def project = ProjectBuilder.builder().build()
def nodeExtension = new NodeExtension(project)
nodeExtension.resolvedPlatform.set(platform)
nodeExtension.download.set(download)
def variantComputer = new VariantComputer()
when:
def resolvedBunDir = variantComputer.computeBunDir(nodeExtension)
def computedBunBinDir = variantComputer.computeBunBinDir(resolvedBunDir, nodeExtension.resolvedPlatform)
def computedBunExec = variantComputer.computeBunExec(nodeExtension, computedBunBinDir)
def computedBunxExec = variantComputer.computeBunxExec(nodeExtension, computedBunBinDir)
def bunBinDir = resolvedBunDir.get().dir("bin")
def bun = nodeExtension.bunCommand.get()
def bunx = nodeExtension.bunxCommand.get()
if (download) {
bun = bunBinDir.file(bun).toString()
bunx = bunBinDir.file(bunx).toString()
}
then:
computedBunExec.get() == bun
computedBunxExec.get() == bunx
where:
download << [true, false]
}
private Platform getPlatform(String osName, String osArch, uname = null) {
return PlatformHelperKt.parsePlatform(osName, osArch, { uname })
}
}