@@ -25,6 +25,10 @@ import kotlin.reflect.KFunction3
25
25
import kotlin.reflect.KFunction4
26
26
27
27
28
+ private const val NEW_LINE = " \n "
29
+ private const val POINT_IN_THE_LIST = " * "
30
+ private const val COMMENT_SEPARATOR = " -------------------------------------------------------------"
31
+
28
32
@Disabled
29
33
open class SummaryTestCaseGeneratorTest (
30
34
testClass : KClass <* >,
@@ -120,18 +124,51 @@ open class SummaryTestCaseGeneratorTest(
120
124
return result
121
125
}
122
126
123
-
124
127
fun List<UtExecution>.checkMatchersWithTextSummary (
125
- summaryTextKeys : List <String >,
128
+ comments : List <String >,
126
129
) {
127
- if (summaryTextKeys .isEmpty()) {
130
+ if (comments .isEmpty()) {
128
131
return
129
132
}
130
133
val notMatchedExecutions = this .filter { execution ->
131
- summaryTextKeys.none { summaryKey -> val normalize = execution.summary?.toString()?.normalize()
132
- normalize?.contains(summaryKey.normalize()) == true }
134
+ comments.none { comment ->
135
+ val normalize = execution.summary?.toString()?.normalize()
136
+ normalize?.contains(comment.normalize()) == true
137
+ }
138
+ }
139
+
140
+ val notMatchedComments = comments.filter { comment ->
141
+ this .none { execution ->
142
+ val normalize = execution.summary?.toString()?.normalize()
143
+ normalize?.contains(comment.normalize()) == true
144
+ }
145
+ }
146
+
147
+ Assertions .assertTrue(notMatchedExecutions.isEmpty() && notMatchedComments.isEmpty()) {
148
+ buildString {
149
+ if (notMatchedExecutions.isNotEmpty()) {
150
+ append(
151
+ " \n The following comments were produced by the UTBot, " +
152
+ " but were not found in the list of comments passed in the check() method:\n\n ${
153
+ commentsFromExecutions(
154
+ notMatchedExecutions
155
+ )
156
+ } "
157
+ )
158
+ }
159
+
160
+ if (notMatchedComments.isNotEmpty()) {
161
+ append(
162
+ " \n The following comments were passed in the check() method, " +
163
+ " but were not found in the list of comments produced by the UTBot:\n\n ${
164
+ comments(
165
+ notMatchedComments
166
+ )
167
+ } "
168
+ )
169
+ }
170
+ }
133
171
}
134
- Assertions .assertTrue(notMatchedExecutions.isEmpty()) { " Not matched comments ${summaries(notMatchedExecutions)} " }
135
172
}
136
173
137
174
fun List<UtExecution>.checkMatchersWithMethodNames (
@@ -143,7 +180,36 @@ open class SummaryTestCaseGeneratorTest(
143
180
val notMatchedExecutions = this .filter { execution ->
144
181
methodNames.none { methodName -> execution.testMethodName?.equals(methodName) == true }
145
182
}
146
- Assertions .assertTrue(notMatchedExecutions.isEmpty()) { " Not matched test names ${summaries(notMatchedExecutions)} " }
183
+
184
+ val notMatchedMethodNames = methodNames.filter { methodName ->
185
+ this .none { execution -> execution.testMethodName?.equals(methodName) == true }
186
+ }
187
+
188
+ Assertions .assertTrue(notMatchedExecutions.isEmpty() && notMatchedMethodNames.isEmpty()) {
189
+ buildString {
190
+ if (notMatchedExecutions.isNotEmpty()) {
191
+ append(
192
+ " \n The following method names were produced by the UTBot, " +
193
+ " but were not found in the list of method names passed in the check() method:\n\n ${
194
+ methodNamesFromExecutions(
195
+ notMatchedExecutions
196
+ )
197
+ } "
198
+ )
199
+ }
200
+
201
+ if (notMatchedMethodNames.isNotEmpty()) {
202
+ append(
203
+ " \n The following method names were passed in the check() method, " +
204
+ " but were not found in the list of method names produced by the UTBot:\n\n ${
205
+ methodNames(
206
+ notMatchedMethodNames
207
+ )
208
+ } "
209
+ )
210
+ }
211
+ }
212
+ }
147
213
}
148
214
149
215
fun List<UtExecution>.checkMatchersWithDisplayNames (
@@ -155,14 +221,108 @@ open class SummaryTestCaseGeneratorTest(
155
221
val notMatchedExecutions = this .filter { execution ->
156
222
displayNames.none { displayName -> execution.displayName?.equals(displayName) == true }
157
223
}
158
- Assertions .assertTrue(notMatchedExecutions.isEmpty()) { " Not matched display names ${summaries(notMatchedExecutions)} " }
224
+
225
+ val notMatchedDisplayNames = displayNames.filter { displayName ->
226
+ this .none { execution -> execution.displayName?.equals(displayName) == true }
227
+ }
228
+
229
+ Assertions .assertTrue(notMatchedExecutions.isEmpty() && notMatchedDisplayNames.isEmpty()) {
230
+ buildString {
231
+ if (notMatchedExecutions.isNotEmpty()) {
232
+ append(
233
+ " \n The following display names were produced by the UTBot, " +
234
+ " but were not found in the list of display names passed in the check() method:\n\n ${
235
+ displayNamesFromExecutions(
236
+ notMatchedExecutions
237
+ )
238
+ } "
239
+ )
240
+ }
241
+
242
+ if (notMatchedDisplayNames.isNotEmpty()) {
243
+ append(
244
+ " \n The following display names were passed in the check() method, " +
245
+ " but were not found in the list of display names produced by the UTBot:\n\n ${
246
+ displayNames(
247
+ notMatchedDisplayNames
248
+ )
249
+ } "
250
+ )
251
+ }
252
+ }
253
+ }
159
254
}
160
255
161
- private fun summaries (executions : List <UtExecution >): String {
162
- var result = " "
163
- executions.forEach {
164
- result + = it.summary?.joinToString(separator = " " , postfix = " \n " )
256
+ private fun commentsFromExecutions (executions : List <UtExecution >): String {
257
+ return buildString {
258
+ append(COMMENT_SEPARATOR )
259
+ executions.forEach {
260
+ append(NEW_LINE )
261
+ append(NEW_LINE )
262
+ append(it.summary?.joinToString(separator = " " , postfix = NEW_LINE ))
263
+ append(COMMENT_SEPARATOR )
264
+ append(NEW_LINE )
265
+ }
266
+ append(NEW_LINE )
267
+ }
268
+ }
269
+
270
+ private fun comments (comments : List <String >): String {
271
+ return buildString {
272
+ append(COMMENT_SEPARATOR )
273
+ comments.forEach {
274
+ append(NEW_LINE )
275
+ append(NEW_LINE )
276
+ append(it)
277
+ append(NEW_LINE )
278
+ append(COMMENT_SEPARATOR )
279
+ append(NEW_LINE )
280
+ }
281
+ append(NEW_LINE )
282
+ }
283
+ }
284
+
285
+ private fun displayNamesFromExecutions (executions : List <UtExecution >): String {
286
+ return buildString {
287
+ executions.forEach {
288
+ append(POINT_IN_THE_LIST )
289
+ append(it.displayName)
290
+ append(NEW_LINE )
291
+ }
292
+ append(NEW_LINE )
293
+ }
294
+ }
295
+
296
+ private fun displayNames (displayNames : List <String >): String {
297
+ return buildString {
298
+ displayNames.forEach {
299
+ append(POINT_IN_THE_LIST )
300
+ append(it)
301
+ append(NEW_LINE )
302
+ }
303
+ append(NEW_LINE )
304
+ }
305
+ }
306
+
307
+ private fun methodNamesFromExecutions (executions : List <UtExecution >): String {
308
+ return buildString {
309
+ executions.forEach {
310
+ append(POINT_IN_THE_LIST )
311
+ append(it.testMethodName)
312
+ append(NEW_LINE )
313
+ }
314
+ append(NEW_LINE )
315
+ }
316
+ }
317
+
318
+ private fun methodNames (methodNames : List <String >): String {
319
+ return buildString {
320
+ methodNames.forEach {
321
+ append(POINT_IN_THE_LIST )
322
+ append(it)
323
+ append(NEW_LINE )
324
+ }
325
+ append(NEW_LINE )
165
326
}
166
- return result
167
327
}
168
328
}
0 commit comments