Пример #1
0
        public void ClearTextReporter_ShouldPrintOnReportDone()
        {
            var console = new TestConsole().EmitAnsiSequences().Width(160);
            var target  = new ClearTextReporter(new StrykerOptions(), console);

            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);

            console.Output.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 │
╰─────────────────────┴─────────┴──────────┴───────────┴────────────┴──────────┴─────────╯
");
            console.Output.DarkGraySpanCount().ShouldBe(2);
        }
Пример #2
0
        public void ClearTextReporter_ShouldPrintOnReportDone()
        {
            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>()
                {
                }
            });

            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   │      N/A │        0 │         0 │          0 │        0 │       0 │
│ SomeFile.cs │      N/A │        0 │         0 │          0 │        0 │       0 │
└─────────────┴──────────┴──────────┴───────────┴────────────┴──────────┴─────────┘
");
            textWriter.DarkGraySpanCount().ShouldBe(2);
        }
        public void ClearTextReporter_ShouldPrintOnReportDone()
        {
            string output    = "";
            var    chalkMock = new Mock <IChalk>(MockBehavior.Strict);

            chalkMock.Setup(x => x.DarkGray(It.IsAny <string>())).Callback((string text) => { output += text; });
            chalkMock.Setup(x => x.Default(It.IsAny <string>())).Callback((string text) => { output += text; });

            var target = new ClearTextReporter(new StrykerOptions(), chalkMock.Object);

            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>()
                {
                }
            });

            target.OnAllMutantsTested(folder);

            output.ToString().ShouldBeWithNewlineReplace($@"

All mutants have been tested, and your mutation score has been calculated
- {Path.DirectorySeparatorChar}RootFolder [0/0 (N/A)]
--- SomeFile.cs [0/0 (N/A)]
");
            chalkMock.Verify(x => x.DarkGray(It.IsAny <string>()), Times.Exactly(2));
        }
Пример #4
0
        public void ClearTextReporter_ShouldPrintYellowBetweenThresholdLowAndThresholdBreak()
        {
            string output    = "";
            var    chalkMock = new Mock <IChalk>(MockBehavior.Strict);

            chalkMock.Setup(x => x.Red(It.IsAny <string>())).Callback((string text) => { output += text; });
            chalkMock.Setup(x => x.Default(It.IsAny <string>())).Callback((string text) => { output += text; });
            chalkMock.Setup(x => x.Green(It.IsAny <string>())).Callback((string text) => { output += text; });
            chalkMock.Setup(x => x.Yellow(It.IsAny <string>())).Callback((string text) => { output += text; });

            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 target = new ClearTextReporter(new StrykerOptions(thresholdHigh: 90, thresholdLow: 70, thresholdBreak: 0), chalkMock.Object);

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

            folder.Add(new FileLeaf()
            {
                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);

            chalkMock.Verify(x => x.Yellow(It.IsAny <string>()), Times.Exactly(2));
        }