Skip to content

Commit ca3b53c

Browse files
SCAN4NET-991 Fix flaky GenerateResult_ValidFiles test (#2908)
1 parent 83bdc66 commit ca3b53c

File tree

1 file changed

+8
-118
lines changed

1 file changed

+8
-118
lines changed

Tests/SonarScanner.MSBuild.Shim.Test/ScannerEngineInputGeneratorTest.GenerateResult.cs

Lines changed: 8 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ namespace SonarScanner.MSBuild.Shim.Test;
2222

2323
public partial class ScannerEngineInputGeneratorTest
2424
{
25-
private static string EscapedDirectorySeparator => Path.DirectorySeparatorChar == '\\' ? @"\\" : Path.DirectorySeparatorChar.ToString();
26-
2725
[TestMethod]
2826
public void GenerateResult_NoProjectInfoFiles()
2927
{
@@ -46,7 +44,6 @@ public void GenerateResult_ValidFiles()
4644
{
4745
// Only non-excluded projects with files to analyze should be marked as valid
4846
var testDir = TestUtils.CreateTestSpecificFolderWithSubPaths(TestContext);
49-
var testDirEscaped = testDir.Replace(@"\", @"\\");
5047
var withoutFilesDir = Path.Combine(testDir, "withoutFiles");
5148
var withoutFilesGuid = Guid.NewGuid();
5249
var withFiles1Guid = Guid.NewGuid();
@@ -66,121 +63,14 @@ public void GenerateResult_ValidFiles()
6663

6764
// One valid project info file -> file created
6865
AssertScannerInputCreated(result);
69-
result.ScannerEngineInput.ToString().Should().BeIgnoringLineEndings(
70-
$$"""
71-
{
72-
"scannerProperties": [
73-
{
74-
"key": "sonar.scanner.app",
75-
"value": "ScannerMSBuild"
76-
},
77-
{
78-
"key": "sonar.scanner.appVersion",
79-
"value": "{{Utilities.ScannerVersion}}"
80-
},
81-
{
82-
"key": "sonar.scanner.bootstrapStartTime",
83-
"value": "1735689600000"
84-
},
85-
{
86-
"key": "sonar.projectKey",
87-
"value": "{{config.SonarProjectKey}}"
88-
},
89-
{
90-
"key": "sonar.projectName",
91-
"value": "{{config.SonarProjectName}}"
92-
},
93-
{
94-
"key": "sonar.projectVersion",
95-
"value": "1.0"
96-
},
97-
{
98-
"key": "sonar.working.directory",
99-
"value": "{{testDirEscaped}}{{EscapedDirectorySeparator}}.sonar"
100-
},
101-
{
102-
"key": "sonar.projectBaseDir",
103-
"value": "{{testDirEscaped}}{{EscapedDirectorySeparator}}projects"
104-
},
105-
{
106-
"key": "sonar.sources",
107-
"value": ""
108-
},
109-
{
110-
"key": "sonar.tests",
111-
"value": ""
112-
},
113-
{
114-
"key": "sonar.modules",
115-
"value": "{{withFiles1Guid.ToString().ToUpper()}},{{withFiles2Guid.ToString().ToUpper()}}"
116-
},
117-
{
118-
"key": "{{withFiles1Guid.ToString().ToUpper()}}.sonar.projectKey",
119-
"value": "{{config.SonarProjectKey}}:{{withFiles1Guid.ToString().ToUpper()}}"
120-
},
121-
{
122-
"key": "{{withFiles1Guid.ToString().ToUpper()}}.sonar.projectName",
123-
"value": "withFiles1"
124-
},
125-
{
126-
"key": "{{withFiles1Guid.ToString().ToUpper()}}.sonar.projectBaseDir",
127-
"value": "{{testDirEscaped}}{{EscapedDirectorySeparator}}projects{{EscapedDirectorySeparator}}withFiles1"
128-
},
129-
{
130-
"key": "{{withFiles1Guid.ToString().ToUpper()}}.sonar.working.directory",
131-
"value": "{{testDirEscaped}}{{EscapedDirectorySeparator}}.sonar{{EscapedDirectorySeparator}}mod0"
132-
},
133-
{
134-
"key": "{{withFiles1Guid.ToString().ToUpper()}}.sonar.sourceEncoding",
135-
"value": "utf-8"
136-
},
137-
{
138-
"key": "{{withFiles1Guid.ToString().ToUpper()}}.sonar.tests",
139-
"value": ""
140-
},
141-
{
142-
"key": "{{withFiles1Guid.ToString().ToUpper()}}.sonar.sources",
143-
"value": "{{testDirEscaped}}{{EscapedDirectorySeparator}}projects{{EscapedDirectorySeparator}}withFiles1{{EscapedDirectorySeparator}}contentFile1.txt"
144-
},
145-
{
146-
"key": "{{withFiles2Guid.ToString().ToUpper()}}.sonar.projectKey",
147-
"value": "{{config.SonarProjectKey}}:{{withFiles2Guid.ToString().ToUpper()}}"
148-
},
149-
{
150-
"key": "{{withFiles2Guid.ToString().ToUpper()}}.sonar.projectName",
151-
"value": "withFiles2"
152-
},
153-
{
154-
"key": "{{withFiles2Guid.ToString().ToUpper()}}.sonar.projectBaseDir",
155-
"value": "{{testDirEscaped}}{{EscapedDirectorySeparator}}projects{{EscapedDirectorySeparator}}withFiles2"
156-
},
157-
{
158-
"key": "{{withFiles2Guid.ToString().ToUpper()}}.sonar.working.directory",
159-
"value": "{{testDirEscaped}}{{EscapedDirectorySeparator}}.sonar{{EscapedDirectorySeparator}}mod1"
160-
},
161-
{
162-
"key": "{{withFiles2Guid.ToString().ToUpper()}}.sonar.sourceEncoding",
163-
"value": "utf-8"
164-
},
165-
{
166-
"key": "{{withFiles2Guid.ToString().ToUpper()}}.sonar.tests",
167-
"value": ""
168-
},
169-
{
170-
"key": "{{withFiles2Guid.ToString().ToUpper()}}.sonar.sources",
171-
"value": "{{testDirEscaped}}{{EscapedDirectorySeparator}}projects{{EscapedDirectorySeparator}}withFiles2{{EscapedDirectorySeparator}}contentFile1.txt"
172-
},
173-
{
174-
"key": "sonar.visualstudio.enable",
175-
"value": "false"
176-
},
177-
{
178-
"key": "sonar.host.url",
179-
"value": "http://sonarqube.com"
180-
}
181-
]
182-
}
183-
""");
66+
67+
var reader = new ScannerEngineInputReader(result.ScannerEngineInput.ToString());
68+
reader.AssertProperty($"{withFiles1Guid.ToString().ToUpper()}.sonar.projectBaseDir", $"{testDir}{Path.DirectorySeparatorChar}projects{Path.DirectorySeparatorChar}withFiles1");
69+
reader.AssertProperty($"{withFiles1Guid.ToString().ToUpper()}.sonar.tests", string.Empty);
70+
reader.AssertProperty($"{withFiles1Guid.ToString().ToUpper()}.sonar.sources", $"{testDir}{Path.DirectorySeparatorChar}projects{Path.DirectorySeparatorChar}withFiles1{Path.DirectorySeparatorChar}contentFile1.txt");
71+
reader.AssertProperty($"{withFiles2Guid.ToString().ToUpper()}.sonar.projectBaseDir", $"{testDir}{Path.DirectorySeparatorChar}projects{Path.DirectorySeparatorChar}withFiles2");
72+
reader.AssertProperty($"{withFiles2Guid.ToString().ToUpper()}.sonar.tests", string.Empty);
73+
reader.AssertProperty($"{withFiles2Guid.ToString().ToUpper()}.sonar.sources", $"{testDir}{Path.DirectorySeparatorChar}projects{Path.DirectorySeparatorChar}withFiles2{Path.DirectorySeparatorChar}contentFile1.txt");
18474
}
18575

18676
[TestMethod]

0 commit comments

Comments
 (0)