Example #1
0
        public void CreateGetSourceAndSequencePoints()
        {
            const uint   fileId1      = 1;
            const string sourceString = "abc { def }";

            var mockLog = new Mock <ILog>();
            var source  = new CodeCoverageStringTextSource(sourceString, "", mockLog.Object);

            var sRepo = new SourceRepository();

            sRepo[fileId1] = source;

            var spLeft = new SequencePoint()
            {
                FileId      = 1,
                StartLine   = 1,
                EndLine     = 1,
                StartColumn = 5,
                EndColumn   = 6
            };

            var spRight = new SequencePoint()
            {
                FileId      = 1,
                StartLine   = 1,
                EndLine     = 1,
                StartColumn = 11,
                EndColumn   = 12
            };

            var spInvalid = new SequencePoint()
            {
                FileId      = 2,
                StartLine   = 1,
                EndLine     = 1,
                StartColumn = 11,
                EndColumn   = 12
            };

            Assert.True(sRepo.GetCodeCoverageStringTextSource(0) == null);
            Assert.True(sRepo.GetCodeCoverageStringTextSource(1) == source);
            Assert.True(sRepo.GetCodeCoverageStringTextSource(2) == null);
            Assert.True(sRepo.GetCodeCoverageStringTextSource(1).GetLine(1) == sourceString);
            Assert.True(sRepo.GetCodeCoverageStringTextSource(1).GetText(spLeft) == "{");
            Assert.True(sRepo.GetCodeCoverageStringTextSource(1).GetText(spRight) == "}");

            Assert.True(sRepo.GetSequencePointText(null) == "");
            Assert.True(sRepo.GetSequencePointText(spInvalid) == "");

            Assert.True(sRepo.GetSequencePointText(spLeft) == "{");
            Assert.True(sRepo.GetSequencePointText(spRight) == "}");
        }
Example #2
0
        private static void TransformSequences_RemoveFalsePositiveUnvisited(IEnumerable <Method> methods, SourceRepository sourceRepository, DateTime moduleTime)
        {
            var sequencePointsSet           = new HashSet <SequencePoint>(new SequencePointComparer());
            var toRemoveMethodSequencePoint = new List <Tuple <Method, SequencePoint> >();

            // Initialise sequencePointsSet
            TransformSequences_RemoveFalsePositiveUnvisited(methods, sequencePointsSet);

            // Check generated methods
            foreach (var method in methods
                     .Where(m => m.FileRefUniqueId != 0 &&
                            m.SequencePoints.Length != 0 &&
                            m.IsGenerated))
            {
                // Select duplicate and false-positive unvisited sequence points
                // (Sequence point duplicated by generated method and left unvisited)
                foreach (var sp in method.SequencePoints
                         .Where(sp => sp.FileId == method.FileRefUniqueId &&
                                sp.VisitCount == 0))
                {
                    if (sequencePointsSet.Contains(sp))
                    {
                        // Unvisited duplicate found, add to remove list
                        toRemoveMethodSequencePoint.Add(new Tuple <Method, SequencePoint>(method, sp));
                    }
                }

                // Get method source if availabile
                var source = sourceRepository.GetCodeCoverageStringTextSource(method.FileRefUniqueId);
                if (source != null && !source.IsChanged(moduleTime))
                {
                    TransformSequences_RemoveFalsePositiveUnvisited(method, source, toRemoveMethodSequencePoint);
                }
            }

            // Remove selected SequencePoints
            foreach (var tuple in toRemoveMethodSequencePoint)
            {
                tuple.Item1.SequencePoints = tuple.Item1.SequencePoints.Where(sp => sp != tuple.Item2).ToArray();
            }
        }
Example #3
0
        private static void TransformSequences_RemoveCompilerGeneratedBranches(IEnumerable <Method> methods, SourceRepository sourceRepository, DateTime moduleTime)
        {
            foreach (var method in methods
                     .Where(m => m.FileRefUniqueId != 0 &&
                            m.SequencePoints.Length != 0))
            {
                // Get method source if availabile
                var source = sourceRepository.GetCodeCoverageStringTextSource(method.FileRefUniqueId);
                if (source != null)
                {
                    if (source.IsChanged(moduleTime))
                    {
                        ("Source file is modified: " + source.FilePath).InformUser();
                        return;
                    }

                    if (!TransformSequences_RemoveCompilerGeneratedBranches(method, source))
                    {
                        return; // empty sequence found -> source.IsChanged (failed access to file-times)
                    }
                }
            }
        }
Example #4
0
        private static void TransformSequences_RemoveFalsePositiveUnvisited (IEnumerable<Method> methods, SourceRepository sourceRepository, DateTime moduleTime)
        {
            var sequencePointsSet = new HashSet<SequencePoint>(new SequencePointComparer());
            var toRemoveMethodSequencePoint = new List<Tuple<Method, SequencePoint>>();

            // Initialise sequencePointsSet
            TransformSequences_RemoveFalsePositiveUnvisited(methods, sequencePointsSet);

            // Check generated methods
            foreach (var method in methods
                     .Where (m => m.FileRefUniqueId != 0
                             && m.SequencePoints.Length != 0
                             && m.IsGenerated)) {

                // Select duplicate and false-positive unvisited sequence points
                // (Sequence point duplicated by generated method and left unvisited)
                foreach (var sp in method.SequencePoints
                         .Where (sp => sp.FileId == method.FileRefUniqueId
                                 && sp.VisitCount == 0) ) {
    
                    if (sequencePointsSet.Contains(sp)) {
                        // Unvisited duplicate found, add to remove list
                        toRemoveMethodSequencePoint.Add (new Tuple<Method, SequencePoint>(method, sp));
                    }
                }
    
                // Get method source if availabile 
                var source = sourceRepository.GetCodeCoverageStringTextSource(method.FileRefUniqueId);
                if (source != null && !source.IsChanged(moduleTime)) {
                    TransformSequences_RemoveFalsePositiveUnvisited (method, source, toRemoveMethodSequencePoint);
                }

            }

            // Remove selected SequencePoints
            foreach (var tuple in toRemoveMethodSequencePoint) {
                tuple.Item1.SequencePoints = tuple.Item1.SequencePoints.Where(sp => sp != tuple.Item2).ToArray();
            }
        }
Example #5
0
        private static void TransformSequences_RemoveCompilerGeneratedBranches (IEnumerable<Method> methods, SourceRepository sourceRepository, DateTime moduleTime)
        {
            foreach (var method in methods
                     .Where (m => m.FileRefUniqueId != 0
                             && m.SequencePoints.Length != 0)) {
            
                // Get method source if availabile 
                var source = sourceRepository.GetCodeCoverageStringTextSource(method.FileRefUniqueId);
                if (source != null) {

                    if (source.IsChanged (moduleTime)) {
                        ("Source file is modified: " + source.FilePath).InformUser();
                        return;
                    }

                    if (!TransformSequences_RemoveCompilerGeneratedBranches (method, source)) {
                        return; // empty sequence found -> source.IsChanged (failed access to file-times)
                    }
                }
            }
        }