From 2347c5a6291c827d1b8be12c4ce9d88f33ee6e87 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 14:39:11 +0100 Subject: [PATCH 01/14] new async prolog alg, reorganize tests. --- Directory.Build.targets | 2 +- .../Symbols/CecilSymbolHelper.cs | 27 +- .../Coverage/CoverageTests.AsyncAwait.cs | 103 ++++ ...erageTests.ExcludeFromCoverageAttribute.cs | 165 +++++++ .../Coverage/CoverageTests.Filters.cs | 131 +++++ .../Coverage/CoverageTests.Lambda.cs | 56 +++ .../CoverageTests.SelectionStatements.cs | 88 ++++ .../Coverage/CoverageTests.cs | 453 +----------------- .../Coverage/InstrumenterHelper.cs | 8 +- .../Samples/Instrumentation.AsyncAwait.cs | 35 ++ 10 files changed, 612 insertions(+), 456 deletions(-) create mode 100644 test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs create mode 100644 test/coverlet.core.tests/Coverage/CoverageTests.ExcludeFromCoverageAttribute.cs create mode 100644 test/coverlet.core.tests/Coverage/CoverageTests.Filters.cs create mode 100644 test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs create mode 100644 test/coverlet.core.tests/Coverage/CoverageTests.SelectionStatements.cs diff --git a/Directory.Build.targets b/Directory.Build.targets index 475ad7649..e3d7b9076 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -14,7 +14,7 @@ - + From bd5923ac5b8a9bf2458c198c210cfbb8b0dfcfa3 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 17:02:22 +0100 Subject: [PATCH 03/14] fix netstandard async/await issue, add async/await prolog recognition --- .../Symbols/CecilSymbolHelper.cs | 30 +++++++++++++++---- ...Await.cs => Instrumentation.AsyncAwait.cs} | 6 ++-- ...rlet.core.tests.samples.netstandard.csproj | 8 ++++- .../Coverage/CoverageTests.AsyncAwait.cs | 11 ++----- 4 files changed, 37 insertions(+), 18 deletions(-) rename test/coverlet.core.tests.samples.netstandard/{CoverageTests.AsyncAwait.cs => Instrumentation.AsyncAwait.cs} (71%) diff --git a/src/coverlet.core/Symbols/CecilSymbolHelper.cs b/src/coverlet.core/Symbols/CecilSymbolHelper.cs index 5a691f4c7..fb2930be3 100644 --- a/src/coverlet.core/Symbols/CecilSymbolHelper.cs +++ b/src/coverlet.core/Symbols/CecilSymbolHelper.cs @@ -60,6 +60,25 @@ private static bool IsMoveNextInsideEnumerator(MethodDefinition methodDefinition return false; } + private static bool IsRecognizedMoveNextInsideAsyncStateMachineProlog(MethodDefinition methodDefinition) + { + /* + // int num = <>1__state; + IL_0000: ldarg.0 + IL_0001: ldfld ...::'<>1__state' + IL_0006: stloc.0 + */ + return (methodDefinition.Body.Instructions[0].OpCode == OpCodes.Ldarg_0 || + methodDefinition.Body.Instructions[0].OpCode == OpCodes.Ldarg) && + + methodDefinition.Body.Instructions[1].OpCode == OpCodes.Ldfld && + methodDefinition.Body.Instructions[1].Operand is FieldDefinition fd && fd.Name == "<>1__state" && + + (methodDefinition.Body.Instructions[2].OpCode == OpCodes.Stloc && + methodDefinition.Body.Instructions[2].Operand is VariableDefinition vd && vd.Index == 0) || + methodDefinition.Body.Instructions[2].OpCode == OpCodes.Stloc_0; + } + public static List GetBranchPoints(MethodDefinition methodDefinition) { var list = new List(); @@ -70,6 +89,7 @@ public static List GetBranchPoints(MethodDefinition methodDefinitio var instructions = methodDefinition.Body.Instructions; bool isAsyncStateMachineMoveNext = IsMoveNextInsideAsyncStateMachine(methodDefinition); + bool isRecognizedMoveNextInsideAsyncStateMachineProlog = isAsyncStateMachineMoveNext && IsRecognizedMoveNextInsideAsyncStateMachineProlog(methodDefinition); bool skipFirstBranch = IsMoveNextInsideEnumerator(methodDefinition); foreach (Instruction instruction in instructions.Where(instruction => instruction.OpCode.FlowControl == FlowControl.Cond_Branch)) @@ -85,15 +105,15 @@ public static List GetBranchPoints(MethodDefinition methodDefinitio // If method is a generated MoveNext skip first branches (could be a switch or a series of branches) // that check state machine value to jump to correct state(for instance after a true async call) // Check if it's a Cond_Branch on state machine current value [int num = <>1__state;] - if (isAsyncStateMachineMoveNext) + if (isAsyncStateMachineMoveNext && isRecognizedMoveNextInsideAsyncStateMachineProlog) { bool skipInstruction = false; Instruction current = instruction.Previous; for (int instructionBefore = 2; instructionBefore > 0 && current.Previous != null; current = current.Previous, instructionBefore--) { if ( - (current.OpCode == OpCodes.Ldloc && current.Operand is VariableDefinition vo && vo.Index == 0) || - current.OpCode == OpCodes.Ldloc_0 + (current.OpCode == OpCodes.Ldloc && current.Operand is VariableDefinition vo && vo.Index == 0) || + current.OpCode == OpCodes.Ldloc_0 ) { skipInstruction = true; @@ -115,8 +135,8 @@ public static List GetBranchPoints(MethodDefinition methodDefinitio ) && ( - operand.DeclaringType.Scope.Name == "System.Runtime" || - operand.DeclaringType.Scope.Name == "netstandard" + operand.DeclaringType.Scope.Name == "System.Runtime" || + operand.DeclaringType.Scope.Name == "netstandard" ) ) { diff --git a/test/coverlet.core.tests.samples.netstandard/CoverageTests.AsyncAwait.cs b/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs similarity index 71% rename from test/coverlet.core.tests.samples.netstandard/CoverageTests.AsyncAwait.cs rename to test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs index b981e2c1c..c183d1448 100644 --- a/test/coverlet.core.tests.samples.netstandard/CoverageTests.AsyncAwait.cs +++ b/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs @@ -1,16 +1,14 @@ // Remember to use full name because adding new using directives change line numbers -using System.Threading.Tasks; - namespace Coverlet.Core.Tests { public class Issue_669_2 { private readonly System.Net.Http.HttpClient _httpClient = new System.Net.Http.HttpClient(); - async public ValueTask SendRequest() + async public System.Threading.Tasks.ValueTask SendRequest() { - using (var requestMessage = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, "http://www.google.com")) + using (var requestMessage = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, "https://www.google.it")) { return await _httpClient.SendAsync(requestMessage).ConfigureAwait(false); } diff --git a/test/coverlet.core.tests.samples.netstandard/coverlet.core.tests.samples.netstandard.csproj b/test/coverlet.core.tests.samples.netstandard/coverlet.core.tests.samples.netstandard.csproj index 4641dbd64..a409df66a 100644 --- a/test/coverlet.core.tests.samples.netstandard/coverlet.core.tests.samples.netstandard.csproj +++ b/test/coverlet.core.tests.samples.netstandard/coverlet.core.tests.samples.netstandard.csproj @@ -1,5 +1,11 @@ - + netstandard2.0 + false + false + + + + diff --git a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs index 7894a07d6..0fb5f50de 100644 --- a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs +++ b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs @@ -118,14 +118,9 @@ public void AsyncAwait_Issue_669_2() }, path, invokeInProcess: true).Dispose(); TestInstrumentationHelper.GetCoverageResult(path) - .GenerateReport(show: true) - //.Document("Instrumentation.AsyncAwait.cs") - //.AssertLinesCovered(BuildConfiguration.Debug, - // (97, 1), (98, 1), (99, 1), (101, 1), (102, 1), (103, 1), - // (110, 1), (111, 1), (112, 1), (113, 1), - // (116, 1), (117, 1), (118, 1), (119, 1) - //) - ; + .Document("Instrumentation.AsyncAwait.cs") + .AssertLinesCovered(BuildConfiguration.Debug, (7, 1), (10, 1), (11, 1), (12, 1), (13, 1), (15, 1)) + .ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0); } finally { From f0f0ce07e9a5e994e151c90e5b72b5885afcf243 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 17:24:53 +0100 Subject: [PATCH 04/14] improve comment on async/await alg --- .../Symbols/CecilSymbolHelper.cs | 58 ++++++++++++++++--- ...rlet.core.tests.samples.netstandard.csproj | 1 + 2 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/coverlet.core/Symbols/CecilSymbolHelper.cs b/src/coverlet.core/Symbols/CecilSymbolHelper.cs index fb2930be3..876a3586c 100644 --- a/src/coverlet.core/Symbols/CecilSymbolHelper.cs +++ b/src/coverlet.core/Symbols/CecilSymbolHelper.cs @@ -63,10 +63,10 @@ private static bool IsMoveNextInsideEnumerator(MethodDefinition methodDefinition private static bool IsRecognizedMoveNextInsideAsyncStateMachineProlog(MethodDefinition methodDefinition) { /* - // int num = <>1__state; - IL_0000: ldarg.0 + int num = <>1__state; + IL_0000: ldarg.0 IL_0001: ldfld ...::'<>1__state' - IL_0006: stloc.0 + IL_0006: stloc.0 */ return (methodDefinition.Body.Instructions[0].OpCode == OpCodes.Ldarg_0 || methodDefinition.Body.Instructions[0].OpCode == OpCodes.Ldarg) && @@ -102,9 +102,52 @@ public static List GetBranchPoints(MethodDefinition methodDefinitio continue; } - // If method is a generated MoveNext skip first branches (could be a switch or a series of branches) - // that check state machine value to jump to correct state(for instance after a true async call) - // Check if it's a Cond_Branch on state machine current value [int num = <>1__state;] + /* + If method is a generated MoveNext we'll skip first branches (could be a switch or a series of branches) + that check state machine value to jump to correct state(for instance after a true async call) + Check if it's a Cond_Branch on state machine current value int num = <>1__state; + We are on branch OpCode so we need to go back by max 2 operation to reach ldloc.0 the load of "num" + Max 2 because we handle following patterns + + Swich + + // switch (num) + IL_0007: ldloc.0 2 + // (no C# code) + IL_0008: switch (IL_0037, IL_003c, ... 1 + ... + + Single branch + + // if (num != 0) + IL_0007: ldloc.0 2 + // (no C# code) + IL_0008: brfalse.s IL_000c 1 + IL_000a: br.s IL_000e + IL_000c: br.s IL_0049 + IL_000e: nop + ... + + More tha one branch + + // if (num != 0) + IL_0007: ldloc.0 + // (no C# code) + IL_0008: brfalse.s IL_0012 + IL_000a: br.s IL_000c + // if (num == 1) + IL_000c: ldloc.0 3 + IL_000d: ldc.i4.1 2 + IL_000e: beq.s IL_0014 1 + // (no C# code) + IL_0010: br.s IL_0019 + IL_0012: br.s IL_0060 + IL_0014: br IL_00e5 + IL_0019: nop + ... + + so we know that current branch are checking that field and we're not interested in. + */ if (isAsyncStateMachineMoveNext && isRecognizedMoveNextInsideAsyncStateMachineProlog) { bool skipInstruction = false; @@ -127,7 +170,8 @@ public static List GetBranchPoints(MethodDefinition methodDefinitio } // Skip get_IsCompleted to avoid unuseful branch due to async/await state machine - if (isAsyncStateMachineMoveNext && instruction.Previous.Operand is MethodReference operand && + if ( + isAsyncStateMachineMoveNext && instruction.Previous.Operand is MethodReference operand && operand.Name == "get_IsCompleted" && ( operand.DeclaringType.FullName.StartsWith("System.Runtime.CompilerServices.TaskAwaiter") || diff --git a/test/coverlet.core.tests.samples.netstandard/coverlet.core.tests.samples.netstandard.csproj b/test/coverlet.core.tests.samples.netstandard/coverlet.core.tests.samples.netstandard.csproj index a409df66a..783e0d0c3 100644 --- a/test/coverlet.core.tests.samples.netstandard/coverlet.core.tests.samples.netstandard.csproj +++ b/test/coverlet.core.tests.samples.netstandard/coverlet.core.tests.samples.netstandard.csproj @@ -8,4 +8,5 @@ + From b2986dbd46fd12887b0234edeb0cdad340ce2313 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 17:44:05 +0100 Subject: [PATCH 05/14] rename test name to avoid collision on test filtering --- .../Coverage/CoverageTests.AsyncAwait.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs index 0fb5f50de..b7dcbdacc 100644 --- a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs +++ b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs @@ -68,7 +68,7 @@ public void AsyncAwait() } [Fact] - public void AsyncAwait_Issue_669() + public void AsyncAwait_Issue_669_1() { string path = Path.GetTempFileName(); try @@ -88,10 +88,9 @@ public void AsyncAwait_Issue_669() TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.AsyncAwait.cs") .AssertLinesCovered(BuildConfiguration.Debug, - (97, 1), (98, 1), (99, 1), (101, 1), (102, 1), (103, 1), - (110, 1), (111, 1), (112, 1), (113, 1), - (116, 1), (117, 1), (118, 1), (119, 1) - ); + (97, 1), (98, 1), (99, 1), (101, 1), (102, 1), (103, 1), + (110, 1), (111, 1), (112, 1), (113, 1), + (116, 1), (117, 1), (118, 1), (119, 1)); } finally { From 89317a5c0f7d3a98644d604d8bc49a1435bd8c90 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 17:50:58 +0100 Subject: [PATCH 06/14] meh --- test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs | 2 +- test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs index b7dcbdacc..b61fad206 100644 --- a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs +++ b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs @@ -75,7 +75,7 @@ public void AsyncAwait_Issue_669_1() { RemoteExecutor.Invoke(async pathSerialize => { - CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => + CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => { ((Task)instance.Test()).ConfigureAwait(false).GetAwaiter().GetResult(); return Task.CompletedTask; diff --git a/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs b/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs index bc8e69c1b..3270a77b6 100644 --- a/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs +++ b/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs @@ -91,7 +91,7 @@ async public Task ConfigureAwait() } } - public class Issue_669 + public class Issue_669_1 { async public Task Test() { From c4ee8daba4b3c17bf99104a9f10a07a2bebc9495 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 18:08:27 +0100 Subject: [PATCH 07/14] try fix CI --- .../Instrumentation.AsyncAwait.cs | 2 +- test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs | 4 ++-- .../coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs b/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs index c183d1448..daf914b13 100644 --- a/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs +++ b/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs @@ -2,7 +2,7 @@ namespace Coverlet.Core.Tests { - public class Issue_669_2 + public class Issue_669_UC2 { private readonly System.Net.Http.HttpClient _httpClient = new System.Net.Http.HttpClient(); diff --git a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs index b61fad206..399072789 100644 --- a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs +++ b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs @@ -75,7 +75,7 @@ public void AsyncAwait_Issue_669_1() { RemoteExecutor.Invoke(async pathSerialize => { - CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => + CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => { ((Task)instance.Test()).ConfigureAwait(false).GetAwaiter().GetResult(); return Task.CompletedTask; @@ -106,7 +106,7 @@ public void AsyncAwait_Issue_669_2() { RemoteExecutor.Invoke(async pathSerialize => { - CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => + CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => { ((ValueTask)instance.SendRequest()).ConfigureAwait(false).GetAwaiter().GetResult(); return Task.CompletedTask; diff --git a/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs b/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs index 3270a77b6..47c32ba59 100644 --- a/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs +++ b/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs @@ -91,7 +91,7 @@ async public Task ConfigureAwait() } } - public class Issue_669_1 + public class Issue_669_UC1 { async public Task Test() { From 979d1d3c00468f68857d07a93ef7a5e912a0d29c Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 21:51:52 +0100 Subject: [PATCH 08/14] add some log --- .../Coverage/InstrumenterHelper.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs b/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs index 9d47a7aab..88b5f7677 100644 --- a/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs +++ b/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs @@ -395,7 +395,16 @@ async public static Task Run(Func callM }).ToArray(), Array.Empty(), Array.Empty(), true, false, "", false, new Logger(logFile), DependencyInjection.Current.GetService(), DependencyInjection.Current.GetService()); CoveragePrepareResult prepareResult = coverage.PrepareModules(); - Assert.Single(prepareResult.Results); + StringBuilder log = new StringBuilder(); + + log.AppendLine($"[{Path.GetFileNameWithoutExtension(fileName)}*]{typeof(T).FullName}*"); + + foreach (var item in prepareResult.Results) + { + log.AppendLine(item.Module); + } + + Assert.True(prepareResult.Results.Length == 1, log.ToString()); // Load new assembly Assembly asm = Assembly.LoadFile(newPath); From 6bdc49d207812a1b7ecb30ba6c46664c3c4d6e1f Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 21:59:53 +0100 Subject: [PATCH 09/14] add more log --- test/coverlet.core.tests/Coverage/InstrumenterHelper.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs b/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs index 88b5f7677..049fa1de1 100644 --- a/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs +++ b/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs @@ -412,6 +412,15 @@ async public static Task Run(Func callM // Instance type and call method await callMethod(Activator.CreateInstance(asm.GetType(typeof(T).FullName))); + List trackers = new List(); + foreach (var item in asm.GetTypes().Where(n => n.FullName.Contains("Coverlet.Core.Instrumentation.Tracker"))) + { + trackers.Add(item.FullName); + log.AppendLine(item.FullName); + } + + Assert.True(trackers.Count == 1, log.ToString()); + // Flush tracker Type tracker = asm.GetTypes().Single(n => n.FullName.Contains("Coverlet.Core.Instrumentation.Tracker")); From cd7c9027cd8d60ad611c2fc98eafde2b6ba77da9 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 22:21:40 +0100 Subject: [PATCH 10/14] update CI --- eng/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/build.yml b/eng/build.yml index e12b5069a..b79acc30d 100644 --- a/eng/build.yml +++ b/eng/build.yml @@ -22,5 +22,5 @@ steps: displayName: Test inputs: command: test - arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include=[coverlet.*]* /p:Exclude=[coverlet.tests.remoteexecutor]* + arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include=\"[coverlet.collector]*,[coverlet.core]*,[coverlet.msbuild.tasks]*\" /p:Exclude=\"[coverlet.core.tests.samples.netstandard]*,[coverlet.tests.remoteexecutor]*\" testRunTitle: $(Agent.JobName) \ No newline at end of file From a05c79cba50ce75d4d815ceac8583bf436e1bc0f Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 22:24:39 +0100 Subject: [PATCH 11/14] Update CI --- eng/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/build.yml b/eng/build.yml index b79acc30d..1fcb0b08c 100644 --- a/eng/build.yml +++ b/eng/build.yml @@ -22,5 +22,5 @@ steps: displayName: Test inputs: command: test - arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include=\"[coverlet.collector]*,[coverlet.core]*,[coverlet.msbuild.tasks]*\" /p:Exclude=\"[coverlet.core.tests.samples.netstandard]*,[coverlet.tests.remoteexecutor]*\" + arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[coverlet.collector]*2%c[coverlet.core]*2%c[coverlet.msbuild.tasks]*" /p:Exclude="[coverlet.core.tests.samples.netstandard]*2%c[coverlet.tests.remoteexecutor]*" testRunTitle: $(Agent.JobName) \ No newline at end of file From 10270a9d5d06baf63d926420424c61e67bd5acea Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 22:29:26 +0100 Subject: [PATCH 12/14] fix CI --- eng/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/eng/build.yml b/eng/build.yml index 1fcb0b08c..996e9476f 100644 --- a/eng/build.yml +++ b/eng/build.yml @@ -22,5 +22,5 @@ steps: displayName: Test inputs: command: test - arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[coverlet.collector]*2%c[coverlet.core]*2%c[coverlet.msbuild.tasks]*" /p:Exclude="[coverlet.core.tests.samples.netstandard]*2%c[coverlet.tests.remoteexecutor]*" + arguments: -c $(BuildConfiguration) --no-build /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:Include="[coverlet.collector]*%2c[coverlet.core]*%2c[coverlet.msbuild.tasks]*" /p:Exclude="[coverlet.core.tests.samples.netstandard]*%2c[coverlet.tests.remoteexecutor]*" testRunTitle: $(Agent.JobName) \ No newline at end of file From 8fa1db3cabe6da5047d53c0703a3095ff31de91b Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 22:35:00 +0100 Subject: [PATCH 13/14] revert changes, fix tests --- .../Instrumentation.AsyncAwait.cs | 2 +- .../Coverage/CoverageTests.AsyncAwait.cs | 4 ++-- .../Coverage/InstrumenterHelper.cs | 20 +------------------ .../Samples/Instrumentation.AsyncAwait.cs | 2 +- 4 files changed, 5 insertions(+), 23 deletions(-) diff --git a/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs b/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs index daf914b13..c183d1448 100644 --- a/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs +++ b/test/coverlet.core.tests.samples.netstandard/Instrumentation.AsyncAwait.cs @@ -2,7 +2,7 @@ namespace Coverlet.Core.Tests { - public class Issue_669_UC2 + public class Issue_669_2 { private readonly System.Net.Http.HttpClient _httpClient = new System.Net.Http.HttpClient(); diff --git a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs index 399072789..b61fad206 100644 --- a/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs +++ b/test/coverlet.core.tests/Coverage/CoverageTests.AsyncAwait.cs @@ -75,7 +75,7 @@ public void AsyncAwait_Issue_669_1() { RemoteExecutor.Invoke(async pathSerialize => { - CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => + CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => { ((Task)instance.Test()).ConfigureAwait(false).GetAwaiter().GetResult(); return Task.CompletedTask; @@ -106,7 +106,7 @@ public void AsyncAwait_Issue_669_2() { RemoteExecutor.Invoke(async pathSerialize => { - CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => + CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run(instance => { ((ValueTask)instance.SendRequest()).ConfigureAwait(false).GetAwaiter().GetResult(); return Task.CompletedTask; diff --git a/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs b/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs index 049fa1de1..9d47a7aab 100644 --- a/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs +++ b/test/coverlet.core.tests/Coverage/InstrumenterHelper.cs @@ -395,16 +395,7 @@ async public static Task Run(Func callM }).ToArray(), Array.Empty(), Array.Empty(), true, false, "", false, new Logger(logFile), DependencyInjection.Current.GetService(), DependencyInjection.Current.GetService()); CoveragePrepareResult prepareResult = coverage.PrepareModules(); - StringBuilder log = new StringBuilder(); - - log.AppendLine($"[{Path.GetFileNameWithoutExtension(fileName)}*]{typeof(T).FullName}*"); - - foreach (var item in prepareResult.Results) - { - log.AppendLine(item.Module); - } - - Assert.True(prepareResult.Results.Length == 1, log.ToString()); + Assert.Single(prepareResult.Results); // Load new assembly Assembly asm = Assembly.LoadFile(newPath); @@ -412,15 +403,6 @@ async public static Task Run(Func callM // Instance type and call method await callMethod(Activator.CreateInstance(asm.GetType(typeof(T).FullName))); - List trackers = new List(); - foreach (var item in asm.GetTypes().Where(n => n.FullName.Contains("Coverlet.Core.Instrumentation.Tracker"))) - { - trackers.Add(item.FullName); - log.AppendLine(item.FullName); - } - - Assert.True(trackers.Count == 1, log.ToString()); - // Flush tracker Type tracker = asm.GetTypes().Single(n => n.FullName.Contains("Coverlet.Core.Instrumentation.Tracker")); diff --git a/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs b/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs index 47c32ba59..3270a77b6 100644 --- a/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs +++ b/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs @@ -91,7 +91,7 @@ async public Task ConfigureAwait() } } - public class Issue_669_UC1 + public class Issue_669_1 { async public Task Test() { From 99a3177c2db2ad78c230c053bc0a928e17b8a9f7 Mon Sep 17 00:00:00 2001 From: Marco Rossignoli Date: Tue, 21 Jan 2020 22:41:01 +0100 Subject: [PATCH 14/14] remove report generation during test --- test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs b/test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs index a7557b7f1..28f4d71a8 100644 --- a/test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs +++ b/test/coverlet.core.tests/Coverage/CoverageTests.Lambda.cs @@ -28,7 +28,7 @@ public void Lambda_Issue343() CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); - result.GenerateReport(show: true).Document("Instrumentation.Lambda.cs") + result.Document("Instrumentation.Lambda.cs") .AssertLinesCoveredAllBut(BuildConfiguration.Debug, 23, 51) .AssertBranchesCovered(BuildConfiguration.Debug, // Expected branches