@@ -26,7 +26,7 @@ import com.saveourtool.save.core.utils.ProcessTimeoutException
2626import com.saveourtool.save.core.utils.calculatePathToSarifFile
2727import com.saveourtool.save.core.utils.singleIsInstance
2828
29- import com.saveourtool.sarifutils.cli. adapter.SarifFixAdapter
29+ import com.saveourtool.sarifutils.adapter.SarifFixAdapter
3030import io.github.petertrr.diffutils.diff
3131import io.github.petertrr.diffutils.patch.ChangeDelta
3232import io.github.petertrr.diffutils.patch.Delta
@@ -124,7 +124,13 @@ class FixPlugin(
124124 val stdout = executionResult.stdout
125125 val stderr = executionResult.stderr
126126
127- buildTestResultsForChunk(testToExpectedFilesMap, adjustedTestCopyToExpectedFilesMap, execCmd, stdout, stderr)
127+ buildTestResultsForChunk(
128+ testToExpectedFilesMap,
129+ adjustedTestCopyToExpectedFilesMap,
130+ execCmd,
131+ stdout,
132+ stderr
133+ )
128134 }
129135 .flatten()
130136 }
@@ -202,9 +208,10 @@ class FixPlugin(
202208 // modify existing map, replace test copies to fixed test copies
203209 val fixedTestCopyToExpectedFilesMap = testCopyToExpectedFilesMap.toMutableList().map { (testCopy, expected) ->
204210 val fixedTestCopy = fixedFiles.first {
205- // FixMe: Until https://github.com/saveourtool/sarif-utils/issues/23
206- // FixMe: compare only by names, but should by full paths
207- it.name == testCopy.name
211+ isComparingTestAndCopy(
212+ it,
213+ testCopy
214+ )
208215 }
209216 fixedTestCopy to expected
210217 }
@@ -226,7 +233,7 @@ class FixPlugin(
226233 testCopyToExpectedFilesMap : List <PathPair >,
227234 execCmd : String ,
228235 stdout : List <String >,
229- stderr : List <String >,
236+ stderr : List <String >
230237 ): List <TestResult > = testCopyToExpectedFilesMap.map { (testCopy, expected) ->
231238 val fixedLines = fs.readLines(testCopy)
232239 val expectedLines = fs.readLines(expected)
@@ -246,19 +253,49 @@ class FixPlugin(
246253 )
247254 }
248255
249- private fun isComparingTestAndCopy (test : Path , testCopy : Path ): Boolean {
250- // TestCopyPath stored in tmpDir, holding the whole hierarchy of original file
251- // while testPath comes to us with path, starting from testRootPath, so we compare them in such way
252- val testCopyPath = testCopy.relativeTo(FileSystem .SYSTEM_TEMPORARY_DIRECTORY )
253- .toString()
254- .substringAfter(Path .DIRECTORY_SEPARATOR )
255- .toPath()
256+ private fun isComparingTestAndCopy (
257+ test : Path ,
258+ testCopy : Path ,
259+ ): Boolean {
260+ val testPath = test.trimTmpDir().trimTestRootPath().replaceSeparators()
261+ val testCopyPath = testCopy.trimTmpDir().trimTestRootPath().replaceSeparators()
262+ return testCopyPath.compareTo(testPath) == 0
263+ }
256264
257- val testPath = test.createRelativePathToTheRoot(testConfig.getRootConfig().directory).toPath()
265+ private fun Path.trimTmpDir (): Path {
266+ val currentPathAdjusted = this .toString().replaceSeparators()
267+ val tmpDirAdjusted = FileSystem .SYSTEM_TEMPORARY_DIRECTORY .toString().replaceSeparators()
268+ return if (currentPathAdjusted.startsWith(tmpDirAdjusted)) {
269+ currentPathAdjusted
270+ // trim tmpDir
271+ .substringAfter(" $tmpDirAdjusted /" )
272+ // trim tmp FixPlugin dir
273+ .substringAfter(" /" )
274+ .toPath()
275+ } else {
276+ this
277+ }
278+ }
258279
259- return testCopyPath.compareTo(testPath) == 0
280+ private fun Path.trimTestRootPath (): Path {
281+ val currentPathAdjusted = this .toString().replaceSeparators()
282+ val testRootPathAdjusted = testConfig.getRootConfig()
283+ .directory
284+ .toString()
285+ .replaceSeparators()
286+ return if (currentPathAdjusted.startsWith(testRootPathAdjusted)) {
287+ currentPathAdjusted
288+ .substringAfter(" $testRootPathAdjusted /" )
289+ .toPath()
290+ } else {
291+ this
292+ }
260293 }
261294
295+ private fun String.replaceSeparators (): String = this .replace(" \\ " , " /" )
296+
297+ private fun Path.replaceSeparators (): Path = this .toString().replaceSeparators().toPath()
298+
262299 private fun failTestResult (
263300 chunk : List <FixTestFiles >,
264301 ex : ProcessExecutionException ,
0 commit comments