Skip to content

Commit 3cd1a90

Browse files
committed
Fix unreliable test
1 parent 8b5e581 commit 3cd1a90

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

SonarScanner.Shim/ProjectLoader.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@
1717
* along with this program; if not, write to the Free Software Foundation,
1818
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
1919
*/
20-
21-
using SonarQube.Common;
22-
using System;
20+
2321
using System.Collections.Generic;
2422
using System.IO;
25-
using System.Linq;
26-
using System.Text;
23+
using SonarQube.Common;
2724

2825
namespace SonarScanner.Shim
2926
{

Tests/SonarScanner.Shim.Tests/PropertiesFileGeneratorTests.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,13 @@ public void FileGen_SharedFiles_CaseInsensitive()
398398
{
399399
// Arrange
400400
string testDir = TestUtils.CreateTestSpecificFolder(this.TestContext);
401+
// Create 2 uuids and order them so that test is reproducible
402+
Guid[] uuids = new Guid[] { Guid.NewGuid(), Guid.NewGuid() };
403+
Array.Sort(uuids);
401404

402405
string project1Dir = TestUtils.EnsureTestSpecificFolder(this.TestContext, "project1");
403406
string project1Path = Path.Combine(project1Dir, "project1.proj");
404-
string project1Info = CreateProjectInfoInSubDir(testDir, "projectName1", Guid.NewGuid(), ProjectType.Product, false, project1Path, "UTF-8"); // not excluded
407+
string project1Info = CreateProjectInfoInSubDir(testDir, "projectName1", uuids[0], ProjectType.Product, false, project1Path, "UTF-8"); // not excluded
405408
var sharedFile = Path.Combine(testDir, "contentFile.txt");
406409
var sharedFileDifferentCase = Path.Combine(testDir, "ContentFile.TXT");
407410
CreateEmptyFile(testDir, "contentFile.txt");
@@ -412,7 +415,7 @@ public void FileGen_SharedFiles_CaseInsensitive()
412415

413416
string project2Dir = TestUtils.EnsureTestSpecificFolder(this.TestContext, "project2");
414417
string project2Path = Path.Combine(project2Dir, "project2.proj");
415-
string project2Info = CreateProjectInfoInSubDir(testDir, "projectName2", Guid.NewGuid(), ProjectType.Product, false, project2Path, "UTF-8"); // not excluded
418+
string project2Info = CreateProjectInfoInSubDir(testDir, "projectName2", uuids[1], ProjectType.Product, false, project2Path, "UTF-8"); // not excluded
416419

417420
// Reference shared file, but not under the project directory
418421
string contentFileList2 = CreateFile(project2Dir, "contentList.txt", sharedFileDifferentCase);
@@ -427,6 +430,7 @@ public void FileGen_SharedFiles_CaseInsensitive()
427430
// Assert
428431
SQPropertiesFileReader provider = new SQPropertiesFileReader(result.FullPropertiesFilePath);
429432
provider.AssertSettingExists("sonar.projectBaseDir", testDir);
433+
// First one wins
430434
provider.AssertSettingExists("sonar.sources", sharedFile);
431435
}
432436

@@ -856,7 +860,7 @@ private static string CreateProjectInfoInSubDir(string parentDir,
856860
string projectName, Guid projectGuid, ProjectType projectType, bool isExcluded, string fullProjectPath, string encoding,
857861
AnalysisProperties additionalProperties = null)
858862
{
859-
string newDir = Path.Combine(parentDir, Guid.NewGuid().ToString());
863+
string newDir = Path.Combine(parentDir, projectName);
860864
Directory.CreateDirectory(newDir); // ensure the directory exists
861865

862866
ProjectInfo project = new ProjectInfo()

0 commit comments

Comments
 (0)