-
Notifications
You must be signed in to change notification settings - Fork 392
SystemIOFile Adapter #550
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SystemIOFile Adapter #550
Changes from 20 commits
a6e0687
84c0aff
5b4e316
45075e1
23aeb1c
7ca75f2
71af4de
8ec57c1
8a4a1f8
3875965
c889d15
202f965
c58508b
5c11795
ef7d0b0
669f042
2af6fe2
b1bf6c9
00de202
4dca604
33c7e40
95ca53d
f8ec589
d87ea07
690d6dc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,27 @@ | ||
| namespace Coverlet.Core.Abstracts | ||
| using System.IO; | ||
|
|
||
| namespace Coverlet.Core.Abstracts | ||
| { | ||
| internal interface IFileSystem | ||
| public interface IFileSystem | ||
| { | ||
| bool Exists(string path); | ||
|
|
||
| void WriteAllText(string path, string contents); | ||
|
|
||
| string ReadAllText(string path); | ||
|
|
||
| Stream OpenRead(string path); | ||
|
|
||
| void Copy(string sourceFileName, string destFileName); | ||
|
||
|
|
||
| void Copy(string sourceFileName, string destFileName, bool overwrite); | ||
|
|
||
| void Delete(string path); | ||
|
|
||
| void AppendAllText(string path, string contents); | ||
MarcoRossignoli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Stream NewFileStream(string path, FileMode mode); | ||
|
|
||
| Stream NewFileStream(string path, FileMode mode, FileAccess access); | ||
MarcoRossignoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ | |
| using System.IO; | ||
| using System.Linq; | ||
| using Coverlet.Core.Abstracts; | ||
| using Coverlet.Core.Helpers; | ||
| using Coverlet.Core.Instrumentation; | ||
| using Coverlet.Core.Logging; | ||
|
|
||
|
|
@@ -27,6 +26,7 @@ public class Coverage | |
| private bool _useSourceLink; | ||
| private ILogger _logger; | ||
| private IInstrumentationHelper _instrumentationHelper; | ||
| private IFileSystem _fileSystem; | ||
| private List<InstrumenterResult> _results; | ||
|
|
||
| public string Identifier | ||
|
|
@@ -45,6 +45,7 @@ public Coverage(string module, | |
| string mergeWith, | ||
| bool useSourceLink, | ||
| ILogger logger, | ||
| IFileSystem fileSystem, | ||
| IInstrumentationHelper instrumentationHelper) | ||
| { | ||
| _module = module; | ||
|
|
@@ -58,20 +59,22 @@ public Coverage(string module, | |
| _mergeWith = mergeWith; | ||
| _useSourceLink = useSourceLink; | ||
| _logger = logger; | ||
| _fileSystem = fileSystem; | ||
| _instrumentationHelper = instrumentationHelper; | ||
|
|
||
| _identifier = Guid.NewGuid().ToString(); | ||
| _results = new List<InstrumenterResult>(); | ||
| } | ||
|
|
||
| public Coverage(CoveragePrepareResult prepareResult, ILogger logger, IInstrumentationHelper instrumentationHelper) | ||
| public Coverage(CoveragePrepareResult prepareResult, ILogger logger, IFileSystem fileSystem, IInstrumentationHelper instrumentationHelper) | ||
|
||
| { | ||
| _identifier = prepareResult.Identifier; | ||
| _module = prepareResult.Module; | ||
| _mergeWith = prepareResult.MergeWith; | ||
| _useSourceLink = prepareResult.UseSourceLink; | ||
| _results = new List<InstrumenterResult>(prepareResult.Results); | ||
| _logger = logger; | ||
| _fileSystem = fileSystem; | ||
| _instrumentationHelper = instrumentationHelper; | ||
| } | ||
|
|
||
|
|
@@ -215,9 +218,9 @@ public CoverageResult GetCoverageResult() | |
|
|
||
| var coverageResult = new CoverageResult { Identifier = _identifier, Modules = modules, InstrumentedResults = _results }; | ||
|
|
||
| if (!string.IsNullOrEmpty(_mergeWith) && !string.IsNullOrWhiteSpace(_mergeWith) && File.Exists(_mergeWith)) | ||
| if (!string.IsNullOrEmpty(_mergeWith) && !string.IsNullOrWhiteSpace(_mergeWith) && _fileSystem.Exists(_mergeWith)) | ||
| { | ||
| string json = File.ReadAllText(_mergeWith); | ||
| string json = _fileSystem.ReadAllText(_mergeWith); | ||
| coverageResult.Merge(JsonConvert.DeserializeObject<Modules>(json)); | ||
| } | ||
|
|
||
|
|
@@ -228,7 +231,7 @@ private void CalculateCoverage() | |
| { | ||
| foreach (var result in _results) | ||
| { | ||
| if (!File.Exists(result.HitsFilePath)) | ||
| if (!_fileSystem.Exists(result.HitsFilePath)) | ||
MarcoRossignoli marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| // Hits file could be missed mainly for two reason | ||
| // 1) Issue during module Unload() | ||
|
|
@@ -249,7 +252,7 @@ private void CalculateCoverage() | |
| } | ||
| } | ||
|
|
||
| using (var fs = new FileStream(result.HitsFilePath, FileMode.Open)) | ||
| using (var fs = _fileSystem.NewFileStream(result.HitsFilePath, FileMode.Open)) | ||
| using (var br = new BinaryReader(fs)) | ||
| { | ||
| int hitCandidatesCount = br.ReadInt32(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,13 +75,14 @@ public override bool Execute() | |
| { | ||
| Console.WriteLine("\nCalculating coverage result..."); | ||
|
|
||
| if (InstrumenterState is null || !File.Exists(InstrumenterState.ItemSpec)) | ||
| IFileSystem fileSystem = (IFileSystem)DependencyInjection.Current.GetService(typeof(IFileSystem)); | ||
| if (InstrumenterState is null || !fileSystem.Exists(InstrumenterState.ItemSpec)) | ||
| { | ||
| _logger.LogError("Result of instrumentation task not found"); | ||
| return false; | ||
| } | ||
|
|
||
| var coverage = new Coverage(CoveragePrepareResult.Deserialize(new FileStream(InstrumenterState.ItemSpec, FileMode.Open)), this._logger, (IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper))); | ||
| var coverage = new Coverage(CoveragePrepareResult.Deserialize(new FileStream(InstrumenterState.ItemSpec, FileMode.Open)), this._logger, fileSystem, (IInstrumentationHelper)DependencyInjection.Current.GetService(typeof(IInstrumentationHelper))); | ||
|
||
| var result = coverage.GetCoverageResult(); | ||
|
|
||
| var directory = Path.GetDirectoryName(_output); | ||
|
|
@@ -118,7 +119,7 @@ public override bool Execute() | |
|
|
||
| var report = Path.Combine(directory, filename); | ||
| Console.WriteLine($" Generating report '{report}'"); | ||
| File.WriteAllText(report, reporter.Report(result)); | ||
| fileSystem.WriteAllText(report, reporter.Report(result)); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -106,7 +106,20 @@ public override bool Execute() | |
| 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))); | ||
| Coverage coverage = new Coverage(_path, | ||
| includeFilters, | ||
| includeDirectories, | ||
| excludeFilters, | ||
| excludedSourceFiles, | ||
| excludeAttributes, | ||
| _includeTestAssembly, | ||
| _singleHit, | ||
| _mergeWith, | ||
| _useSourceLink, | ||
| _logger, | ||
| (IFileSystem) DependencyInjection.Current.GetService(typeof(IFileSystem)), | ||
| (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)) | ||
MarcoRossignoli marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.