public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent)
        {
            Tree root = null;

            var stack = new Stack <IHasTreeNodes>();

            // setup display handlers
            reportComponent.DisplayFolder = (IReadOnlyProjectComponent current) =>
            {
                var name = Path.GetFileName(current.RelativePath);

                if (root is null)
                {
                    root = new Tree("All files" + DisplayComponent(current));
                    stack.Push(root);
                }
                else if (!string.IsNullOrWhiteSpace(name))
                {
                    stack.Push(stack.Peek().AddNode(name + DisplayComponent(current)));
                }
            };

            reportComponent.DisplayFile = (IReadOnlyProjectComponent current) =>
            {
                var name = Path.GetFileName(current.RelativePath);

                var fileNode = stack.Peek().AddNode(name + DisplayComponent(current));

                if (current.FullPath == current.Parent.Children.Last().FullPath)
                {
                    stack.Pop();
                }

                var totalMutants = current.TotalMutants();
                foreach (var mutant in totalMutants)
                {
                    var status = mutant.ResultStatus switch
                    {
                        MutantStatus.Killed or MutantStatus.Timeout => $"[Green][[{mutant.ResultStatus}]][/]",
                             MutantStatus.NoCoverage => $"[Yellow][[{mutant.ResultStatus}]][/]",
                             _ => $"[Red][[{mutant.ResultStatus}]][/]",
                    };

                    var mutantNode = fileNode.AddNode(status + $" {mutant.Mutation.DisplayName} on line {mutant.Line}");
                    mutantNode.AddNode(Markup.Escape($"[-] {mutant.Mutation.OriginalNode}"));
                    mutantNode.AddNode(Markup.Escape($"[+] {mutant.Mutation.ReplacementNode}"));
                }
            };

            // print empty line for readability
            _console.WriteLine();
            _console.WriteLine();
            _console.WriteLine("All mutants have been tested, and your mutation score has been calculated");

            // start recursive invocation of handlers
            reportComponent.Display();

            _console.Write(root);
        }
Esempio n. 2
0
        public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent)
        {
            var files = new List <ReadOnlyFileLeaf>();

            ReadOnlyFolderComposite rootFolder = null;

            reportComponent.DisplayFolder = (IReadOnlyProjectComponent current) =>
            {
                rootFolder ??= (ReadOnlyFolderComposite)current;
            };

            reportComponent.DisplayFile = (IReadOnlyProjectComponent current) =>
            {
                files.Add((ReadOnlyFileLeaf)current);
            };

            // print empty line for readability
            _consoleWriter.WriteLine();
            _consoleWriter.WriteLine();
            _consoleWriter.WriteLine("All mutants have been tested, and your mutation score has been calculated");

            // start recursive invocation of handlers
            reportComponent.Display();

            var filePathLength = Math.Max(9, files.Max(f => f.RelativePath?.Length ?? 0) + 1);

            _consoleWriter.WriteLine($"┌─{new string('─', filePathLength)}┬──────────┬──────────┬───────────┬────────────┬──────────┬─────────┐");
            _consoleWriter.WriteLine($"│ File{new string(' ', filePathLength - 4)}│  % score │ # killed │ # timeout │ # survived │ # no cov │ # error │");
            _consoleWriter.WriteLine($"├─{new string('─', filePathLength)}┼──────────┼──────────┼───────────┼────────────┼──────────┼─────────┤");

            DisplayComponent(rootFolder, filePathLength);

            foreach (var file in files)
            {
                DisplayComponent(file, filePathLength);
            }

            _consoleWriter.WriteLine($"└─{new string('─', filePathLength)}┴──────────┴──────────┴───────────┴────────────┴──────────┴─────────┘");
        }
Esempio n. 3
0
        public void OnAllMutantsTested(IReadOnlyProjectComponent reportComponent)
        {
            var rootFolderProcessed = false;

            // setup display handlers
            reportComponent.DisplayFolder = (IReadOnlyProjectComponent current) =>
            {
                // show depth
                var continuationLines = ParentContinuationLines(current);

                var stringBuilder = new StringBuilder();
                foreach (var item in continuationLines.SkipLast(1))
                {
                    stringBuilder.Append(item ? ContinueLine : NoLine);
                }

                var folderLines = string.Empty;
                if (continuationLines.Count > 0)
                {
                    folderLines = continuationLines.Last() ? BranchLine : FinalBranchLine;
                }

                var name = Path.GetFileName(current.RelativePath);
                if (current.Parent == null && !rootFolderProcessed)
                {
                    name = "All files";
                    rootFolderProcessed = true;
                }

                if (!string.IsNullOrWhiteSpace(name))
                {
                    _consoleWriter.Write($"{stringBuilder}{folderLines}{name}");
                    DisplayComponent(current);
                }
            };

            reportComponent.DisplayFile = (IReadOnlyProjectComponent current) =>
            {
                // show depth
                var continuationLines = ParentContinuationLines(current);

                var stringBuilder = new StringBuilder();
                foreach (var item in continuationLines.SkipLast(1))
                {
                    stringBuilder.Append(item ? ContinueLine : NoLine);
                }
                var name = Path.GetFileName(current.RelativePath);

                _consoleWriter.Write($"{stringBuilder}{(continuationLines.Last() ? BranchLine : FinalBranchLine)}{name}");
                DisplayComponent(current);

                stringBuilder.Append(continuationLines.Last() ? ContinueLine : NoLine);

                var prefix       = stringBuilder.ToString();
                var totalMutants = current.TotalMutants();
                foreach (var mutant in totalMutants)
                {
                    var isLastMutant = totalMutants.Last() == mutant;

                    _consoleWriter.Write($"{prefix}{(isLastMutant ? FinalBranchLine : BranchLine)}");

                    switch (mutant.ResultStatus)
                    {
                    case MutantStatus.Killed:
                    case MutantStatus.Timeout:
                        _consoleWriter.Write(Output.Green($"[{mutant.ResultStatus}]"));
                        break;

                    case MutantStatus.NoCoverage:
                        _consoleWriter.Write(Output.Yellow($"[{mutant.ResultStatus}]"));
                        break;

                    default:
                        _consoleWriter.Write(Output.Red($"[{mutant.ResultStatus}]"));
                        break;
                    }

                    _consoleWriter.WriteLine($" {mutant.Mutation.DisplayName} on line {mutant.Line}");
                    _consoleWriter.WriteLine($"{prefix}{(isLastMutant ? NoLine : ContinueLine)}{BranchLine}[-] {mutant.Mutation.OriginalNode}");
                    _consoleWriter.WriteLine($"{prefix}{(isLastMutant ? NoLine : ContinueLine)}{FinalBranchLine}[+] {mutant.Mutation.ReplacementNode}");
                }
            };

            // print empty line for readability
            _consoleWriter.WriteLine();
            _consoleWriter.WriteLine();
            _consoleWriter.WriteLine("All mutants have been tested, and your mutation score has been calculated");

            // start recursive invocation of handlers
            reportComponent.Display();
        }