Skip to content

Commit

Permalink
Update tests to cover more scenarios
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwengier committed May 10, 2021
1 parent beb4d0f commit 333cdbe
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class C
c2.GlobalNamespace.GetMember<NamedTypeSymbol>("C").GetMember("Main"))
};

c2.EmitDifference(baseline, edits, mdStream, ilStream, pdbStream, updatedMethods);
c2.EmitDifference(baseline, edits, s => false, mdStream, ilStream, pdbStream);

var actualIL = ImmutableArray.Create(ilStream.ToArray()).GetMethodIL();
var expectedIL = @"
Expand Down Expand Up @@ -152,7 +152,7 @@ class C
c2.GlobalNamespace.GetMember<NamedTypeSymbol>("C").GetMember("Main"))
};

c2.EmitDifference(baseline, edits, mdStream, ilStream, pdbStream, updatedMethods);
c2.EmitDifference(baseline, edits, s => false, mdStream, ilStream, pdbStream);

var actualIL = ImmutableArray.Create(ilStream.ToArray()).GetMethodIL();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ static IEnumerable<int> G()
using var md1 = diff1.GetMetadata();
var reader1 = md1.Reader;

var x = Visualize(generation0.OriginalMetadata, diff1.GetMetadata());
diff1.VerifyUpdatedTypes("0x02000002");

CheckEncLog(reader1,
Row(2, TableIndex.AssemblyRef, EditAndContinueOperation.Default),
Row(17, TableIndex.MemberRef, EditAndContinueOperation.Default),
Expand Down Expand Up @@ -860,6 +863,8 @@ static async Task<int> F()
// only methods with sequence points should be listed in UpdatedMethods:
diff1.VerifyUpdatedMethods("0x06000004");

diff1.VerifyUpdatedTypes("0x02000002", "0x02000003");

using (var md1 = diff1.GetMetadata())
{
// Verify that no new TypeDefs, FieldDefs or MethodDefs were added,
Expand Down Expand Up @@ -3321,6 +3326,8 @@ .locals init (int V_0)
ImmutableArray.Create(
SemanticEdit.Create(SemanticEditKind.Update, f0, f1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));

diff1.VerifyUpdatedTypes("0x02000003", "0x02000004");

diff1.VerifySynthesizedMembers(
"C: {<F>d__0}",
"C.<F>d__0: {<>1__state, <>2__current, <>l__initialThreadId, <>4__this, <x>5__1, System.IDisposable.Dispose, MoveNext, System.Collections.Generic.IEnumerator<System.Int32>.get_Current, System.Collections.IEnumerator.Reset, System.Collections.IEnumerator.get_Current, System.Collections.Generic.IEnumerable<System.Int32>.GetEnumerator, System.Collections.IEnumerable.GetEnumerator, System.Collections.Generic.IEnumerator<System.Int32>.Current, System.Collections.IEnumerator.Current}",
Expand All @@ -3333,6 +3340,8 @@ .locals init (int V_0)
ImmutableArray.Create(
SemanticEdit.Create(SemanticEditKind.Update, f1, f2, GetSyntaxMapFromMarkers(source1, source2), preserveLocalVariables: true)));

diff2.VerifyUpdatedTypes("0x02000003", "0x02000004");

diff2.VerifySynthesizedMembers(
"C: {<F>d__0}",
"C.<F>d__0: {<>1__state, <>2__current, <>l__initialThreadId, <>4__this, <x>5__1, System.IDisposable.Dispose, MoveNext, System.Collections.Generic.IEnumerator<System.Int32>.get_Current, System.Collections.IEnumerator.Reset, System.Collections.IEnumerator.get_Current, System.Collections.Generic.IEnumerable<System.Int32>.GetEnumerator, System.Collections.IEnumerable.GetEnumerator, System.Collections.Generic.IEnumerator<System.Int32>.Current, System.Collections.IEnumerator.Current}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,8 @@ static object F()
var reader1 = md1.Reader;
var readers = new[] { reader0, reader1 };

diff1.VerifyUpdatedTypes("0x02000002", "0x02000003");

CheckNames(readers, reader1.GetTypeDefNames(), "C`1");
Assert.Equal(1, reader1.GetTableRowCount(TableIndex.NestedClass));

Expand Down Expand Up @@ -6196,7 +6198,7 @@ .locals init ([unchanged] V_0,
IL_0021: br.s IL_0023
-IL_0023: ldloc.s V_6
IL_0025: ret
}", methodToken: diff1.UpdatedMethods.Single());
}", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

/// <summary>
Expand Down Expand Up @@ -7399,8 +7401,6 @@ static string F()
var method1F = compilation1.GetMember<MethodSymbol>("C.F");

using MemoryStream mdStream = new MemoryStream(), ilStream = new MemoryStream(), pdbStream = new MemoryStream();
var updatedMethods = new List<MethodDefinitionHandle>();
var updatedTypes = new List<TypeDefinitionHandle>();
var isAddedSymbol = new Func<ISymbol, bool>(s => false);

var badStream = new BrokenStream();
Expand All @@ -7413,8 +7413,6 @@ static string F()
badStream,
ilStream,
pdbStream,
updatedMethods,
updatedTypes,
new CompilationTestData(),
default);
Assert.False(result.Success);
Expand All @@ -7430,8 +7428,6 @@ static string F()
mdStream,
badStream,
pdbStream,
updatedMethods,
updatedTypes,
new CompilationTestData(),
default);
Assert.False(result.Success);
Expand All @@ -7447,8 +7443,6 @@ static string F()
mdStream,
ilStream,
badStream,
updatedMethods,
updatedTypes,
new CompilationTestData(),
default);
Assert.False(result.Success);
Expand Down Expand Up @@ -7492,8 +7486,6 @@ static string F()
var method1F = compilation1.GetMember<MethodSymbol>("C.F");

using MemoryStream mdStream = new MemoryStream(), ilStream = new MemoryStream(), pdbStream = new MemoryStream();
var updatedMethods = new List<MethodDefinitionHandle>();
var updatedTypes = new List<TypeDefinitionHandle>();
var isAddedSymbol = new Func<ISymbol, bool>(s => false);

var badStream = new BrokenStream();
Expand All @@ -7506,8 +7498,6 @@ static string F()
mdStream,
ilStream,
badStream,
updatedMethods,
updatedTypes,
new CompilationTestData(),
default);
Assert.False(result.Success);
Expand Down Expand Up @@ -9404,6 +9394,8 @@ .maxstack 2
ImmutableArray.Create(
SemanticEdit.Create(SemanticEditKind.Update, ctor0, ctor1, GetSyntaxMapFromMarkers(source0, source1), preserveLocalVariables: true)));

diff1.VerifyUpdatedTypes("0x02000002", "0x02000004");

diff1.VerifySynthesizedMembers(
"C: {<>c__DisplayClass0_0}",
"C.<>c__DisplayClass0_0: {x, <.ctor>b__0}");
Expand Down Expand Up @@ -9447,6 +9439,8 @@ .maxstack 2
ImmutableArray.Create(
SemanticEdit.Create(SemanticEditKind.Update, ctor1, ctor2, GetSyntaxMapFromMarkers(source1, source0), preserveLocalVariables: true)));

diff1.VerifyUpdatedTypes("0x02000002", "0x02000004");

diff2.VerifySynthesizedMembers(
"C: {<>c__DisplayClass0_0}",
"C.<>c__DisplayClass0_0: {x, <.ctor>b__0}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ .locals init (object V_0,
}
-IL_0041: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

/// <summary>
Expand Down Expand Up @@ -1296,7 +1296,7 @@ .locals init (double[,,] V_0,
IL_006c: ble.s IL_0027
-IL_006e: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -1765,7 +1765,7 @@ .locals init (string[] V_0, //arr
IL_002b: conv.i4
IL_002c: blt.s IL_0017
-IL_002e: ret
}", methodToken: diff1.UpdatedMethods.Single());
}", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -2035,7 +2035,7 @@ .locals init (object V_0,
IL_0055: callvirt ""int string.Length.get""
IL_005a: blt.s IL_0044
-IL_005c: ret
}", methodToken: diff2.UpdatedMethods.Single());
}", methodToken: diff2.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -2426,7 +2426,7 @@ .locals init (string V_0,
IL_0036: nop
-IL_0037: br.s IL_0039
-IL_0039: ret
}", methodToken: diff1.UpdatedMethods.Single());
}", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -3270,7 +3270,7 @@ .locals init (object V_0,
ImmutableArray.Create(SemanticEdit.Create(SemanticEditKind.Update, method0, method1, GetEquivalentNodesMap(method1, method0), preserveLocalVariables: true)));

diff1.VerifyIL("C.<M>b__0", @"
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
#endif
}

Expand Down Expand Up @@ -3529,7 +3529,7 @@ .locals init (int V_0)
ImmutableArray.Create(SemanticEdit.Create(SemanticEditKind.Update, method0, method1, GetEquivalentNodesMap(method1, method0), preserveLocalVariables: true)));

diff1.VerifyIL("?", @"
{", methodToken: diff1.UpdatedMethods.Single());
{", methodToken: diff1.EmitResult.UpdatedMethods.Single());
#endif
}

Expand Down Expand Up @@ -3689,7 +3689,7 @@ .locals init (int V_0,
ImmutableArray.Create(SemanticEdit.Create(SemanticEditKind.Update, method0, method1, GetEquivalentNodesMap(method1, method0), preserveLocalVariables: true)));

diff1.VerifyIL("?", @"
{", methodToken: diff1.UpdatedMethods.Single());
{", methodToken: diff1.EmitResult.UpdatedMethods.Single());
#endif
}

Expand Down Expand Up @@ -3738,7 +3738,7 @@ .locals init (int V_0, //x
-IL_0011: ldloc.3
IL_0012: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -3794,7 +3794,7 @@ .locals init (int V_0, //i
IL_001f: br.s IL_0021
-IL_0021: ldloc.3
IL_0022: ret
}", methodToken: diff1.UpdatedMethods.Single());
}", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -3849,7 +3849,7 @@ .locals init (System.ValueTuple<int, System.ValueTuple<int, int>> V_0, //x
-IL_0031: ldloc.2
IL_0032: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -3901,7 +3901,7 @@ .locals init (int V_0, //x
-IL_0010: ldloc.s V_4
IL_0012: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -3957,7 +3957,7 @@ .locals init (int V_0, //i
IL_001f: br.s IL_0021
-IL_0021: ldloc.3
IL_0022: ret
}", methodToken: diff1.UpdatedMethods.Single());
}", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -4017,7 +4017,7 @@ .locals init (bool V_0,
IL_002b: br.s IL_002d
-IL_002d: ldloc.2
IL_002e: ret
}", methodToken: diff1.UpdatedMethods.Single());
}", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -4095,7 +4095,7 @@ .locals init (int V_0, //a
-IL_003b: ldloc.s V_5
IL_003d: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -4186,7 +4186,7 @@ .locals init (int V_0, //i
-IL_0049: ldloc.s V_6
IL_004b: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -4251,7 +4251,7 @@ .locals init (C.<G>d__0 V_0)
IL_0032: call ""System.Threading.Tasks.Task<object> System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.Task.get""
IL_0037: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -4311,7 +4311,7 @@ .locals init (C.<G>d__0 V_0)
IL_0032: call ""System.Threading.Tasks.Task<object> System.Runtime.CompilerServices.AsyncTaskMethodBuilder<object>.Task.get""
IL_0037: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -4401,7 +4401,7 @@ .locals init (int V_0, //x
-IL_0046: ldloc.s V_8
IL_0048: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down Expand Up @@ -4485,7 +4485,7 @@ .locals init ([unchanged] V_0,
IL_004b: blt.s IL_000e
-IL_004d: ret
}
", methodToken: diff1.UpdatedMethods.Single());
", methodToken: diff1.EmitResult.UpdatedMethods.Single());
}

[Fact]
Expand Down

0 comments on commit 333cdbe

Please sign in to comment.