@@ -146,7 +146,7 @@ class SarifReport(
146
146
val sourceRelativePath = sourceFinding.getSourceRelativePath(classFqn)
147
147
val startLine = extractLineNumber(utExecution) ? : defaultLineNumber
148
148
val sourceCode = sourceFinding.getSourceFile(classFqn)?.readText() ? : " "
149
- val sourceRegion = SarifRegion .fromStartLine(startLine, sourceCode )
149
+ val sourceRegion = SarifRegion .withStartLine(sourceCode, startLine )
150
150
return listOf (
151
151
SarifPhysicalLocationWrapper (
152
152
SarifPhysicalLocation (SarifArtifact (sourceRelativePath), sourceRegion)
@@ -157,11 +157,11 @@ class SarifReport(
157
157
private fun getRelatedLocations (utExecution : UtExecution ): List <SarifRelatedPhysicalLocationWrapper > {
158
158
val startLine = utExecution.testMethodName?.let { testMethodName ->
159
159
val neededLine = generatedTestsCode.split(' \n ' ).indexOfFirst { line ->
160
- line.contains(testMethodName)
160
+ line.contains(" $ testMethodName( " )
161
161
}
162
162
if (neededLine == - 1 ) null else neededLine + 1 // to one-based
163
163
} ? : defaultLineNumber
164
- val sourceRegion = SarifRegion .fromStartLine(startLine, generatedTestsCode )
164
+ val sourceRegion = SarifRegion .withStartLine(generatedTestsCode, startLine )
165
165
return listOf (
166
166
SarifRelatedPhysicalLocationWrapper (
167
167
relatedLocationId,
@@ -235,7 +235,7 @@ class SarifReport(
235
235
),
236
236
physicalLocation = SarifPhysicalLocation (
237
237
SarifArtifact (relativePath),
238
- SarifRegion .fromStartLine(lineNumber, sourceCode )
238
+ SarifRegion .withStartLine(sourceCode, lineNumber )
239
239
)
240
240
)
241
241
)
@@ -256,18 +256,23 @@ class SarifReport(
256
256
// searching needed method call
257
257
val publicMethodCallPattern = " $methodName ("
258
258
val privateMethodCallPattern = Regex (""" $methodName .*\.invoke\(""" ) // using reflection
259
- val methodCallLineNumber = testsBodyLines
259
+ val methodCallShiftInTestMethod = testsBodyLines
260
260
.drop(testMethodStartsAt + 1 ) // for search after it
261
261
.indexOfFirst { line ->
262
262
line.contains(publicMethodCallPattern) || line.contains(privateMethodCallPattern)
263
263
}
264
- if (methodCallLineNumber == - 1 )
264
+ if (methodCallShiftInTestMethod == - 1 )
265
265
return null
266
266
267
- val startLine = methodCallLineNumber + 1 + testMethodStartsAt + 1
267
+ // `startLine` consists of:
268
+ // shift to the testMethod call (+ testMethodStartsAt)
269
+ // the line with testMethodName (+ 1)
270
+ // shift to the method call (+ methodCallShiftInTestMethod)
271
+ // to one-based (+ 1)
272
+ val startLine = testMethodStartsAt + 1 + methodCallShiftInTestMethod + 1
268
273
return SarifPhysicalLocation (
269
274
SarifArtifact (sourceFinding.testsRelativePath),
270
- SarifRegion .fromStartLine(startLine, generatedTestsCode )
275
+ SarifRegion .withStartLine(generatedTestsCode, startLine )
271
276
)
272
277
}
273
278
0 commit comments