Exemple #1
0
        public void ClearTextTreeReporter_ShouldPrintOnReportDone()
        {
            var textWriter = new StringWriter();
            var target     = new ClearTextTreeReporter(new StrykerOptions(), 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>()
                {
                }
            });

            target.OnAllMutantsTested(folder.ToReadOnly());

            textWriter.RemoveAnsi().ShouldBeWithNewlineReplace($@"

All mutants have been tested, and your mutation score has been calculated
All files [0/0 (N/A)]
└── SomeFile.cs [0/0 (N/A)]
");
            textWriter.DarkGraySpanCount().ShouldBe(2);
        }
        public void ClearTextReporter_ShouldPrintYellowBetweenThresholdLowAndThresholdBreak()
        {
            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(thresholdHigh: 90, thresholdLow: 70, thresholdBreak: 0), textWriter);

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

            folder.Add(new CsharpFileLeaf()
            {
                Name         = "SomeFile.cs",
                RelativePath = "RootFolder/SomeFile.cs",
                RelativePathToProjectFile = "SomeFile.cs",
                FullPath = "C://RootFolder/SomeFile.cs",
                Mutants  = new Collection <Mutant>()
                {
                    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
                    },
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Killed, Mutation = mutation
                    }
                }
            });

            target.OnAllMutantsTested(folder.ToReadOnly());

            textWriter.YellowSpanCount().ShouldBe(2);
        }
        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 folder = new CsharpFolderComposite()
            {
                Name         = "RootFolder",
                RelativePath = "RootFolder",
                FullPath     = "C://RootFolder",
            };

            folder.Add(new CsharpFileLeaf()
            {
                Name         = "SomeFile.cs",
                RelativePath = "RootFolder/SomeFile.cs",
                RelativePathToProjectFile = "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
┌─────────────┬──────────┬──────────┬───────────┬────────────┬──────────┬─────────┐
│ File        │  % score │ # killed │ # timeout │ # survived │ # no cov │ # error │
├─────────────┼──────────┼──────────┼───────────┼────────────┼──────────┼─────────┤
│ All files   │     {0:N2} │        0 │         0 │          1 │        0 │       0 │
│ SomeFile.cs │     {0:N2} │        0 │         0 │          1 │        0 │       0 │
└─────────────┴──────────┴──────────┴───────────┴────────────┴──────────┴─────────┘
");
            // All percentages should be red and the [Survived] too
            textWriter.RedSpanCount().ShouldBe(2);
        }
Exemple #4
0
        public void ClearTextTreeReporter_ShouldPrintKilledMutation()
        {
            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 CsharpFolderComposite()
            {
                Name         = "RootFolder",
                RelativePath = "RootFolder",
                FullPath     = "C://RootFolder",
            };

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

            target.OnAllMutantsTested(folder.ToReadOnly());

            textWriter.RemoveAnsi().ShouldBeWithNewlineReplace($@"

All mutants have been tested, and your mutation score has been calculated
RootFolder [1/1 ({1:P2})]
└── SomeFile.cs [1/1 ({1:P2})]
    └── [Killed] This name should display on line 1
        ├── [-] 0 + 8
        └── [+] 0 -8
");
            textWriter.GreenSpanCount().ShouldBe(3);
        }
Exemple #5
0
        public void ClearTextReporter_ShouldPrintOnReportDone()
        {
            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>()
                {
                }
            });

            rootFolder.Add(folder);

            target.OnAllMutantsTested(rootFolder.ToReadOnly());

            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           │      N/A │        0 │         0 │          0 │        0 │       0 │
│ FolderA/SomeFile.cs │      N/A │        0 │         0 │          0 │        0 │       0 │
└─────────────────────┴──────────┴──────────┴───────────┴────────────┴──────────┴─────────┘
");
            textWriter.DarkGraySpanCount().ShouldBe(2);
        }
Exemple #6
0
        public void ClearTextTreeReporter_ShouldPrintFullTree()
        {
            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 CsharpFolderComposite()
            {
                FullPath = "C://ProjectFolder",
            };

            folder.Add(new CsharpFileLeaf()
            {
                RelativePath = "ProjectFolder/Order.cs",
                FullPath     = "C://ProjectFolder/Order.cs",
                Mutants      = new Collection <Mutant>()
                {
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Killed, Mutation = mutation
                    },
                    new Mutant()
                    {
                        ResultStatus = MutantStatus.Killed, Mutation = mutation
                    }
                }
            });
            var folder2 = new CsharpFolderComposite()
            {
                RelativePath = "Subdir",
                FullPath     = "C://ProjectFolder/SubDir",
            };

            folder.Add(folder2);
            folder2.Add(new CsharpFileLeaf()
            {
                RelativePath = "ProjectFolder/SubDir/OrderItem.cs",
                FullPath     = "C://ProjectFolder/SubDir/OrderItem.cs",
                Mutants      = new Collection <Mutant>()
            });
            folder2.Add(new CsharpFileLeaf()
            {
                RelativePath = "ProjectFolder/SubDir/CustomerOrdersWithItemsSpecification.cs",
                FullPath     = "C://ProjectFolder/SubDir/CustomerOrdersWithItemsSpecification.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
All files [2/3 ({(2.0/3.0):P2})]
├── Order.cs [2/2 ({1:P2})]
│   ├── [Killed] This name should display on line 1
│   │   ├── [-] 0 + 8
│   │   └── [+] 0 -8
│   └── [Killed] This name should display on line 1
│       ├── [-] 0 + 8
│       └── [+] 0 -8
└── Subdir [0/1 ({0:P2})]
    ├── OrderItem.cs [0/0 (N/A)]
    └── CustomerOrdersWithItemsSpecification.cs [0/1 ({0:P2})]
        └── [Survived] This name should display on line 1
            ├── [-] 0 + 8
            └── [+] 0 -8
");
        }