Skip to content

Commit

Permalink
Include language information for headers in the command line
Browse files Browse the repository at this point in the history
This helps analyze headers in C projects as C code. This is needed now
that we no longer pass HeaderFileLanguage separately to the analyzer.
  • Loading branch information
michael-jabbour-sonarsource committed Nov 29, 2024
1 parent 377b7a7 commit 0594303
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
10 changes: 5 additions & 5 deletions src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,18 @@ public void AddOptFromProperties(string input, string output, string cmd)
}

[TestMethod]
[DataRow("Default", "cpp")]
[DataRow("CompileAsC", "c")]
[DataRow("CompileAsCpp", "cpp")]
public void HeaderFileLang(string compileAs, string lang)
[DataRow("Default", "cpp", "")]
[DataRow("CompileAsC", "c", "/TC ")]
[DataRow("CompileAsCpp", "cpp", "/TP ")]
public void HeaderFileLang(string compileAs, string lang, string cmd)
{
var cmdBuilder = new CmdBuilder(true);
var settingsMock = new Mock<IVCRulePropertyStorage>();
settingsMock.Setup(x => x.GetEvaluatedPropertyValue(It.IsAny<string>())).Returns<string>(s => s == "CompileAs" ? compileAs : "");

cmdBuilder.AddOptFromProperties(settingsMock.Object);

cmdBuilder.GetFullCmd().Should().Be("");
cmdBuilder.GetFullCmd().Should().Be(cmd);
cmdBuilder.HeaderFileLang.Should().Be(lang);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,18 @@ public void TryGet_HeaderFileOptions_ReturnsValidConfig()
request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.h");

// Assert
Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu \"c:\\dummy\\file.h\"", request.CDCommand);
Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu /TC \"c:\\dummy\\file.h\"", request.CDCommand);
Assert.AreEqual("c", request.HeaderFileLanguage);

// Arrange
projectItemConfig.FileConfigProperties["CompileAs"] = "CompileAsCpp";

// Act
request = FileConfig.TryGet(testLogger, projectItemMock.Object, "c:\\dummy\\file.h");

// Assert
Assert.AreEqual("\"C:\\path\\cl.exe\" /FI\"FHeader.h\" /Yu\"pch.h\" /EHsc /RTCu /TP \"c:\\dummy\\file.h\"", request.CDCommand);
Assert.AreEqual("cpp", request.HeaderFileLanguage);
}

[TestMethod]
Expand Down
5 changes: 1 addition & 4 deletions src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ internal void AddOptFromProperties(IVCRulePropertyStorage properties)
{
HeaderFileLang = (compileAs == "CompileAsC") ? "c" : "cpp";
}
else
{
AddCmdOpt(ConvertCompileAsAndGetLanguage(compileAs));
}
AddCmdOpt(ConvertCompileAsAndGetLanguage(compileAs));

// Additional options
var additionalOptions = properties.GetEvaluatedPropertyValue("AdditionalOptions");
Expand Down

0 comments on commit 0594303

Please sign in to comment.