@@ -50,6 +50,7 @@ class BuildTimeTrackerPluginFunctionalTest {
50
50
import ${Thread ::class .qualifiedName}
51
51
import ${Output ::class .qualifiedName}
52
52
import ${Duration ::class .qualifiedName}
53
+ import ${Sort ::class .qualifiedName}
53
54
54
55
plugins {
55
56
id("${props.getProperty(" pluginId" )} ")
@@ -82,7 +83,7 @@ class BuildTimeTrackerPluginFunctionalTest {
82
83
83
84
println (buildFile.readText())
84
85
85
- val result = run ()
86
+ val result = run (taskName )
86
87
87
88
assertThat(result.task(taskName)?.outcome == SUCCESS )
88
89
val lines = result.output
@@ -110,7 +111,7 @@ class BuildTimeTrackerPluginFunctionalTest {
110
111
111
112
println (buildFile.readText())
112
113
113
- val result = run ()
114
+ val result = run (taskName )
114
115
115
116
assertThat(result.task(taskName)?.outcome == SUCCESS )
116
117
val lines = result.output
@@ -140,7 +141,7 @@ class BuildTimeTrackerPluginFunctionalTest {
140
141
141
142
println (buildFile.readText())
142
143
143
- val result = run ()
144
+ val result = run (taskName )
144
145
val csvFile = testProjectDir.resolve(Constants .CSV_FILENAME )
145
146
assertThat(result.task(taskName)?.outcome == SUCCESS )
146
147
assertThat(Files .exists(csvFile)).isTrue
@@ -166,7 +167,7 @@ class BuildTimeTrackerPluginFunctionalTest {
166
167
167
168
println (buildFile.readText())
168
169
169
- val result = run ()
170
+ val result = run (taskName )
170
171
val csvFile = testProjectDir.resolve(Constants .CSV_FILENAME )
171
172
assertThat(result.task(taskName)?.outcome == SUCCESS )
172
173
assertThat(Files .exists(csvFile)).isTrue
@@ -175,10 +176,142 @@ class BuildTimeTrackerPluginFunctionalTest {
175
176
assertThat(lines.first()).isEqualTo(" :$taskName ,0S,0%," )
176
177
}
177
178
178
- private fun run (): BuildResult {
179
+ @Test
180
+ fun testSort () {
181
+ newBuildFile(" build.gradle.kts" )
182
+ Files .newBufferedWriter(buildFile, APPEND ).use {
183
+ it.write(
184
+ """
185
+ tasks.register("a") {
186
+ doLast {
187
+ Thread.sleep(1100)
188
+ println("Hello, World!")
189
+ }
190
+ }
191
+ tasks.register("b") {
192
+ doLast {
193
+ Thread.sleep(2100)
194
+ println("Hi there!")
195
+ }
196
+ }
197
+ ${Constants .PLUGIN_EXTENSION_NAME } {
198
+ minTaskDuration.set(Duration.ofMillis(100))
199
+ sort.set(true)
200
+ }
201
+ """ .trimIndent()
202
+ )
203
+ }
204
+
205
+ println (buildFile.readText())
206
+
207
+ val result = run (" a" , " b" )
208
+
209
+ assertThat(result.task(taskName)?.outcome == SUCCESS )
210
+ val lines = result.output
211
+ .lines()
212
+ .filter { it.isNotEmpty() }
213
+ assertThat(lines).hasSizeGreaterThanOrEqualTo(4 )
214
+ assertThat(lines[0 ]).isEqualTo(" > Task :a" )
215
+ assertThat(lines[1 ]).isEqualTo(" Hello, World!" )
216
+ assertThat(lines[2 ]).isEqualTo(" > Task :b" )
217
+ assertThat(lines[3 ]).isEqualTo(" Hi there!" )
218
+ assertThat(lines[4 ]).isEqualTo(" == Build time summary ==" )
219
+ assertThat(lines[5 ]).isEqualTo(" :b | 2S | 67% | ${Printer .BLOCK_CHAR .toString().repeat(2 )} " )
220
+ assertThat(lines[6 ]).isEqualTo(" :a | 1S | 33% | ${Printer .BLOCK_CHAR } " )
221
+ }
222
+
223
+ @Test
224
+ fun testSortByDesc () {
225
+ newBuildFile(" build.gradle.kts" )
226
+ Files .newBufferedWriter(buildFile, APPEND ).use {
227
+ it.write(
228
+ """
229
+ tasks.register("a") {
230
+ doLast {
231
+ Thread.sleep(1100)
232
+ println("Hello, World!")
233
+ }
234
+ }
235
+ tasks.register("b") {
236
+ doLast {
237
+ Thread.sleep(2100)
238
+ println("Hi there!")
239
+ }
240
+ }
241
+ ${Constants .PLUGIN_EXTENSION_NAME } {
242
+ minTaskDuration.set(Duration.ofMillis(100))
243
+ sortBy.set(Sort.DESC)
244
+ }
245
+ """ .trimIndent()
246
+ )
247
+ }
248
+
249
+ println (buildFile.readText())
250
+
251
+ val result = run (" a" , " b" )
252
+
253
+ assertThat(result.task(taskName)?.outcome == SUCCESS )
254
+ val lines = result.output
255
+ .lines()
256
+ .filter { it.isNotEmpty() }
257
+ assertThat(lines).hasSizeGreaterThanOrEqualTo(4 )
258
+ assertThat(lines[0 ]).isEqualTo(" > Task :a" )
259
+ assertThat(lines[1 ]).isEqualTo(" Hello, World!" )
260
+ assertThat(lines[2 ]).isEqualTo(" > Task :b" )
261
+ assertThat(lines[3 ]).isEqualTo(" Hi there!" )
262
+ assertThat(lines[4 ]).isEqualTo(" == Build time summary ==" )
263
+ assertThat(lines[5 ]).isEqualTo(" :b | 2S | 67% | ${Printer .BLOCK_CHAR .toString().repeat(2 )} " )
264
+ assertThat(lines[6 ]).isEqualTo(" :a | 1S | 33% | ${Printer .BLOCK_CHAR } " )
265
+ }
266
+
267
+ @Test
268
+ fun testSortByAsc () {
269
+ newBuildFile(" build.gradle.kts" )
270
+ Files .newBufferedWriter(buildFile, APPEND ).use {
271
+ it.write(
272
+ """
273
+ tasks.register("a") {
274
+ doLast {
275
+ Thread.sleep(1100)
276
+ println("Hello, World!")
277
+ }
278
+ }
279
+ tasks.register("b") {
280
+ doLast {
281
+ Thread.sleep(2100)
282
+ println("Hi there!")
283
+ }
284
+ }
285
+ ${Constants .PLUGIN_EXTENSION_NAME } {
286
+ minTaskDuration.set(Duration.ofMillis(100))
287
+ sortBy.set(Sort.ASC)
288
+ }
289
+ """ .trimIndent()
290
+ )
291
+ }
292
+
293
+ println (buildFile.readText())
294
+
295
+ val result = run (" a" , " b" )
296
+
297
+ assertThat(result.task(taskName)?.outcome == SUCCESS )
298
+ val lines = result.output
299
+ .lines()
300
+ .filter { it.isNotEmpty() }
301
+ assertThat(lines).hasSizeGreaterThanOrEqualTo(4 )
302
+ assertThat(lines[0 ]).isEqualTo(" > Task :a" )
303
+ assertThat(lines[1 ]).isEqualTo(" Hello, World!" )
304
+ assertThat(lines[2 ]).isEqualTo(" > Task :b" )
305
+ assertThat(lines[3 ]).isEqualTo(" Hi there!" )
306
+ assertThat(lines[4 ]).isEqualTo(" == Build time summary ==" )
307
+ assertThat(lines[5 ]).isEqualTo(" :a | 1S | 33% | ${Printer .BLOCK_CHAR } " )
308
+ assertThat(lines[6 ]).isEqualTo(" :b | 2S | 67% | ${Printer .BLOCK_CHAR .toString().repeat(2 )} " )
309
+ }
310
+
311
+ private fun run (vararg tasks : String ): BuildResult {
179
312
return GradleRunner .create()
180
313
.withProjectDir(testProjectDir.toFile())
181
- .withArguments(taskName , " --warning-mode=all" , " --stacktrace" )
314
+ .withArguments(* tasks , " --warning-mode=all" , " --stacktrace" )
182
315
.withPluginClasspath()
183
316
.withDebug(false )
184
317
.forwardOutput()
0 commit comments