-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added test to for ConfigurationContext #10535
Changes from all commits
c5c7191
49d9359
4b99164
26c44ef
9791e8e
5a7d67d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: ": An extra message for the check" |
||
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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: i beleive you can use the existing ReadEditorConfig() method located in the same file EndToEndTests.cs in order to populate config |
||
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)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ root = true | |
|
||
[*.csproj] | ||
build_check.X01234.Severity=X01234Severity | ||
build_check.X01234.CustomConfig=dummy |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,19 @@ public sealed class Check1 : Check | |
|
||
public override IReadOnlyList<CheckRule> SupportedRules { get; } = new List<CheckRule>() { SupportedRule }; | ||
|
||
private string message = "Argument for the message format"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: message -> _message |
||
|
||
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<EvaluatedProperties | |
context.ReportResult(BuildCheckResult.Create( | ||
SupportedRule, | ||
ElementLocation.EmptyLocation, | ||
"Argument for the message format")); | ||
message)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you need env here and not the global _env?