Example #1
0
        public void ClearTextReporter_ShouldPrintRedUnderThresholdBreak()
        {
            var tree         = CSharpSyntaxTree.ParseText("void M(){ int i = 0 + 8; }");
            var originalNode = tree.GetRoot().DescendantNodes().OfType <BinaryExpressionSyntax>().First();

            var mutation = new Mutation()
            {
                OriginalNode    = originalNode,
                ReplacementNode = SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, originalNode.Left, originalNode.Right),
                DisplayName     = "This name should display",
                Type            = Mutator.Arithmetic
            };

            var textWriter = new StringWriter();
            var options    = new StrykerOptions {
                Thresholds = new Thresholds {
                    High = 80, Low = 70, Break = 0
                }
            };
            var target = new ClearTextReporter(options, textWriter);

            var folder = new CsharpFolderComposite()
            {
                RelativePath = "RootFolder",
                FullPath     = "C://RootFolder",
            };

            folder.Add(new CsharpFileLeaf()
            {
                RelativePath = "RootFolder/SomeFile.cs",
                FullPath     = "C://RootFolder/SomeFile.cs",
                Mutants      = new Collection <Mutant>()
                {
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Survived, Mutation = mutation
                    },
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Survived, Mutation = mutation
                    },
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Killed, Mutation = mutation
                    },
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Killed, Mutation = mutation
                    },
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Killed, Mutation = mutation
                    }
                }
            });

            target.OnAllMutantsTested(folder);

            textWriter.RedSpanCount().ShouldBe(2);
        }
Example #2
0
        public void ClearTextReporter_ShouldPrintSurvivedMutation()
        {
            var tree         = CSharpSyntaxTree.ParseText("void M(){ int i = 0 + 8; }");
            var originalNode = tree.GetRoot().DescendantNodes().OfType <BinaryExpressionSyntax>().First();

            var mutation = new Mutation()
            {
                OriginalNode    = originalNode,
                ReplacementNode = SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, originalNode.Left, originalNode.Right),
                DisplayName     = "This name should display",
                Type            = Mutator.Arithmetic
            };

            var textWriter = new StringWriter();
            var target     = new ClearTextReporter(new StrykerOptions(), textWriter);

            var rootFolder = new CsharpFolderComposite();

            var folder = new CsharpFolderComposite()
            {
                RelativePath = "FolderA",
                FullPath     = "C://Project/FolderA",
            };

            folder.Add(new CsharpFileLeaf()
            {
                RelativePath = "FolderA/SomeFile.cs",
                FullPath     = "C://Project/FolderA/SomeFile.cs",
                Mutants      = new Collection <Mutant>()
                {
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Survived,
                        Mutation     = mutation
                    }
                }
            });
            rootFolder.Add(folder);

            target.OnAllMutantsTested(rootFolder);

            textWriter.RemoveAnsi().ShouldBeWithNewlineReplace($@"

All mutants have been tested, and your mutation score has been calculated
┌─────────────────────┬──────────┬──────────┬───────────┬────────────┬──────────┬─────────┐
│ File                │  % score │ # killed │ # timeout │ # survived │ # no cov │ # error │
├─────────────────────┼──────────┼──────────┼───────────┼────────────┼──────────┼─────────┤
│ All files           │     {0:N2} │        0 │         0 │          1 │        0 │       0 │
│ FolderA/SomeFile.cs │     {0:N2} │        0 │         0 │          1 │        0 │       0 │
└─────────────────────┴──────────┴──────────┴───────────┴────────────┴──────────┴─────────┘
");
            // All percentages should be red and the [Survived] too
            textWriter.RedSpanCount().ShouldBe(2);
        }
        public void ClearTextTreeReporter_ShouldPrintSurvivedMutation()
        {
            var tree         = CSharpSyntaxTree.ParseText("void M(){ int i = 0 + 8; }");
            var originalNode = tree.GetRoot().DescendantNodes().OfType <BinaryExpressionSyntax>().First();

            var mutation = new Mutation()
            {
                OriginalNode    = originalNode,
                ReplacementNode = SyntaxFactory.BinaryExpression(SyntaxKind.SubtractExpression, originalNode.Left, originalNode.Right),
                DisplayName     = "This name should display",
                Type            = Mutator.Arithmetic
            };

            var textWriter = new StringWriter();
            var target     = new ClearTextTreeReporter(new StrykerOptions(), textWriter);

            var folder = new FolderComposite()
            {
                Name         = "RootFolder",
                RelativePath = "RootFolder",
                FullPath     = "C://RootFolder",
            };

            folder.Add(new FileLeaf()
            {
                Name         = "SomeFile.cs",
                RelativePath = "RootFolder/SomeFile.cs",
                FullPath     = "C://RootFolder/SomeFile.cs",
                Mutants      = new Collection <Mutant>()
                {
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Survived, Mutation = mutation
                    }
                }
            });

            target.OnAllMutantsTested(folder.ToReadOnly());

            textWriter.RemoveAnsi().ShouldBeWithNewlineReplace($@"

All mutants have been tested, and your mutation score has been calculated
RootFolder [0/1 ({0:P2})]
└── SomeFile.cs [0/1 ({0:P2})]
    └── [Survived] This name should display on line 1
        ├── [-] 0 + 8
        └── [+] 0 -8
");

            // All percentages should be red and the [Survived] too
            textWriter.RedSpanCount().ShouldBe(3);
        }
Example #4
0
        public void ConsoleDotReporter_ShouldPrintRightCharOnMutation(MutantStatus givenStatus, string expectedOutput, string color)
        {
            var textWriter = new StringWriter();
            var target     = new ConsoleDotProgressReporter(textWriter);

            target.OnMutantTested(new Mutant()
            {
                ResultStatus = givenStatus
            });

            if (color == "default")
            {
                textWriter.AnyForegroundColorSpanCount().ShouldBe(0);
            }

            if (color == "red")
            {
                textWriter.RedSpanCount().ShouldBe(1);
            }

            textWriter.RemoveAnsi().ShouldBe(expectedOutput);
        }