From 98f44a72ea3afed0ce4a52a852eb6e1b6abe2b6e Mon Sep 17 00:00:00 2001 From: Victor Diez Date: Thu, 7 Nov 2024 16:05:13 +0100 Subject: [PATCH 1/3] Fix PRAnalysisTest --- .../sonar/javascript/it/plugin/assertj/BuildResultAssert.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java index 615776cde03..f519573c22f 100644 --- a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java +++ b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java @@ -21,7 +21,6 @@ import static java.lang.String.format; import static java.util.regex.Pattern.compile; -import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assertions.tuple; @@ -150,7 +149,7 @@ public BuildResultAssert generatesUcfgFilesForAll(Path projectPath, String... fi for (var filename : filenames) { Assertions .assertThat(ucfgFiles) - .filteredOn(file -> file.getFileName().toString().contains(filename.replace('.', '_'))) + .filteredOn(file -> filename.replace('.', '_').contains(file.getFileName().toString().replaceFirst("[.][^.]+$", ""))) .isNotEmpty(); } } catch (IOException e) { From f77588fc2b791484f9b800a81329c7812a6c5bb1 Mon Sep 17 00:00:00 2001 From: Victor Diez Date: Thu, 7 Nov 2024 17:24:42 +0100 Subject: [PATCH 2/3] Fix ucfg matching during PRAnalysis test --- .../it/plugin/assertj/BuildResultAssert.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java index f519573c22f..aa5f7782d49 100644 --- a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java +++ b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java @@ -146,10 +146,19 @@ public BuildResultAssert generatesUcfgFilesForAll(Path projectPath, String... fi List ucfgFiles; try { ucfgFiles = findUcfgFilesIn(projectPath); - for (var filename : filenames) { + for (var ucfgFile : ucfgFiles) { + // Filenames: file2_SomeLambdaFunction_yaml + // ucfgFile: /Users/VICTOR~1.DIE/AppData/Local/Temp/junit14107160890921213721/pr-analysis-yaml/.scannerwork/ucfg2/js/daFunction_yaml.ucfgs + // We check if file2_SomeLambdaFunction_yaml contains daFunction_yaml + // or + // Filenames: index.ts + // ucfg: /Users/VICTOR~1.DIE/AppData/Local/Temp/junit2107948845245431806/pr-analysis-ts/.scannerwork/ucfg2/js/sis_ts_index_ts.ucfgs + // We check if sis_ts_index_ts ends with index_ts + + var key = ucfgFile.getFileName().toString().replaceFirst("[.][^.]+$", ""); Assertions - .assertThat(ucfgFiles) - .filteredOn(file -> filename.replace('.', '_').contains(file.getFileName().toString().replaceFirst("[.][^.]+$", ""))) + .assertThat(filenames) + .filteredOn(filename -> filename.replace('.', '_').contains(key) || key.endsWith(filename.replace('.', '_'))) .isNotEmpty(); } } catch (IOException e) { From 23d74e108e8690f291494312d3b7e44d90e44072 Mon Sep 17 00:00:00 2001 From: Victor Diez Date: Thu, 7 Nov 2024 19:45:58 +0100 Subject: [PATCH 3/3] Fix tests --- .../javascript/it/plugin/assertj/BuildResultAssert.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java index aa5f7782d49..70a9345ebf3 100644 --- a/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java +++ b/its/plugin/tests/src/test/java/com/sonar/javascript/it/plugin/assertj/BuildResultAssert.java @@ -148,17 +148,17 @@ public BuildResultAssert generatesUcfgFilesForAll(Path projectPath, String... fi ucfgFiles = findUcfgFilesIn(projectPath); for (var ucfgFile : ucfgFiles) { // Filenames: file2_SomeLambdaFunction_yaml - // ucfgFile: /Users/VICTOR~1.DIE/AppData/Local/Temp/junit14107160890921213721/pr-analysis-yaml/.scannerwork/ucfg2/js/daFunction_yaml.ucfgs - // We check if file2_SomeLambdaFunction_yaml contains daFunction_yaml + // ucfgFile: /Users/VICTOR~1.DIE/AppData/Local/Temp/junit14107160890921213721/pr-analysis-yaml/.scannerwork/ucfg2/js/daFunction_yaml_1.ucfgs + // We check if file2_SomeLambdaFunction_yaml ends with daFunction_yaml // or // Filenames: index.ts // ucfg: /Users/VICTOR~1.DIE/AppData/Local/Temp/junit2107948845245431806/pr-analysis-ts/.scannerwork/ucfg2/js/sis_ts_index_ts.ucfgs // We check if sis_ts_index_ts ends with index_ts - var key = ucfgFile.getFileName().toString().replaceFirst("[.][^.]+$", ""); + var key = ucfgFile.getFileName().toString().replaceFirst("(_\\d+)?[.][^.]+$", ""); // We remove index and extension: _1.ucfgs Assertions .assertThat(filenames) - .filteredOn(filename -> filename.replace('.', '_').contains(key) || key.endsWith(filename.replace('.', '_'))) + .filteredOn(filename -> filename.replace('.', '_').endsWith(key) || key.endsWith(filename.replace('.', '_'))) .isNotEmpty(); } } catch (IOException e) {