From 3a5f1f74023de116c0f74eeccf9cd05db6eec629 Mon Sep 17 00:00:00 2001 From: Michael Jabbour Date: Thu, 28 Nov 2024 21:13:55 +0100 Subject: [PATCH] Include language information for headers in the command line This helps analyze headers in C projects as C code. This is needed now that we no longer pass HeaderFileLanguage separately to the analyzer. --- .../CFamily/CmdBuilderTests.cs | 10 +++++----- .../CFamily/VcxProject/FileConfigTests.cs | 12 +++++++++++- .../CFamily/VcxProject/CmdBuilder.cs | 5 +---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs b/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs index eaf1bd6a60..352b49b5d6 100644 --- a/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs +++ b/src/Integration.Vsix.UnitTests/CFamily/CmdBuilderTests.cs @@ -318,10 +318,10 @@ 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(); @@ -329,7 +329,7 @@ public void HeaderFileLang(string compileAs, string lang) cmdBuilder.AddOptFromProperties(settingsMock.Object); - cmdBuilder.GetFullCmd().Should().Be(""); + cmdBuilder.GetFullCmd().Should().Be(cmd); cmdBuilder.HeaderFileLang.Should().Be(lang); } diff --git a/src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs b/src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs index be9ff0e454..a5e982f083 100644 --- a/src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs +++ b/src/Integration.Vsix.UnitTests/CFamily/VcxProject/FileConfigTests.cs @@ -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] diff --git a/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs b/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs index 5774d6170f..6fdbf642a6 100644 --- a/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs +++ b/src/Integration.Vsix/CFamily/VcxProject/CmdBuilder.cs @@ -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");