Skip to content

Commit 5036976

Browse files
authored
Merge pull request #40 from platan/mark-previous
Allow to add mark showing total time of all tests
2 parents 149c3db + d4da5ef commit 5036976

23 files changed

+520
-98
lines changed

README.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ rendered: ([info](https://github.blog/2022-02-14-include-diagrams-markdown-files
105105

106106
```mermaid
107107
gantt
108-
dateFormat YYYY-MM-DDTHH:mm:ss.SSSZZ
109-
axisFormat %H:%M:%S.%L
110-
section Test1Spec
111-
test 2 - 120 ms :active, 2022-11-08T20:46:17.854+0100, 2022-11-08T20:46:17.974+0100
112-
test 1 - 213 ms :active, 2022-11-08T20:46:17.854+0100, 2022-11-08T20:46:18.067+0100
108+
dateFormat YYYY-MM-DDTHH:mm:ss.SSSZZ
109+
axisFormat %H:%M:%S.%L
110+
section Test1Spec
111+
test 2 - 120 ms: active, 2022-11-08T20:46:17.854+0100, 2022-11-08T20:46:17.974+0100
112+
test 1 - 213 ms: active, 2022-11-08T20:46:17.854+0100, 2022-11-08T20:46:18.067+0100
113113
```
114114

115115
# Configuration
@@ -125,6 +125,8 @@ Options:
125125
| `formats.json.enabled` | boolean | Generate report in json format | `true` |
126126
| `formats.mermaid.enabled` | boolean | Generate report in mermaid text format | `true` |
127127
| `shiftTimestampsToStartOfDay` | boolean | Adjust the earliest timestamp to the start of the day | `false` |
128+
| `marks.totalTimeOfAllTests.enabled` | boolean | Enable mark showing total time of all tests | `false` |
129+
| `marks.totalTimeOfAllTests.name` | string | Label used for mark | `total time of all tests` |
128130

129131
`build.gradle.kts`:
130132

@@ -149,6 +151,12 @@ configure<io.github.platan.tests_execution_chart.CreateTestsExecutionReportExten
149151
}
150152
}
151153
shiftTimestampsToStartOfDay.set(true)
154+
marks {
155+
totalTimeOfAllTests {
156+
enabled.set(true)
157+
name.set("total time of all tests")
158+
}
159+
}
152160
}
153161
```
154162

@@ -175,6 +183,12 @@ createTestsExecutionReport {
175183
}
176184
}
177185
shiftTimestampsToStartOfDay = true
186+
marks {
187+
totalTimeOfAllTests {
188+
enabled = true
189+
name = 'total time of all tests'
190+
}
191+
}
178192
}
179193
```
180194

@@ -238,6 +252,14 @@ Gradle can generate reports in JUnit XML format. But such reports cannot be used
238252

239253
## Unreleased
240254

255+
### Added
256+
257+
- A new option `marks.totalTimeOfAllTests` allows to add mark showing total time of all tests
258+
259+
### Changed
260+
261+
- Do not remove `#` character from names of tasks/sections
262+
241263
## 0.3.1 (29 March 2023)
242264

243265
### Added

src/functionalTest/groovy/ReportsFunctionalTest.groovy

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class ReportsFunctionalTest extends Specification {
3434
json { enabled = true }
3535
mermaid { enabled = true }
3636
}
37+
marks {
38+
totalTimeOfAllTests {
39+
enabled = true
40+
}
41+
}
3742
}
3843
repositories {
3944
mavenCentral()
@@ -72,6 +77,9 @@ class ReportsFunctionalTest extends Specification {
7277
mermaidFile.exists()
7378
jsonFile.exists()
7479
htmlFile.exists()
80+
81+
and:
82+
mermaidFile.text.contains 'total time of all tests : milestone, '
7583
}
7684

7785
def "should replace special characters in mermaid graph test names"() {
@@ -121,10 +129,10 @@ class ReportsFunctionalTest extends Specification {
121129

122130
when:
123131
def result = GradleRunner.create()
124-
.withProjectDir(testProjectDir)
125-
.withArguments('test', 'createTestsExecutionReport')
126-
.withPluginClasspath()
127-
.build()
132+
.withProjectDir(testProjectDir)
133+
.withArguments('test', 'createTestsExecutionReport')
134+
.withPluginClasspath()
135+
.build()
128136

129137
then:
130138
result.task(":createTestsExecutionReport").outcome == SUCCESS
@@ -133,7 +141,7 @@ class ReportsFunctionalTest extends Specification {
133141
def mermaidGraph = new File("$projectDirRealPath/build/reports/tests-execution/mermaid/test.txt").text
134142
!mermaidGraph.contains("test with # character")
135143
!mermaidGraph.contains("test with : character")
136-
mermaidGraph.contains("test with character")
144+
mermaidGraph.contains("test with #35; character")
137145
mermaidGraph.contains("test with #colon; character")
138146
}
139147

@@ -213,6 +221,38 @@ class ReportsFunctionalTest extends Specification {
213221
!new File("$projectDirRealPath/build/reports/tests-execution/").exists()
214222
}
215223

224+
def "exit with error on empty mark name"() {
225+
given:
226+
settingsFile << "rootProject.name = 'hello-world'"
227+
buildFile << """
228+
plugins {
229+
id 'groovy'
230+
id 'io.github.platan.tests-execution-chart'
231+
}
232+
createTestsExecutionReport {
233+
marks {
234+
totalTimeOfAllTests {
235+
name = ''
236+
}
237+
}
238+
}
239+
"""
240+
241+
when:
242+
def result = GradleRunner.create()
243+
.withProjectDir(testProjectDir)
244+
.withArguments('createTestsExecutionReport')
245+
.withPluginClasspath()
246+
.buildAndFail()
247+
248+
then:
249+
result.output.contains("marks.totalTimeOfAllTests.name cannot be blank")
250+
result.output.contains('BUILD FAILED')
251+
252+
and:
253+
!new File("$projectDirRealPath/build/reports/tests-execution/").exists()
254+
}
255+
216256
// @TempDir creates directories in /var, but on macOS /var is a link to /private/var
217257
// so we have to use toRealPath to get a real path which is logged
218258
private Path getProjectDirRealPath() {
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package io.github.platan.tests_execution_chart.reporters.mermaid
22

3+
import io.github.platan.tests_execution_chart.reporters.mermaid.core.MermaidGanttDiagram
4+
import io.github.platan.tests_execution_chart.reporters.mermaid.core.MermaidGanttDiagramFormatter
35
import spock.lang.Retry
46
import spock.lang.Specification
57
import spock.lang.TempDir
68

7-
class MermaidGanttDiagramFormatterSpec extends Specification {
9+
class MermaidGanttDiagramFormatterToSvgConversionSpec extends Specification {
810

911
@TempDir
1012
File tempDir
@@ -27,7 +29,9 @@ class MermaidGanttDiagramFormatterSpec extends Specification {
2729
def "should produce result parsable by mmdc (mermaid CLI)"() {
2830
given:
2931
def diagramBuilder = new MermaidGanttDiagram.MermaidGanttDiagramBuilder()
30-
diagramBuilder.add("test-section $SPECIAL_CHARS", "test-row $SPECIAL_CHARS", 'active', 1, 2)
32+
diagramBuilder.addSection("test-section $SPECIAL_CHARS")
33+
diagramBuilder.addTask("test-row $SPECIAL_CHARS", 'active', 1, 2)
34+
diagramBuilder.addMilestone("test-milestone $SPECIAL_CHARS", 1)
3135
def diagram = diagramBuilder.build("YYYY-MM-DD\\THH\\:mm\\:ss\\.SSSZ", "%H:%M:%S.%L")
3236
def mermaid = new MermaidGanttDiagramFormatter().format(diagram, "yyyy-MM-dd'T'HH:mm:ss.SSSZ")
3337
inputFile.text = mermaid

src/functionalTest/resources/report-visual-regression.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,11 @@
8080
"resultType": "SUCCESS",
8181
"testName": "test 3"
8282
}
83+
],
84+
"marks": [
85+
{
86+
"timestamp": 1679338714982,
87+
"name": "total time of all tests"
88+
}
8389
]
8490
}

src/main/kotlin/io/github/platan/tests_execution_chart/CreateTestsExecutionReportExtension.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.platan.tests_execution_chart
22

33
import io.github.platan.tests_execution_chart.config.Formats
4+
import io.github.platan.tests_execution_chart.config.Marks
45
import org.gradle.api.Action
56
import org.gradle.api.model.ObjectFactory
67
import org.gradle.api.provider.Property
@@ -13,10 +14,17 @@ abstract class CreateTestsExecutionReportExtension @Inject constructor(objectFac
1314
@Nested
1415
abstract fun getFormats(): Formats
1516

17+
@Nested
18+
abstract fun getMarks(): Marks
19+
1620
@get:Input
1721
val shiftTimestampsToStartOfDay: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(false)
1822

1923
open fun formats(action: Action<in Formats>) {
2024
action.execute(getFormats())
2125
}
26+
27+
open fun marks(action: Action<in Marks>) {
28+
action.execute(getMarks())
29+
}
2230
}

src/main/kotlin/io/github/platan/tests_execution_chart/CreateTestsExecutionReportTask.kt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.github.platan.tests_execution_chart
22

33
import io.github.platan.tests_execution_chart.config.Formats
4+
import io.github.platan.tests_execution_chart.config.Marks
45
import io.github.platan.tests_execution_chart.report.TestExecutionScheduleReport
56
import io.github.platan.tests_execution_chart.reporters.Logger
67
import io.github.platan.tests_execution_chart.reporters.html.HtmlGanttDiagramReporter
@@ -37,6 +38,9 @@ abstract class CreateTestsExecutionReportTask @Inject constructor(objectFactory:
3738
@Nested
3839
abstract fun getFormats(): Formats
3940

41+
@Nested
42+
abstract fun getMarks(): Marks
43+
4044
@get:Input
4145
val shiftTimestampsToStartOfDay: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(false)
4246

@@ -57,7 +61,11 @@ abstract class CreateTestsExecutionReportTask @Inject constructor(objectFactory:
5761
)
5862
}
5963
if (getFormats().getJson().enabled.get()) {
60-
JsonReporter(getFormats().getJson(), customLogger).report(adjustedResults, task.project.buildDir, task.name)
64+
JsonReporter(getFormats().getJson(), customLogger).report(
65+
adjustedResults,
66+
task.project.buildDir,
67+
task.name
68+
)
6169
}
6270
if (getFormats().getHtml().enabled.get()) {
6371
HtmlGanttDiagramReporter(getFormats().getHtml().toHtmlConfig(), customLogger).report(
@@ -71,10 +79,13 @@ abstract class CreateTestsExecutionReportTask @Inject constructor(objectFactory:
7179
}
7280

7381
private fun adjustResults(results: TestExecutionScheduleReport): TestExecutionScheduleReport {
74-
return if (shiftTimestampsToStartOfDay.get()) {
75-
results.timestampsShiftedToStartOfDay(ZoneId.systemDefault())
76-
} else {
77-
results
82+
var adjusted = results
83+
if (shiftTimestampsToStartOfDay.get()) {
84+
adjusted = results.timestampsShiftedToStartOfDay(ZoneId.systemDefault())
85+
}
86+
if (getMarks().getTotalTimeOfAllTests().enabled.get()) {
87+
adjusted = adjusted.addTotalTimeOfAllTestsMark(getMarks().getTotalTimeOfAllTests().name.get())
7888
}
89+
return adjusted
7990
}
8091
}

src/main/kotlin/io/github/platan/tests_execution_chart/TestsExecutionReportPlugin.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,11 @@ class TestsExecutionReportPlugin : Plugin<Project> {
5151
.set(createTestsExecutionReportExtension.getFormats().getMermaid().outputLocation)
5252

5353
task.shiftTimestampsToStartOfDay.set(createTestsExecutionReportExtension.shiftTimestampsToStartOfDay)
54+
task.getMarks().getTotalTimeOfAllTests().enabled.set(
55+
createTestsExecutionReportExtension.getMarks().getTotalTimeOfAllTests().enabled
56+
)
57+
val name = createTestsExecutionReportExtension.getMarks().getTotalTimeOfAllTests().name.get()
58+
require(name.isNotBlank()) { "marks.totalTimeOfAllTests.name cannot be blank" }
59+
task.getMarks().getTotalTimeOfAllTests().name.set(name)
5460
}
5561
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.github.platan.tests_execution_chart.config
2+
3+
import org.gradle.api.model.ObjectFactory
4+
import org.gradle.api.provider.Property
5+
import org.gradle.api.tasks.Input
6+
import javax.inject.Inject
7+
8+
abstract class Mark @Inject constructor(objectFactory: ObjectFactory, name: String) {
9+
10+
@get:Input
11+
val enabled: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(false)
12+
13+
@get:Input
14+
val name: Property<String> = objectFactory.property(String::class.java).convention(name)
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.github.platan.tests_execution_chart.config
2+
3+
import org.gradle.api.Action
4+
import org.gradle.api.tasks.Nested
5+
6+
abstract class Marks {
7+
8+
@Nested
9+
abstract fun getTotalTimeOfAllTests(): TotalTimeOfAllTestsMark
10+
11+
open fun totalTimeOfAllTests(action: Action<in Mark>) {
12+
action.execute(getTotalTimeOfAllTests())
13+
}
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.github.platan.tests_execution_chart.config
2+
3+
import org.gradle.api.model.ObjectFactory
4+
import javax.inject.Inject
5+
6+
abstract class TotalTimeOfAllTestsMark @Inject constructor(objectFactory: ObjectFactory) :
7+
Mark(objectFactory, "total time of all tests")

0 commit comments

Comments
 (0)