Update 'UseExpressionBody' tests to the new test library#51623
Update 'UseExpressionBody' tests to the new test library#51623CyrusNajmabadi merged 18 commits intodotnet:mainfrom
Conversation
|
Converting to a draft until I fix test failures. Meanwhile, I'd like to get an initial feedback on this and whether you want to do this. |
src/Analyzers/CSharp/Tests/UseExpressionBody/UseExpressionBodyForPropertiesAnalyzerTests.cs
Outdated
Show resolved
Hide resolved
| UseExpressionBodyDiagnosticAnalyzer, | ||
| UseExpressionBodyCodeFixProvider>; |
There was a problem hiding this comment.
📝 It may be possible to remove the MEF suppressions on the constructor in each of these types
|
@Youssef1313 Definitely the direction we want to take the tests. I recommend converting to the syntax of the new tests first (which is exactly what you did here so far), and then make any corrections to the test (compiler errors, etc.) as separate commits in the PR so we can review those changes separately from the simple API transformation. |
|
@sharwell Should we get |
@sharwell I'm not sure why it expects "0" for fixed state? Here is the test: |
It wasn't viable prior to #46666. Now it probably is, but I'm also not sure it's hurting anything.
You need to set |
src/Analyzers/CSharp/Tests/UseExpressionBody/UseExpressionBodyForPropertiesAnalyzerTests.cs
Show resolved
Hide resolved
|
@sharwell Does "WithNoneEnforcement" in the original test the same as "Never"? The test is failing with "ExpressionBodyPreference.WhenOnSingleLine" as it expects expression body for indexer, while the original test doesn't. |
|
There is also public async Task TestAccessorListFormatting_FixAll()
{
var code = @"
class C
{
int Bar() { return 0; }
int Goo { {|IDE0027:get => Bar();|} {|IDE0027:set => Bar();|} }
}";
var fixedCode = @"
class C
{
int Bar() { return 0; }
int Goo
{
get
{
return Bar();
}
set
{
Bar();
}
}
}";
await TestWithUseBlockBodyIncludingPropertiesAndIndexers(code, fixedCode);
}content of '/0/Test0.cs' did not match. Diff shown with expected as baseline:
class C
{
int Bar() { return 0; }
int Goo
{
- get
+ get { return Bar(); }
- {
- return Bar();
- }
-
set
{
Bar();
}
}
}I can't figure out how it's passing in public async Task TestAccessorListFormatting_FixAll()
{
await TestInRegularAndScriptAsync(
@"class C
{
int Goo { get {|FixAllInDocument:=>|} Bar(); set => Bar(); }
}",
@"class C
{
int Goo
{
get
{
return Bar();
}
set
{
Bar();
}
}
}", options: UseBlockBodyIncludingPropertiesAndIndexers);
} |
No, you'll need to also pass the third parameter as |
|
@sharwell That worked. The only failing test now is the one I stated in #51623 (comment) I couldn't figure out what's wrong. It's failing with the following diff. class C
{
int Bar() { return 0; }
int Goo
{
- get { return Bar(); }
+ get
+ {
+ return Bar();
+ }
+
set
{
Bar();
}
}
}However, when I update it, it fails with the exact opposite diff. class C
{
int Bar() { return 0; }
int Goo
{
- get
+ get { return Bar(); }
- {
- return Bar();
- }
-
set
{
Bar();
}
}
}Do you know what's going on? I've tried to set |
|
I'm guessing the iterative code fix and the Fix All are producing different results. You can specify both by setting |
|
Thanks @sharwell. I think CI should pass now. |
|
Thanks! |
No description provided.