Example #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;
                }
            }
        }
    }
Example #2
0
        public bool Valid(CoverageFile coverageFile, out string error)
        {
            error = null;

            if (coverageFile == null)
            {
                error = "Obiekt jest pusty.";
            }
            else if (string.IsNullOrEmpty(coverageFile.Path))
            {
                error = "Ścieżka do pliku jest pusta.";
            }
            else if (coverageFile.CoverageData == null || coverageFile.CoverageData.Count == 0)
            {
                error = "Wczytany plik nie zawiera poprawnych danych.";
            }
            else
            {
                var length = coverageFile.CoverageData[0].Count;
                if (coverageFile.CoverageData.Any(x => x.Count != length))
                {
                    error = "Wiersze muszą mieć jednakową ilość kolumn.";
                }
            }

            return(error == null);
        }
Example #3
0
        public void Coverage_NoSource_LengthIsLargestLineRecorded()
        {
            var coverageFile = new CoverageFile();

            coverageFile.Record(20, 3);

            coverageFile.Coverage.Length.Should().Be(20);
        }
Example #4
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();
    }
Example #5
0
        public void Source_SetToGet_MaintainsToUnixLineBreaks()
        {
            var sourceText   = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Source.Should().Be("Line1\nLine2\nLine3");
        }
Example #6
0
        public void Coverage_NoLinesCovered_StillHasCorrectLength()
        {
            var sourceText   = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Coverage.Length.Should().Be(3);
        }
        public void Source_SetEmptyString_BecomesNull()
        {
            var sourceText   = "";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Source.Should().BeNull();
        }
Example #8
0
        public void Coverage_NoLinesCovered_AllValuesNull()
        {
            var sourceText   = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Coverage[0].Should().Be(null);
            coverageFile.Coverage[1].Should().Be(null);
            coverageFile.Coverage[2].Should().Be(null);
        }
        public override List <CoverageFile> Generate()
        {
            var files = new List <CoverageFile>();

            if (Report == null || Report.Root == null)
            {
                return(files);
            }

            foreach (var module in Report.Root.XPathSelectElements("//Modules/Module"))
            {
                var skippedAttr = module.Attribute("skippedDueTo");
                if (skippedAttr != null && skippedAttr.Value.IsNotBlank())
                {
                    continue;
                }

                foreach (var file in module.XPathSelectElements("./Files/File"))
                {
                    var fileid   = file.Attribute("uid").Value;
                    var fullPath = file.Attribute("fullPath").Value;

                    var coverageFile = new CoverageFile
                    {
                        Path   = fullPath.ToUnixPath(),
                        Source = FileSystem.ReadFileText(fullPath)
                    };

                    foreach (var @class in module.XPathSelectElements("./Classes/Class"))
                    {
                        foreach (var method in @class.XPathSelectElements("./Methods/Method"))
                        {
                            foreach (var sequencePoint in method.XPathSelectElements("./SequencePoints/SequencePoint"))
                            {
                                var sequenceFileId = sequencePoint.Attribute("fileid").Value;
                                if (fileid == sequenceFileId)
                                {
                                    var line   = int.Parse(sequencePoint.Attribute("sl").Value);
                                    var visits = int.Parse(sequencePoint.Attribute("vc").Value);

                                    coverageFile.Record(line, visits);
                                }
                            }
                        }
                    }

                    files.Add(coverageFile);
                }
            }

            return(files);
        }
Example #10
0
        public void Coverage_OneLineCovered_AllValuesCorrect()
        {
            var sourceText   = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Record(1, 1);

            coverageFile.Coverage[0].Should().Be(1);
            coverageFile.Coverage[1].Should().Be(null);
            coverageFile.Coverage[2].Should().Be(null);
        }
        public void Coverage_MultipleLinesCovered_AllValuesCorrect()
        {
            var sourceText   = "Line1\nLine2\nLine3";
            var coverageFile = new CoverageFile();

            coverageFile.Source = sourceText;

            coverageFile.Record(1, 1);
            coverageFile.Record(3, 3);

            coverageFile.Coverage.ToArray()[0].Should().Be(1);
            coverageFile.Coverage.ToArray()[1].Should().Be(null);
            coverageFile.Coverage.ToArray()[2].Should().Be(3);
        }
Example #12
0
        public void Valid_WhenPutEmptyDataInCoverageFile_ThenShouldReturnFalseWithError()
        {
            //Arrange
            var path         = "path";
            var coverageData = new CoverageData(new List <List <int> >());
            var coverageFile = new CoverageFile(path, coverageData);

            //Act
            var result = _coverageFileValidator.Valid(coverageFile, out var errorMessage);

            //Assert
            Assert.False(result);
            Assert.NotEmpty(errorMessage);
        }
Example #13
0
        public override IEnumerable <CoverageFile> Generate()
        {
            var files = new List <CoverageFile>();

            if (Report == null || Report.Root == null)
            {
                return(files);
            }

            var basePathEl = Report.Root.XPathSelectElement("//sources/source");
            var basePath   = string.Empty;

            if (basePathEl != null && basePathEl.Value.IsNotBlank())
            {
                basePath = basePathEl.Value;
            }

            foreach (var package in Report.Root.XPathSelectElements("//packages/package"))
            {
                foreach (var cl in package.XPathSelectElements("./classes/class"))
                {
                    var filenameAttrib = cl.Attribute("filename");
                    var fileName       = filenameAttrib.Value;
                    var path           = Path.Combine(basePath, fileName);

                    var coverageFile = new CoverageFile()
                    {
                        Path = path.ToUnixPath()
                    };

                    foreach (var line in cl.XPathSelectElements("./lines/line"))
                    {
                        var lineNumber = int.Parse(line.Attribute("number").Value);
                        var hits       = int.Parse(line.Attribute("hits").Value);

                        coverageFile.Record(lineNumber, hits);
                    }

                    files.Add(coverageFile);
                }
            }

            return(files);
        }
Example #14
0
        public GranuleSetWithPath Load(out string error)
        {
            error = null;
            var path = _fileService.GetPathFromOpenFileDialog(FileService.CsvFilter);

            if (string.IsNullOrEmpty(path))
            {
                if (path == string.Empty)
                {
                    error = "Ścieżka do pliku jest pusta.";
                }

                return(null);
            }

            var content = _fileService.ReadFile(path, out error);

            if (!string.IsNullOrEmpty(error))
            {
                return(null);
            }

            var data = _coverageDataConverter.Convert(content, out error);

            if (data == null)
            {
                return(null);
            }

            var coverageFile = new CoverageFile(path, data);

            if (!_coverageFileValidator.Valid(coverageFile, out error))
            {
                return(null);
            }

            var granuleSet = _granuleService.GenerateGran(coverageFile.CoverageData);

            return(new GranuleSetWithPath(granuleSet, path));
        }
Example #15
0
        public void Valid_WhenPutNullLikePathInCoverageFile_ThenShouldReturnFalseWithError()
        {
            //Arrange
            var coverageData = new CoverageData(new List <List <int> >
            {
                new List <int> {
                    1, 2, 3
                }, new List <int> {
                    1, 2, 3
                }, new List <int> {
                    1, 2, 3
                }
            });
            var coverageFile = new CoverageFile(null, coverageData);

            //Act
            var result = _coverageFileValidator.Valid(coverageFile, out var errorMessage);

            //Assert
            Assert.False(result);
            Assert.NotEmpty(errorMessage);
        }
Example #16
0
        public void Valid_WhenPutRightCoverageFile_ThenShouldReturnTrueWithoutError()
        {
            //Arrange
            var path         = "path";
            var coverageData = new CoverageData(new List <List <int> >
            {
                new List <int> {
                    1, 2, 3
                }, new List <int> {
                    1, 2, 3
                }, new List <int> {
                    1, 2, 3
                }
            });
            var coverageFile = new CoverageFile(path, coverageData);

            //Act
            var result = _coverageFileValidator.Valid(coverageFile, out var errorMessage);

            //Assert
            Assert.True(result);
            Assert.Null(errorMessage);
        }
Example #17
0
 public override void OnStartFile(CoverageFile file)
 {
     _jsonWriter !.WritePropertyName(file.RealName ?? file.FileName);
     WriteStats(file.Stats !);
 }
Example #18
0
 public virtual void OnFinishFile(CoverageFile file)
 {
 }
            public WhenCreatingACoverageFromADefaultBuilder()
            {
                var builder = CreateFileBuilder(Filename);

                _coverageFile = builder.CreateFile();
            }
 public  WhenCreatingACoverageFromADefaultBuilder()
 {
     var builder = CreateFileBuilder(Filename);
     _coverageFile = builder.CreateFile();
 }
Example #21
0
 public virtual void OnStartFile(CoverageFile file)
 {
 }
Example #22
0
 public CompareFiles(CoverageFile one, CoverageFile two, CompareBy compareBy) : base(one.Modules.ToArray(), two.Modules.ToArray(), compareBy)
 {
 }