-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SLVS-1678 Use unique generated compilation database names (#5875)
[SLVS-1678](https://sonarsource.atlassian.net/browse/SLVS-1678) [SLVS-1678]: https://sonarsource.atlassian.net/browse/SLVS-1678?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
- Loading branch information
1 parent
1f0fe81
commit 4b7a22b
Showing
14 changed files
with
422 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/CFamily.UnitTests/CompilationDatabase/ExternalCompilationDatabaseHandleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
using SonarLint.VisualStudio.CFamily.CompilationDatabase; | ||
|
||
namespace SonarLint.VisualStudio.CFamily.UnitTests.CompilationDatabase; | ||
|
||
[TestClass] | ||
public class ExternalCompilationDatabaseHandleTests | ||
{ | ||
[TestMethod] | ||
public void Ctor_AssignsExpectedValues() | ||
{ | ||
const string filePath = "some path"; | ||
var testSubject = new ExternalCompilationDatabaseHandle(filePath); | ||
|
||
testSubject.FilePath.Should().BeSameAs(filePath); | ||
} | ||
|
||
[TestMethod] | ||
public void Ctor_NullPath_Throws() | ||
{ | ||
var act = () => new ExternalCompilationDatabaseHandle(null); | ||
|
||
act.Should().Throw<ArgumentNullException>().Which.ParamName.Should().Be("filePath"); | ||
} | ||
|
||
[TestMethod] | ||
public void Dispose_NoOp_DoesNotThrow() | ||
{ | ||
var act = () => new ExternalCompilationDatabaseHandle("some path").Dispose(); | ||
|
||
act.Should().NotThrow(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/CFamily/CompilationDatabase/ExternalCompilationDatabaseHandle.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
using SonarLint.VisualStudio.Core.CFamily; | ||
|
||
namespace SonarLint.VisualStudio.CFamily.CompilationDatabase; | ||
|
||
internal sealed class ExternalCompilationDatabaseHandle(string filePath) : ICompilationDatabaseHandle | ||
{ | ||
public string FilePath { get; } = filePath ?? throw new ArgumentNullException(nameof(filePath)); | ||
|
||
public void Dispose() | ||
{ | ||
// do nothing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/Integration.Vsix.UnitTests/CFamily/VcxProject/TemporaryCompilationDatabaseHandleTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2024 SonarSource SA | ||
* mailto:info AT sonarsource DOT com | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this program; if not, write to the Free Software Foundation, | ||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
using System.IO.Abstractions; | ||
using NSubstitute.ReceivedExtensions; | ||
using SonarLint.VisualStudio.Integration.Vsix.CFamily.VcxProject; | ||
|
||
namespace SonarLint.VisualStudio.Integration.UnitTests.CFamily.VcxProject; | ||
|
||
[TestClass] | ||
public class TemporaryCompilationDatabaseHandleTests | ||
{ | ||
private const string FilePath = "some path"; | ||
private IFile file; | ||
private TestLogger logger; | ||
private TemporaryCompilationDatabaseHandle testSubject; | ||
|
||
[TestInitialize] | ||
public void TestInitialize() | ||
{ | ||
file = Substitute.For<IFile>(); | ||
logger = new TestLogger(); | ||
testSubject = new TemporaryCompilationDatabaseHandle(FilePath, file, logger); | ||
} | ||
|
||
[DataRow("path1")] | ||
[DataRow(@"path1\path2")] | ||
[DataTestMethod] | ||
public void Ctor_AssignsExpectedValues(string path) => | ||
new TemporaryCompilationDatabaseHandle(path, default, default).FilePath.Should().BeSameAs(path); | ||
|
||
[TestMethod] | ||
public void Ctor_NullPath_Throws() | ||
{ | ||
var act = () => new TemporaryCompilationDatabaseHandle(null, default, default); | ||
|
||
act.Should().Throw<ArgumentNullException>().Which.ParamName.Should().Be("filePath"); | ||
} | ||
|
||
[TestMethod] | ||
public void Dispose_DeletesFile() | ||
{ | ||
testSubject.Dispose(); | ||
|
||
file.Received().Delete(FilePath); | ||
logger.AssertNoOutputMessages(); | ||
} | ||
|
||
[TestMethod] | ||
public void Dispose_MultipleTimes_ActsOnlyOnce() | ||
{ | ||
testSubject.Dispose(); | ||
testSubject.Dispose(); | ||
testSubject.Dispose(); | ||
|
||
file.ReceivedWithAnyArgs(1).Delete(default); | ||
} | ||
|
||
[TestMethod] | ||
public void Dispose_CatchesAndLogsExceptions() | ||
{ | ||
var exception = new Exception("testexc"); | ||
file.When(x => x.Delete(Arg.Any<string>())).Throw(exception); | ||
|
||
var act = () => testSubject.Dispose(); | ||
|
||
act.Should().NotThrow(); | ||
logger.AssertPartialOutputStringExists(exception.ToString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.