public void AsyncAwait_Issue_1233() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue_1233>(instance => { ((Task)instance.Test()).ConfigureAwait(false).GetAwaiter().GetResult(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); var document = TestInstrumentationHelper.GetCoverageResult(path).Document("Instrumentation.AsyncAwait.cs"); document.AssertLinesCovered(BuildConfiguration.Debug, (150, 1)); Assert.DoesNotContain(document.Branches, x => x.Key.Line == 150); } finally { File.Delete(path); } }
public void Switch_DoesNotReturnAttribute_InstrumentsCorrect() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <DoesNotReturn>(instance => { try { instance.Switch(); } catch (Exception) { } return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.DoesNotReturn.cs") .AssertInstrumentLines(BuildConfiguration.Debug, 7, 8, 33, 34, 36, 39, 40, 44, 45, 49, 50, 52, 53, 55, 56, 58, 59, 61, 62, 64, 65, 68, 69) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 41, 42); } finally { File.Delete(path); } }
public void ExcludeFromCodeCoverageCompilerGeneratedMethodsAndTypes_Issue670() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <MethodsWithExcludeFromCodeCoverageAttr_Issue670>(instance => { instance.Test("test"); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.ExcludeFromCoverage.Issue670.cs") .AssertLinesCovered(BuildConfiguration.Debug, (8, 1), (9, 1), (10, 1), (11, 1)) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 15, 53); } finally { File.Delete(path); } }
public void Subtle_DoesNotReturnAttribute_InstrumentsCorrect() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <DoesNotReturn>(instance => { try { instance.Subtle(); } catch (Exception) { } return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.DoesNotReturn.cs") .AssertInstrumentLines(BuildConfiguration.Debug, 7, 8, 72, 73, 75, 78, 82, 83, 86, 87, 91, 92, 95, 101, 102, 103) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 79, 80, 88, 96, 98, 99); } finally { File.Delete(path); } }
public void FiltersAndFinallies_DoesNotReturnAttribute_InstrumentsCorrect() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <DoesNotReturn>(instance => { try { instance.FiltersAndFinallies(); } catch (Exception) { } return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.DoesNotReturn.cs") .AssertInstrumentLines(BuildConfiguration.Debug, 7, 8, 171, 173, 174, 175, 179, 180, 181, 182, 185, 186, 187, 188, 192, 193, 194) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 176, 177, 183, 184, 189, 190, 195, 196, 197); } finally { File.Delete(path); } }
public override bool Execute() { try { var includeFilters = _include?.Split(','); var includeDirectories = _includeDirectory?.Split(','); var excludeFilters = _exclude?.Split(','); var excludedSourceFiles = _excludeByFile?.Split(','); var excludeAttributes = _excludeByAttribute?.Split(','); Coverage coverage = new Coverage(_path, includeFilters, includeDirectories, excludeFilters, excludedSourceFiles, excludeAttributes, _includeTestAssembly, _singleHit, _mergeWith, _useSourceLink, _logger, (IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper))); CoveragePrepareResult prepareResult = coverage.PrepareModules(); InstrumenterState = new TaskItem(System.IO.Path.GetTempFileName()); using (var instrumentedStateFile = new FileStream(InstrumenterState.ItemSpec, FileMode.Open, FileAccess.Write)) { using (Stream serializedState = CoveragePrepareResult.Serialize(prepareResult)) { serializedState.CopyTo(instrumentedStateFile); } } } catch (Exception ex) { _logger.LogError(ex); return(false); } return(true); }
public void AsyncAwait_Issue_669_2() { string path = Path.GetTempFileName(); try { RemoteExecutor.Invoke(async pathSerialize => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue_669_2>(instance => { ((ValueTask <System.Net.Http.HttpResponseMessage>)instance.SendRequest()).ConfigureAwait(false).GetAwaiter().GetResult(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize, disableRestoreModules: true); return(0); }, path, invokeInProcess: true).Dispose(); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.AsyncAwait.cs") .AssertLinesCovered(BuildConfiguration.Debug, (7, 1), (10, 1), (11, 1), (12, 1), (13, 1), (15, 1)) .ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0); } finally { File.Delete(path); } }
public void Lambda_Issue760() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue_760>(instance => { ((Task)instance.If()).ConfigureAwait(false).GetAwaiter().GetResult(); ((Task)instance.Foreach()).ConfigureAwait(false).GetAwaiter().GetResult(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.Lambda.cs") .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 83, 92) .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 95, 104); } finally { File.Delete(path); } }
public void Yield_Enumerable() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Yield>(instance => { foreach (dynamic _ in instance.Enumerable(new[] { "one", "two", "three", "four" })) { ; } return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.Yield.cs") .Method("System.Boolean Coverlet.Core.Samples.Tests.Yield/<Enumerable>d__4::MoveNext()") .AssertLinesCovered(BuildConfiguration.Debug, (48, 1), (49, 1), (50, 4), (51, 5), (52, 1), (54, 4), (55, 4), (56, 4), (57, 1)) .ExpectedTotalNumberOfBranches(1); } finally { File.Delete(path); } }
public void Issue_1056() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue_1056>(instance => { instance.T1(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.Lambda.cs") .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 110, 119) .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 122, 124) .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 127, 129) .AssertLinesCoveredFromTo(BuildConfiguration.Debug, 131, 131) .AssertLinesCovered(BuildConfiguration.Debug, (110, 1), (111, 2), (112, 2), (113, 2), (114, 2), (115, 2), (116, 2), (117, 2), (118, 2), (119, 1), (122, 2), (123, 2), (124, 2), (127, 2), (128, 2), (129, 2), (131, 4)); } finally { File.Delete(path); } }
public void AsyncAwait_Issue_730() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue_730>(instance => { ((Task)instance.Invoke()).ConfigureAwait(false).GetAwaiter().GetResult(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.Lambda.cs") .AssertLinesCovered(BuildConfiguration.Debug, (73, 1), (74, 1), (75, 101), (76, 1), (77, 1)) .ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0); } finally { File.Delete(path); } }
public override bool Execute() { try { var includeFilters = _include?.Split(','); var includeDirectories = _includeDirectory?.Split(','); var excludeFilters = _exclude?.Split(','); var excludedSourceFiles = _excludeByFile?.Split(','); var excludeAttributes = _excludeByAttribute?.Split(','); // We add default exclusion filter if no specified if (excludeFilters is null || excludeFilters.Length == 0) { excludeFilters = new string[] { "[xunit*]*" }; } Coverage coverage = new Coverage(_path, includeFilters, includeDirectories, excludeFilters, excludedSourceFiles, excludeAttributes, _includeTestAssembly, _singleHit, _mergeWith, _useSourceLink, _logger); CoveragePrepareResult prepareResult = coverage.PrepareModules(); InstrumenterState = new TaskItem(System.IO.Path.GetTempFileName()); using (var instrumentedStateFile = new FileStream(InstrumenterState.ItemSpec, FileMode.Open, FileAccess.Write)) { using (Stream serializedState = CoveragePrepareResult.Serialize(prepareResult)) { serializedState.CopyTo(instrumentedStateFile); } } } catch (Exception ex) { _logger.LogError(ex); return(false); } return(true); }
public void SelectionStatements_Switch_CSharp8_OneBranch() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <SelectionStatements>(instance => { instance.SwitchCsharp8(int.MaxValue); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.SelectionStatements.cs") .AssertLinesCovered(BuildConfiguration.Debug, 33, 34, 35, 36, 40) .AssertLinesNotCovered(BuildConfiguration.Debug, 37, 38, 39) .AssertBranchesCovered(BuildConfiguration.Debug, (34, 0, 1), (34, 1, 0), (34, 2, 0), (34, 3, 0), (34, 4, 0), (34, 5, 0)) .ExpectedTotalNumberOfBranches(3); } finally { File.Delete(path); } }
public override bool Execute() { WaitForDebuggerIfEnabled(); IServiceCollection serviceCollection = new ServiceCollection(); serviceCollection.AddTransient <IProcessExitHandler, ProcessExitHandler>(); serviceCollection.AddTransient <IFileSystem, FileSystem>(); serviceCollection.AddTransient <IConsole, SystemConsole>(); serviceCollection.AddTransient <ILogger, MSBuildLogger>(_ => _logger); serviceCollection.AddTransient <IRetryHelper, RetryHelper>(); // We cache resolutions serviceCollection.AddSingleton <ISourceRootTranslator, SourceRootTranslator>(serviceProvider => new SourceRootTranslator(_path, serviceProvider.GetRequiredService <ILogger>(), serviceProvider.GetRequiredService <IFileSystem>())); // We need to keep singleton/static semantics serviceCollection.AddSingleton <IInstrumentationHelper, InstrumentationHelper>(); DependencyInjection.Set(serviceCollection.BuildServiceProvider()); try { var includeFilters = _include?.Split(','); var includeDirectories = _includeDirectory?.Split(','); var excludeFilters = _exclude?.Split(','); var excludedSourceFiles = _excludeByFile?.Split(','); var excludeAttributes = _excludeByAttribute?.Split(','); var fileSystem = DependencyInjection.Current.GetService <IFileSystem>(); Coverage coverage = new Coverage(_path, includeFilters, includeDirectories, excludeFilters, excludedSourceFiles, excludeAttributes, _includeTestAssembly, _singleHit, _mergeWith, _useSourceLink, _logger, DependencyInjection.Current.GetService <IInstrumentationHelper>(), fileSystem, DependencyInjection.Current.GetService <ISourceRootTranslator>()); CoveragePrepareResult prepareResult = coverage.PrepareModules(); InstrumenterState = new TaskItem(System.IO.Path.GetTempFileName()); using (var instrumentedStateFile = fileSystem.NewFileStream(InstrumenterState.ItemSpec, FileMode.Open, FileAccess.Write)) { using (Stream serializedState = CoveragePrepareResult.Serialize(prepareResult)) { serializedState.CopyTo(instrumentedStateFile); } } } catch (Exception ex) { _logger.LogError(ex); return(false); } return(true); }
public void ExcludeFilteredTypes() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <ExcludeFilterOuterTypes>(instance => { Assert.Equal(42, instance.Run()); return(Task.CompletedTask); }, excludeFilter: moduleFileName => new string[] { $"[{Path.GetFileNameWithoutExtension(moduleFileName)}*]*ExcludeFilterOuterTypes" }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.ExcludeFilter.cs") .AssertNonInstrumentedLines(BuildConfiguration.Debug, 1, 62) .AssertLinesCovered(BuildConfiguration.Debug, (66, 1), (68, 1)); } finally { File.Delete(path); } }
public void Yield_SingleWithSwitch() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Yield>(instance => { foreach (dynamic _ in instance.OneWithSwitch(2)) { ; } return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.Yield.cs") .Method("System.Boolean Coverlet.Core.Samples.Tests.Yield/<OneWithSwitch>d__2::MoveNext()") .AssertLinesCovered(BuildConfiguration.Debug, (21, 1), (30, 1), (31, 1), (37, 1)) .ExpectedTotalNumberOfBranches(1); } finally { File.Delete(path); } }
public void CallsGenericClassDoesNotReturn_DoesNotReturnAttribute_InstrumentsCorrect() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <DoesNotReturn>(instance => { try { instance.CallsGenericClassDoesNotReturn(); } catch (Exception) { } return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0], doesNotReturnAttributes: _ => new string[] { "DoesNotReturnAttribute" }); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.DoesNotReturn.cs") .AssertInstrumentLines(BuildConfiguration.Debug, 134, 135, 140, 141, 142) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 143, 144); } finally { File.Delete(path); } }
public void Lambda_Issue343() { string path = Path.GetTempFileName(); try { RemoteExecutor.Invoke(async pathSerialize => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Lambda_Issue343>(instance => { instance.InvokeAnonymous_Test(); ((Task <bool>)instance.InvokeAnonymousAsync_Test()).ConfigureAwait(false).GetAwaiter().GetResult(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize); return(0); }, path).Dispose(); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.Lambda.cs") .AssertLinesCoveredAllBut(BuildConfiguration.Debug, 23, 51) .AssertBranchesCovered(BuildConfiguration.Debug, // Expected branches (22, 0, 0), (22, 1, 1), (50, 0, 0), (50, 1, 1) ); } finally { File.Delete(path); } }
public void SelectionStatements_Switch() { string path = Path.GetTempFileName(); try { RemoteExecutor.Invoke(async pathSerialize => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <SelectionStatements>(instance => { instance.Switch(1); return(Task.CompletedTask); }, pathSerialize); return(0); }, path).Dispose(); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.SelectionStatements.cs") .AssertLinesCovered(BuildConfiguration.Release, (24, 1), (26, 0), (28, 0)) .AssertBranchesCovered(BuildConfiguration.Release, (24, 1, 1)) .AssertLinesCovered(BuildConfiguration.Debug, (20, 1), (21, 1), (24, 1), (30, 1)) .AssertBranchesCovered(BuildConfiguration.Debug, (21, 0, 0), (21, 1, 1), (21, 2, 0), (21, 3, 0)); } finally { File.Delete(path); } }
public void AsyncAwait_Issue_730() { string path = Path.GetTempFileName(); try { RemoteExecutor.Invoke(async pathSerialize => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue_730>(instance => { ((Task)instance.Invoke()).ConfigureAwait(false).GetAwaiter().GetResult(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize, disableRestoreModules: true); return(0); }, path, invokeInProcess: true).Dispose(); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.Lambda.cs") .AssertLinesCovered(BuildConfiguration.Debug, (72, 1), (73, 1), (74, 101), (75, 1), (76, 1)) .ExpectedTotalNumberOfBranches(BuildConfiguration.Debug, 0); } finally { File.Delete(path); } }
public void AsyncAwait_Issue_669_1() { string path = Path.GetTempFileName(); try { RemoteExecutor.Invoke(async pathSerialize => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue_669_1>(instance => { ((Task)instance.Test()).ConfigureAwait(false).GetAwaiter().GetResult(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize, disableRestoreModules: true); return(0); }, path, invokeInProcess: true).Dispose(); 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)); } finally { File.Delete(path); } }
public void ExcludeFromCodeCoverage_Issue809() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <TaskRepo_Issue809>(instance => { Assert.True(((Task <bool>)instance.EditTask(null, 10)).GetAwaiter().GetResult()); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.ExcludeFromCoverage.Issue809.cs") // public async Task<bool> EditTask(Tasks_Issue809 tasks, int val) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 153, 162) // .AssertNonInstrumentedLines(BuildConfiguration.Debug, 167, 170) -> Shoud be not covered, issue with lambda .AssertNonInstrumentedLines(BuildConfiguration.Debug, 167, 197) // public List<Tasks_Issue809> GetAllTasks() // .AssertNonInstrumentedLines(BuildConfiguration.Debug, 263, 266) -> Shoud be not covered, issue with lambda .AssertNonInstrumentedLines(BuildConfiguration.Debug, 263, 264); // .AssertNonInstrumentedLines(BuildConfiguration.Debug, 269, 275) -> Shoud be not covered, issue with lambda } finally { File.Delete(path); } }
public void WithLeave_DoesNotReturnAttribute_InstrumentsCorrect() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <DoesNotReturn>(instance => { try { instance.WithLeave(); } catch (Exception) { } return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.DoesNotReturn.cs") .AssertInstrumentLines(BuildConfiguration.Debug, 7, 8, 147, 149, 150, 151, 152, 153, 154, 155, 156, 159, 161, 166, 167, 168) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 163, 164); } finally { File.Delete(path); } }
public void ExcludeFromCodeCoverageAutoGeneratedGet() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <AutoGeneneratedGetOnly>(instance => { instance.SetId(10); Assert.Equal(10, instance.Id); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.ExcludeFromCoverage.cs") .AssertNonInstrumentedLines(BuildConfiguration.Debug, 177) .AssertLinesCovered(BuildConfiguration.Debug, 178, 181); } finally { File.Delete(path); } }
public void If_DoesNotReturnAttribute_InstrumentsCorrect() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <DoesNotReturn>(instance => { try { instance.If(); } catch (Exception) { } return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.DoesNotReturn.cs") .AssertInstrumentLines(BuildConfiguration.Debug, 7, 8, 19, 20, 22, 23, 24, 25, 29, 30) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 26, 27); } finally { File.Delete(path); } }
public void ExcludeFromCodeCoverage_Issue1302() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue1302>(instance => { instance.Run(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.ExcludeFromCoverage.Issue1302.cs") .AssertNonInstrumentedLines(BuildConfiguration.Debug, 10, 13); } finally { File.Delete(path); } }
public void TestCoverageSkipModule__AssemblyMarkedAsExcludeFromCodeCoverage() { Mock <FileSystem> partialMockFileSystem = new Mock <FileSystem>(); partialMockFileSystem.CallBase = true; partialMockFileSystem.Setup(fs => fs.NewFileStream(It.IsAny <string>(), It.IsAny <FileMode>(), It.IsAny <FileAccess>())).Returns((string path, FileMode mode, FileAccess access) => { return(new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read)); }); var loggerMock = new Mock <ILogger>(); string excludedbyattributeDll = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), "TestAssets"), "coverlet.tests.projectsample.excludedbyattribute.dll").First(); InstrumentationHelper instrumentationHelper = new InstrumentationHelper(new ProcessExitHandler(), new RetryHelper(), new FileSystem(), new Mock <ILogger>().Object, new SourceRootTranslator(excludedbyattributeDll, new Mock <ILogger>().Object, new FileSystem())); // test skip module include test assembly feature var coverage = new Coverage(excludedbyattributeDll, new string[] { "[coverlet.tests.projectsample.excludedbyattribute*]*" }, Array.Empty <string>(), Array.Empty <string>(), Array.Empty <string>(), Array.Empty <string>(), true, false, string.Empty, false, loggerMock.Object, instrumentationHelper, partialMockFileSystem.Object, new SourceRootTranslator(loggerMock.Object, new FileSystem())); CoveragePrepareResult result = coverage.PrepareModules(); Assert.Empty(result.Results); loggerMock.Verify(l => l.LogVerbose(It.IsAny <string>())); }
public void AsyncAwait_Issue_669_1() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <Issue_669_1>(instance => { ((Task)instance.Test()).ConfigureAwait(false).GetAwaiter().GetResult(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); 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)); } finally { File.Delete(path); } }
public void ExcludeFromCodeCoverageNextedTypes() { string path = Path.GetTempFileName(); try { FunctionExecutor.Run(async(string[] pathSerialize) => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <ExcludeFromCoverageAttrFilterClass1>(instance => { Assert.Equal(42, instance.Run()); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize[0]); return(0); }, new string[] { path }); TestInstrumentationHelper.GetCoverageResult(path) .Document("Instrumentation.ExcludeFromCoverage.cs") .AssertLinesCovered(BuildConfiguration.Debug, (143, 1)) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 146, 160); } finally { File.Delete(path); } }
public void ExcludeFromCodeCoverage_CompilerGeneratedMethodsAndTypes_NestedMembers() { string path = Path.GetTempFileName(); try { RemoteExecutor.Invoke(async pathSerialize => { CoveragePrepareResult coveragePrepareResult = await TestInstrumentationHelper.Run <MethodsWithExcludeFromCodeCoverageAttr_NestedStateMachines>(instance => { instance.Test(); return(Task.CompletedTask); }, persistPrepareResultToFile: pathSerialize); return(0); }, path).Dispose(); CoverageResult result = TestInstrumentationHelper.GetCoverageResult(path); result.Document("Instrumentation.ExcludeFromCoverage.NestedStateMachines.cs") .AssertLinesCovered(BuildConfiguration.Debug, (14, 1), (15, 1), (16, 1)) .AssertNonInstrumentedLines(BuildConfiguration.Debug, 9, 11); } finally { File.Delete(path); } }