diff --git a/src/BuildCheck.UnitTests/EndToEndTests.cs b/src/BuildCheck.UnitTests/EndToEndTests.cs index 358f8725b90..be460ba4062 100644 --- a/src/BuildCheck.UnitTests/EndToEndTests.cs +++ b/src/BuildCheck.UnitTests/EndToEndTests.cs @@ -172,6 +172,38 @@ public void EditorConfig_SeverityAppliedCorrectly(string BC0101Severity, string } } + [Fact] + public void CheckHasAccessToAllConfigs() + { + using (var env = TestEnvironment.Create()) + { + string checkCandidatePath = Path.Combine(TestAssetsRootPath, "CheckCandidate"); + string message = ": An extra message for the analyzer"; + string severity = "warning"; + + // Can't use Transitive environment due to the need to dogfood local nuget packages. + AddCustomDataSourceToNugetConfig(checkCandidatePath); + string editorConfigName = Path.Combine(checkCandidatePath, EditorConfigFileName); + File.WriteAllText(editorConfigName, ReadEditorConfig( + new List<(string, string)>() { ("X01234", severity) }, + new List<(string, (string, string))> + { + ("X01234",("setMessage", message)) + }, + checkCandidatePath)); + + string projectCheckBuildLog = RunnerUtilities.ExecBootstrapedMSBuild( + $"{Path.Combine(checkCandidatePath, $"CheckCandidate.csproj")} /m:1 -nr:False -restore -check -verbosity:n", out bool success, timeoutMilliseconds: 1200_0000); + success.ShouldBeTrue(); + + projectCheckBuildLog.ShouldContain("warning X01234"); + projectCheckBuildLog.ShouldContain(severity + message); + + // Cleanup + File.Delete(editorConfigName); + } + } + [Theory] [InlineData(true, true)] [InlineData(false, true)] diff --git a/src/BuildCheck.UnitTests/TestAssets/CheckCandidate/.editorconfigtest b/src/BuildCheck.UnitTests/TestAssets/CheckCandidate/.editorconfigtest index be166e833cd..0a06c0d3eb8 100644 --- a/src/BuildCheck.UnitTests/TestAssets/CheckCandidate/.editorconfigtest +++ b/src/BuildCheck.UnitTests/TestAssets/CheckCandidate/.editorconfigtest @@ -2,3 +2,4 @@ root = true [*.csproj] build_check.X01234.Severity=X01234Severity +build_check.X01234.CustomConfig=dummy diff --git a/src/BuildCheck.UnitTests/TestAssets/CustomCheck/Check1.cs b/src/BuildCheck.UnitTests/TestAssets/CustomCheck/Check1.cs index 940791d3705..860f0138c42 100644 --- a/src/BuildCheck.UnitTests/TestAssets/CustomCheck/Check1.cs +++ b/src/BuildCheck.UnitTests/TestAssets/CustomCheck/Check1.cs @@ -17,9 +17,19 @@ public sealed class Check1 : Check public override IReadOnlyList SupportedRules { get; } = new List() { SupportedRule }; + private string message = "Argument for the message format"; + public override void Initialize(ConfigurationContext configurationContext) { + var infraData = configurationContext.CheckConfig[0]; + var customData = configurationContext.CustomConfigurationData[0].ConfigurationData; // configurationContext to be used only if check needs external configuration data. + if (customData is not null && + configurationContext.CustomConfigurationData[0].RuleId == "X01234" && + customData.TryGetValue("setmessage", out string? setMessage)) + { + message = infraData.Severity + setMessage; + } } public override void RegisterActions(IBuildCheckRegistrationContext registrationContext) @@ -32,7 +42,7 @@ private void EvaluatedPropertiesAction(BuildCheckDataContext