Exemplo n.º 1
0
        public void BuildCoveredFiles(string?commonRoot = null)
        {
            CoveredFiles.Clear();
            foreach (var keyValuePair in InstrumentedFiles)
            {
                var fn       = keyValuePair.Key;
                var fileName = keyValuePair.Value.FileName;
                var realName = keyValuePair.Value.RealName;
                if (commonRoot != null)
                {
                    fn       = PathUtils.Subtract(fn, commonRoot);
                    fileName = PathUtils.Subtract(fileName, commonRoot);
                    if (realName != null)
                    {
                        realName = PathUtils.Subtract(realName, commonRoot);
                    }
                }

                if (realName == null || fn == realName)
                {
                    var cf = new CoverageFile(fileName, realName, keyValuePair.Value);
                    CoveredFiles[fn] = cf;
                    if (realName != null)
                    {
                        CoveredFiles[fileName] = cf;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void OnStartFile(CoverageFile file)
        {
            _jsonWriter !.WritePropertyName(file.RealName ?? file.FileName);
            WriteStats(file.Stats !, false);
            _jsonWriter !.WriteStartArray("encodedRanges");
            foreach (var coverageInfo in file.Infos)
            {
                var info = coverageInfo.Source;
                switch (info.Type)
                {
                case InstrumentedInfoType.Statement:
                    _jsonWriter !.WriteNumberValue(0);
                    _jsonWriter !.WriteNumberValue(info.Start.Line);
                    _jsonWriter !.WriteNumberValue(info.Start.Col);
                    _jsonWriter !.WriteNumberValue(info.End.Line);
                    _jsonWriter !.WriteNumberValue(info.End.Col);
                    _jsonWriter !.WriteNumberValue((int)coverageInfo.Hits);
                    break;

                case InstrumentedInfoType.Condition:
                    _jsonWriter !.WriteNumberValue(1);
                    _jsonWriter !.WriteNumberValue(info.Start.Line);
                    _jsonWriter !.WriteNumberValue(info.Start.Col);
                    _jsonWriter !.WriteNumberValue(info.End.Line);
                    _jsonWriter !.WriteNumberValue(info.End.Col);
                    _jsonWriter !.WriteNumberValue((int)coverageInfo.Hits);
                    _jsonWriter !.WriteNumberValue((int)coverageInfo.SecondaryHits);
                    break;

                case InstrumentedInfoType.Function:
                    _jsonWriter !.WriteNumberValue(2);
                    _jsonWriter !.WriteNumberValue(info.Start.Line);
                    _jsonWriter !.WriteNumberValue(info.Start.Col);
                    _jsonWriter !.WriteNumberValue(info.End.Line);
                    _jsonWriter !.WriteNumberValue(info.End.Col);
                    _jsonWriter !.WriteNumberValue((int)coverageInfo.Hits);
                    break;

                case InstrumentedInfoType.SwitchBranch:
                    _jsonWriter !.WriteNumberValue(3);
                    _jsonWriter !.WriteNumberValue(info.Start.Line);
                    _jsonWriter !.WriteNumberValue(info.Start.Col);
                    _jsonWriter !.WriteNumberValue(info.End.Line);
                    _jsonWriter !.WriteNumberValue(info.End.Col);
                    _jsonWriter !.WriteNumberValue((int)coverageInfo.Hits);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            _jsonWriter !.WriteEndArray();
            if (_covInstr.SourceReader != null)
            {
                _jsonWriter !.WriteString("source", Encoding.UTF8.GetString(_covInstr.SourceReader.ReadUtf8(file.InstrumentedFile.FileName)));
            }
            _jsonWriter !.WriteEndObject();
        }
Exemplo n.º 3
0
 public override void OnStartFile(CoverageFile file)
 {
     _jsonWriter !.WritePropertyName(file.RealName ?? file.FileName);
     WriteStats(file.Stats !);
 }