-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
UpgradeProject code fixer for C# #17435
Changes from all commits
b61f8f6
5331648
16bee18
6347aa9
a8cde3e
5448bf4
685fafd
d86922f
7e895df
280689b
f3461b0
7752d56
ab8cbf9
7b9d347
97a9af4
e913a27
cb0dae3
1da8634
73d3709
ead449f
2c952ac
5820b9c
2d48bdf
2c5cf56
a6cdef3
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 |
---|---|---|
|
@@ -1325,13 +1325,68 @@ public void LangVersion() | |
} | ||
|
||
[Fact] | ||
public void RememberToUpdateDiagnosticsWhenUpdatingLangVersion() | ||
public void LanguageVersionAdded_Canary() | ||
{ | ||
// When new language versions are added, this test will fail. Remember to update the diagnostics message (ERR_BadCompatMode). | ||
// When a new version is added, this test will break. This list must be checked: | ||
// - update the command-line error for bad /langver flag (<see cref="ErrorCode.ERR_BadCompatMode"/>) | ||
// - update the "UpgradeProject" codefixer | ||
// - update the IDE drop-down for selecting Language Version | ||
// - don't fix the canary test until you update all the tests that include it | ||
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion()); | ||
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.Default.MapSpecifiedToEffectiveVersion()); | ||
} | ||
|
||
[Fact] | ||
public void LanguageVersion_DisplayString() | ||
{ | ||
AssertEx.SetEqual(new[] { "default", "1", "2", "3", "4", "5", "6", "7", "latest" }, | ||
Enum.GetValues(typeof(LanguageVersion)).Cast<LanguageVersion>().Select(v => v.ToDisplayString())); | ||
// For minor versions, the format should be "x.y", such as "7.1" | ||
} | ||
|
||
[Fact] | ||
public void LanguageVersion_MapSpecifiedToEffectiveVersion() | ||
{ | ||
Assert.Equal(LanguageVersion.CSharp1, LanguageVersion.CSharp1.MapSpecifiedToEffectiveVersion()); | ||
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. xunit as "theories" which let you run the same test with a bunch of bits of data like this. 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. Thanks for the suggestion. I gave it a try, but I didn't feel it fit that well. 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. Not sure I understand this, especially when you used a theory for the next test. 😄 |
||
Assert.Equal(LanguageVersion.CSharp2, LanguageVersion.CSharp2.MapSpecifiedToEffectiveVersion()); | ||
Assert.Equal(LanguageVersion.CSharp3, LanguageVersion.CSharp3.MapSpecifiedToEffectiveVersion()); | ||
Assert.Equal(LanguageVersion.CSharp4, LanguageVersion.CSharp4.MapSpecifiedToEffectiveVersion()); | ||
Assert.Equal(LanguageVersion.CSharp5, LanguageVersion.CSharp5.MapSpecifiedToEffectiveVersion()); | ||
Assert.Equal(LanguageVersion.CSharp6, LanguageVersion.CSharp6.MapSpecifiedToEffectiveVersion()); | ||
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.CSharp7.MapSpecifiedToEffectiveVersion()); | ||
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.Default.MapSpecifiedToEffectiveVersion()); | ||
Assert.Equal(LanguageVersion.CSharp7, LanguageVersion.Latest.MapSpecifiedToEffectiveVersion()); | ||
|
||
// The canary check is a reminder that this test needs to be updated when a language version is added | ||
LanguageVersionAdded_Canary(); | ||
} | ||
|
||
[Theory, | ||
InlineData("iso-1", true, LanguageVersion.CSharp1), | ||
InlineData("ISO-1", true, LanguageVersion.CSharp1), | ||
InlineData("iso-2", true, LanguageVersion.CSharp2), | ||
InlineData("1", true, LanguageVersion.CSharp1), | ||
InlineData("2", true, LanguageVersion.CSharp2), | ||
InlineData("3", true, LanguageVersion.CSharp3), | ||
InlineData("4", true, LanguageVersion.CSharp4), | ||
InlineData("5", true, LanguageVersion.CSharp5), | ||
InlineData("05", true, LanguageVersion.CSharp5), | ||
InlineData("6", true, LanguageVersion.CSharp6), | ||
InlineData("7", true, LanguageVersion.CSharp7), | ||
InlineData("07", false, LanguageVersion.Default), | ||
InlineData("default", true, LanguageVersion.Default), | ||
InlineData("latest", true, LanguageVersion.Latest), | ||
InlineData(null, true, LanguageVersion.Default), | ||
InlineData("bad", false, LanguageVersion.Default)] | ||
public void LanguageVersion_TryParseDisplayString(string input, bool success, LanguageVersion expected) | ||
{ | ||
Assert.Equal(success, input.TryParse(out var version)); | ||
Assert.Equal(expected, version); | ||
|
||
// The canary check is a reminder that this test needs to be updated when a language version is added | ||
LanguageVersionAdded_Canary(); | ||
} | ||
|
||
[Fact] | ||
[WorkItem(546961, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/546961")] | ||
public void Define() | ||
|
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.
Support for 7.1 is happening in the other PR? I think so, just trying to wrap my head around it.
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.
Yes, 7.1 will come separately. I'm still trying to work out some logistics (should the 7.1 change be made in a branch? which one? etc).
Also, adding 7.1 separately will be a good dry-run to verify for the checklist.