-
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-1717 Fix C++ Language standard recognition when a C language sta…
…ndard is also specified * Only set one language standard for the file * Always set either /TC or /TP flag for the file (/TC for C and /TP for CPP) * Assume the file is C if CompileAs == CompileAsC or if CompileAs != CompileAsCpp and vcFile.ContentType == CCode * ASsume the file is CPP otherwise
- Loading branch information
1 parent
3a63a13
commit e144488
Showing
9 changed files
with
349 additions
and
164 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
43 changes: 43 additions & 0 deletions
43
src/Integration.Vsix.UnitTests/CFamily/VcxProject/CompileAsValueConverterTests.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,43 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2025 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.Integration.Vsix.CFamily.VcxProject; | ||
|
||
namespace SonarLint.VisualStudio.Integration.UnitTests.CFamily.VcxProject; | ||
|
||
[TestClass] | ||
public class CompileAsValueConverterTests | ||
{ | ||
[TestMethod] | ||
[DataRow("", "")] | ||
[DataRow("Default", "")] | ||
[DataRow("CompileAsC", "/TC")] | ||
[DataRow("CompileAsCpp", "/TP")] | ||
public void GetFlagValue_ConvertsToCorrectFlagValue(string input, string output) => | ||
CompileAsValueConverter.GetFlagValue(input).Should().Be(output); | ||
|
||
[TestMethod] | ||
public void GetFlagValue_UnsupportedPropertyValue_Throws() | ||
{ | ||
var act = () => CompileAsValueConverter.GetFlagValue("INVALID"); | ||
|
||
act.Should().Throw<ArgumentException>().WithMessage("Unsupported CompileAs: INVALID"); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
src/Integration.Vsix.UnitTests/CFamily/VcxProject/LanguageFlagsProviderTests.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,69 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2025 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.Integration.Vsix.CFamily.VcxProject; | ||
|
||
namespace SonarLint.VisualStudio.Integration.UnitTests.CFamily.VcxProject; | ||
|
||
[TestClass] | ||
public class LanguageFlagsProviderTests | ||
{ | ||
[TestMethod] | ||
public void GetLanguageConfiguration_DefaultCompileAs_NoContentType_ReturnsCpp() => | ||
new LanguageFlagsProvider("unknown") | ||
.GetLanguageConfiguration("Default", "stdc23", "stdcpp20") | ||
.Should().Be(("/TP", "/std:c++20")); | ||
|
||
[TestMethod] | ||
public void GetLanguageConfiguration_DefaultCompileAs_ContentTypeCppCode_ReturnsCpp() => | ||
new LanguageFlagsProvider("CppCode") | ||
.GetLanguageConfiguration("Default", "stdc23", "stdcpp20") | ||
.Should().Be(("/TP", "/std:c++20")); | ||
|
||
[TestMethod] | ||
public void GetLanguageConfiguration_DefaultCompileAs_ContentTypeCppHeader_ReturnsCpp() => | ||
new LanguageFlagsProvider("CppHeader") | ||
.GetLanguageConfiguration("Default", "stdc23", "stdcpp20") | ||
.Should().Be(("/TP", "/std:c++20")); | ||
|
||
[TestMethod] | ||
public void GetLanguageConfiguration_DefaultCompileAs_ContentTypeCCode_ReturnsC() => | ||
new LanguageFlagsProvider("CCode") | ||
.GetLanguageConfiguration("Default", "stdc23", "stdcpp20") | ||
.Should().Be(("/TC", "/std:c23")); | ||
|
||
[DataTestMethod] | ||
[DataRow("CppCode")] | ||
[DataRow("CCode")] | ||
[DataRow("Default")] | ||
public void GetLanguageConfiguration_CompileAsC_AnyContentType_ReturnsC(string contentType) => | ||
new LanguageFlagsProvider(contentType) | ||
.GetLanguageConfiguration("CompileAsC", "stdc23", "stdcpp20") | ||
.Should().Be(("/TC", "/std:c23")); | ||
|
||
[DataTestMethod] | ||
[DataRow("CppCode")] | ||
[DataRow("CCode")] | ||
[DataRow("Default")] | ||
public void GetLanguageConfiguration_CompileAsCpp_AnyContentType_ReturnsCpp(string contentType) => | ||
new LanguageFlagsProvider(contentType) | ||
.GetLanguageConfiguration("CompileAsCpp", "stdc23", "stdcpp20") | ||
.Should().Be(("/TP", "/std:c++20")); | ||
} |
66 changes: 66 additions & 0 deletions
66
src/Integration.Vsix.UnitTests/CFamily/VcxProject/LanguageStandardConverterTests.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,66 @@ | ||
/* | ||
* SonarLint for Visual Studio | ||
* Copyright (C) 2016-2025 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.Integration.Vsix.CFamily.VcxProject; | ||
|
||
namespace SonarLint.VisualStudio.Integration.UnitTests.CFamily.VcxProject; | ||
|
||
[TestClass] | ||
public class LanguageStandardConverterTests | ||
{ | ||
|
||
[TestMethod] | ||
[DataRow("", "")] | ||
[DataRow("Default", "")] | ||
[DataRow(null, "")] | ||
[DataRow("stdcpplatest", "/std:c++latest")] | ||
[DataRow("stdcpp20", "/std:c++20")] | ||
[DataRow("stdcpp17", "/std:c++17")] | ||
[DataRow("stdcpp14", "/std:c++14")] | ||
public void GetCppStandardFlagValue(string input, string output) => | ||
LanguageStandardConverter.GetCppStandardFlagValue(input).Should().Be(output); | ||
|
||
[TestMethod] | ||
public void GetCppStandardFlagValue_UnsupportedValue_Throws() | ||
{ | ||
var act = () => LanguageStandardConverter.GetCppStandardFlagValue("INVALID"); | ||
|
||
act.Should().Throw<ArgumentException>().WithMessage("Unsupported LanguageStandard: INVALID"); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow("", "")] | ||
[DataRow("Default", "")] | ||
[DataRow(null, "")] | ||
[DataRow("stdclatest", "/std:clatest")] | ||
[DataRow("stdc23", "/std:c23")] | ||
[DataRow("stdc17", "/std:c17")] | ||
[DataRow("stdc11", "/std:c11")] | ||
public void GetCStandardFlagValue(string input, string output) => | ||
LanguageStandardConverter.GetCStandardFlagValue(input).Should().Be(output); | ||
|
||
[TestMethod] | ||
public void GetCStandardFlagValue_UnsupportedValue_Throws() | ||
{ | ||
var act = () => LanguageStandardConverter.GetCStandardFlagValue("INVALID"); | ||
|
||
act.Should().Throw<ArgumentException>().WithMessage("Unsupported LanguageStandard_C: INVALID"); | ||
} | ||
} |
Oops, something went wrong.