From 04417046b90400cf1ad2ec2d5db282bbde48a8ea Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Mon, 27 Jul 2020 10:18:05 -0700 Subject: [PATCH] Make certain errors expected --- ...ateEqualsAndGetHashCodeFromMembersTests.cs | 153 +++++------------- 1 file changed, 39 insertions(+), 114 deletions(-) diff --git a/src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs b/src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs index 9a76d9cf548..076a9149e44 100644 --- a/src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs +++ b/src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs @@ -283,7 +283,7 @@ public async Task TestReferenceIEquatable() using System; using System.Collections.Generic; -class S : IEquatable { } +class S : {|CS0535:IEquatable|} { } class Program { @@ -293,7 +293,7 @@ class Program using System; using System.Collections.Generic; -class S : IEquatable { } +class S : {|CS0535:IEquatable|} { } class Program { @@ -306,12 +306,7 @@ public override bool Equals(object obj) EqualityComparer.Default.Equals(a, program.a); } }", -parameters: CSharp6Implicit, -expectedDiagnostics: new List -{ - // /0/Test0.cs(5,11): error CS0535: 'S' does not implement interface member 'IEquatable.Equals(S)' - DiagnosticResult.CompilerError("CS0535").WithSpan(5, 11, 5, 24).WithArguments("S", "System.IEquatable.Equals(S)"), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -323,7 +318,7 @@ public async Task TestNullableReferenceIEquatable() using System; using System.Collections.Generic; -class S : IEquatable { } +class S : {|CS0535:IEquatable|} { } class Program { @@ -334,7 +329,7 @@ class Program using System; using System.Collections.Generic; -class S : IEquatable { } +class S : {|CS0535:IEquatable|} { } class Program { @@ -350,12 +345,7 @@ public override int GetHashCode() { return -1757793268 + EqualityComparer.Default.GetHashCode(a); } -}", index: 1, options: PreferImplicitTypeWithInfo(), -expectedDiagnostics: new List -{ - // /0/Test0.cs(6,11): error CS0535: 'S' does not implement interface member 'IEquatable.Equals(S)' - DiagnosticResult.CompilerError("CS0535").WithSpan(6, 11, 6, 24).WithArguments("S", "System.IEquatable.Equals(S)"), -}); +}", index: 1, options: PreferImplicitTypeWithInfo()); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -366,7 +356,7 @@ public async Task TestValueIEquatable() using System; using System.Collections.Generic; -struct S : IEquatable { } +struct S : {|CS0535:IEquatable|} { } class Program { @@ -376,7 +366,7 @@ class Program using System; using System.Collections.Generic; -struct S : IEquatable { } +struct S : {|CS0535:IEquatable|} { } class Program { @@ -389,12 +379,7 @@ public override bool Equals(object obj) a.Equals(program.a); } }", -parameters: CSharp6Implicit, -expectedDiagnostics: new List -{ - // /0/Test0.cs(5,12): error CS0535: 'S' does not implement interface member 'IEquatable.Equals(S)' - DiagnosticResult.CompilerError("CS0535").WithSpan(5, 12, 5, 25).WithArguments("S", "System.IEquatable.Equals(S)"), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -710,7 +695,7 @@ public async Task TestEqualsStructAlreadyImplementsIEquatable() @"using System; using System.Collections.Generic; -struct ReallyLongName : IEquatable +struct ReallyLongName : {|CS0535:IEquatable|} { [|int i; @@ -719,7 +704,7 @@ struct ReallyLongName : IEquatable @"using System; using System.Collections.Generic; -struct ReallyLongName : IEquatable +struct ReallyLongName : {|CS0535:IEquatable|} { int i; @@ -741,12 +726,7 @@ public override bool Equals(object obj) { return !(left == right); } -}", -expectedDiagnostics: new List -{ - // /0/Test0.cs(4,25): error CS0535: 'ReallyLongName' does not implement interface member 'IEquatable.Equals(ReallyLongName)' - DiagnosticResult.CompilerError("CS0535").WithSpan(4, 25, 4, 51).WithArguments("ReallyLongName", "System.IEquatable.Equals(ReallyLongName)"), -}); +}"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -797,7 +777,7 @@ public async Task TestEqualsStructAlreadyImplementsIEquatableAndHasOperators() @"using System; using System.Collections.Generic; -struct ReallyLongName : IEquatable +struct ReallyLongName : {|CS0535:IEquatable|} { [|int i; @@ -809,7 +789,7 @@ struct ReallyLongName : IEquatable @"using System; using System.Collections.Generic; -struct ReallyLongName : IEquatable +struct ReallyLongName : {|CS0535:IEquatable|} { int i; @@ -824,11 +804,7 @@ public override bool Equals(object obj) public static bool operator ==(ReallyLongName left, ReallyLongName right) => false; public static bool operator !=(ReallyLongName left, ReallyLongName right) => false; -}", expectedDiagnostics: new List -{ - // /0/Test0.cs(4,25): error CS0535: 'ReallyLongName' does not implement interface member 'IEquatable.Equals(ReallyLongName)' - DiagnosticResult.CompilerError("CS0535").WithSpan(4, 25, 4, 51).WithArguments("ReallyLongName", "System.IEquatable.Equals(ReallyLongName)"), -}); +}"); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -1243,13 +1219,13 @@ public async Task Tuple_Disabled() class C { - [|(int, string) a;|] + [|{|CS8059:(int, string)|} a;|] }", @"using System.Collections.Generic; class C { - (int, string) a; + {|CS8059:(int, string)|} a; public override bool Equals(object obj) { @@ -1259,12 +1235,7 @@ public override bool Equals(object obj) } }", index: 0, -parameters: CSharp6Implicit, -expectedDiagnostics: new List -{ - // /0/Test0.cs(5,5): error CS8059: Feature 'tuples' is not available in C# 6. Please use language version 7.0 or greater. - DiagnosticResult.CompilerError("CS8059").WithSpan(5, 5, 5, 18).WithArguments("tuples", "7.0"), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -1275,13 +1246,13 @@ public async Task Tuples_Equals() class C { - [|(int, string) a;|] + [|{|CS8059:(int, string)|} a;|] }", @"using System.Collections.Generic; class C { - (int, string) a; + {|CS8059:(int, string)|} a; public override bool Equals(object obj) { @@ -1290,12 +1261,7 @@ public override bool Equals(object obj) a.Equals(c.a); } }", -parameters: CSharp6Implicit, -expectedDiagnostics: new List -{ - // /0/Test0.cs(5,5): error CS8059: Feature 'tuples' is not available in C# 6. Please use language version 7.0 or greater. - DiagnosticResult.CompilerError("CS8059").WithSpan(5, 5, 5, 18).WithArguments("tuples", "7.0"), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -1306,13 +1272,13 @@ public async Task TupleWithNames_Equals() class C { - [|(int x, string y) a;|] + [|{|CS8059:(int x, string y)|} a;|] }", @"using System.Collections.Generic; class C { - (int x, string y) a; + {|CS8059:(int x, string y)|} a; public override bool Equals(object obj) { @@ -1321,12 +1287,7 @@ public override bool Equals(object obj) a.Equals(c.a); } }", -parameters: CSharp6Implicit, -expectedDiagnostics: new List -{ - // /0/Test0.cs(5,5): error CS8059: Feature 'tuples' is not available in C# 6. Please use language version 7.0 or greater. - DiagnosticResult.CompilerError("CS8059").WithSpan(5, 5, 5, 22).WithArguments("tuples", "7.0"), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -1337,13 +1298,13 @@ public async Task Tuple_HashCode() class Program { - [|(int, string) i;|] + [|{|CS8059:(int, string)|} i;|] }", @"using System.Collections.Generic; class Program { - (int, string) i; + {|CS8059:(int, string)|} i; public override bool Equals(object obj) { @@ -1358,12 +1319,7 @@ public override int GetHashCode() } }", index: 1, -parameters: CSharp6Implicit, -expectedDiagnostics: new List -{ - // /0/Test0.cs(5,5): error CS8059: Feature 'tuples' is not available in C# 6. Please use language version 7.0 or greater. - DiagnosticResult.CompilerError("CS8059").WithSpan(5, 5, 5, 18).WithArguments("tuples", "7.0"), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -1374,13 +1330,13 @@ public async Task TupleWithNames_HashCode() class Program { - [|(int x, string y) i;|] + [|{|CS8059:(int x, string y)|} i;|] }", @"using System.Collections.Generic; class Program { - (int x, string y) i; + {|CS8059:(int x, string y)|} i; public override bool Equals(object obj) { @@ -1395,12 +1351,7 @@ public override int GetHashCode() } }", index: 1, -parameters: CSharp6Implicit, -expectedDiagnostics: new List -{ - // /0/Test0.cs(5,5): error CS8059: Feature 'tuples' is not available in C# 6. Please use language version 7.0 or greater. - DiagnosticResult.CompilerError("CS8059").WithSpan(5, 5, 5, 22).WithArguments("tuples", "7.0"), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -1976,7 +1927,7 @@ class Program public string s; [||] - public static bool operator ==(Program left, Program right) => true; + public static bool operator {|CS0216:==|}(Program left, Program right) => true; }", @" using System.Collections.Generic; @@ -1992,21 +1943,11 @@ public override bool Equals(object obj) s == program.s; } - public static bool operator ==(Program left, Program right) => true; + public static bool operator {|CS0216:==|}(Program left, Program right) => true; }", chosenSymbols: null, optionsCallback: options => Assert.Null(options.FirstOrDefault(i => i.Id == GenerateOperatorsId)), -parameters: CSharp6Implicit, -testExpectedDiagnostics: new List -{ - // /0/Test0.cs(9,33): error CS0216: The operator 'Program.operator ==(Program, Program)' requires a matching operator '!=' to also be defined - DiagnosticResult.CompilerError("CS0216").WithSpan(9, 33, 9, 35).WithArguments("Program.operator ==(Program, Program)", "!="), -}, -fixedExpectedDiagnostics: new List -{ - // /0/Test0.cs(15,33): error CS0216: The operator 'Program.operator ==(Program, Program)' requires a matching operator '!=' to also be defined - DiagnosticResult.CompilerError("CS0216").WithSpan(15, 33, 15, 35).WithArguments("Program.operator ==(Program, Program)", "!="), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -2450,7 +2391,7 @@ public async Task TestDoNotOfferIEquatableIfTypeAlreadyImplementsIt() @" using System.Collections.Generic; -class Program : System.IEquatable +class Program : {|CS0535:System.IEquatable|} { public string s; [||] @@ -2458,7 +2399,7 @@ class Program : System.IEquatable @" using System.Collections.Generic; -class Program : System.IEquatable +class Program : {|CS0535:System.IEquatable|} { public string s; @@ -2471,12 +2412,7 @@ public override bool Equals(object obj) }", chosenSymbols: null, optionsCallback: options => Assert.Null(options.FirstOrDefault(i => i.Id == ImplementIEquatableId)), -parameters: CSharp6Implicit, -expectedDiagnostics: new List -{ - // /0/Test0.cs(4,17): error CS0535: 'Program' does not implement interface member 'IEquatable.Equals(Program)' - DiagnosticResult.CompilerError("CS0535").WithSpan(4, 17, 4, 43).WithArguments("Program", "System.IEquatable.Equals(Program)"), -}); +parameters: CSharp6Implicit); } [Fact, Trait(Traits.Feature, Traits.Features.CodeActionsGenerateEqualsAndGetHashCode)] @@ -3480,11 +3416,11 @@ public async Task TestAbstractBase() abstract class Base { - public abstract override bool Equals(object? obj); + public abstract override bool Equals(object{|CS8632:?|} obj); public abstract override int GetHashCode(); } -class Derived : Base +class {|CS0534:{|CS0534:Derived|}|} : Base { [|public int P { get; }|] }", @@ -3494,7 +3430,7 @@ namespace System { public struct HashCode { } } abstract class Base { - public abstract override bool Equals(object? obj); + public abstract override bool Equals(object{|CS8632:?|} obj); public abstract override int GetHashCode(); } @@ -3515,19 +3451,8 @@ public override int GetHashCode() }", index: 1, parameters: CSharpLatest, -testExpectedDiagnostics: new List -{ - // /0/Test0.cs(5,48): error CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. - DiagnosticResult.CompilerError("CS8632").WithSpan(5, 48, 5, 49), - // /0/Test0.cs(9,7): error CS0534: 'Derived' does not implement inherited abstract member 'Base.Equals(object?)' - DiagnosticResult.CompilerError("CS0534").WithSpan(9, 7, 9, 14).WithArguments("Derived", "Base.Equals(object?)"), - // /0/Test0.cs(9,7): error CS0534: 'Derived' does not implement inherited abstract member 'Base.GetHashCode()' - DiagnosticResult.CompilerError("CS0534").WithSpan(9, 7, 9, 14).WithArguments("Derived", "Base.GetHashCode()"), -}, fixedExpectedDiagnostics: new List { - // /0/Test0.cs(7,48): error CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. - DiagnosticResult.CompilerError("CS8632").WithSpan(7, 48, 7, 49), // /0/Test0.cs(23,25): error CS0117: 'HashCode' does not contain a definition for 'Combine' DiagnosticResult.CompilerError("CS0117").WithSpan(23, 25, 23, 32).WithArguments("System.HashCode", "Combine"), }); -- GitLab