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 options = new StrykerOptions { Thresholds = new Thresholds { High = 90, 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.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); textWriter.YellowSpanCount().ShouldBe(2); }
public void ClearTextReporter_ShouldPrintSurvivedMutation() { 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; }); 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(), 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 } } }); target.OnAllMutantsTested(folder); output.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 chalkMock.Verify(x => x.Red(It.IsAny <string>()), Times.Exactly(2)); }
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 target = new ClearTextReporter(new StrykerOptions(thresholdHigh: 80, thresholdLow: 70, thresholdBreak: 0), textWriter); 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.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.ToReadOnly()); textWriter.RedSpanCount().ShouldBe(2); }
public void ClearTextReporter_ShouldPrintSurvivedMutation() { 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; }); 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(), 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>() { new Mutant() { ResultStatus = MutantStatus.Survived, Mutation = mutation } } }); target.OnAllMutantsTested(folder); output.ShouldBeWithNewlineReplace(string.Format( @" All mutants have been tested, and your mutation score has been calculated - {0}RootFolder [0/1 ({1:P2})] --- SomeFile.cs [0/1 ({1:P2})] [Survived] This name should display on line 1: '0 + 8' ==> '0 -8' ", Path.DirectorySeparatorChar, 0)); // All percentages should be red and the [Survived] too chalkMock.Verify(x => x.Red(It.IsAny <string>()), Times.Exactly(3)); }
public void ClearTextReporter_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 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.Killed, 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 │ {100:N2} │ 1 │ 0 │ 0 │ 0 │ 0 │ │ FolderA/SomeFile.cs │ {100:N2} │ 1 │ 0 │ 0 │ 0 │ 0 │ └─────────────────────┴──────────┴──────────┴───────────┴────────────┴──────────┴─────────┘ "); textWriter.GreenSpanCount().ShouldBe(2); }
public void ClearTextReporter_ShouldPrintGreenAboveThresholdHigh() { string output = ""; var chalkMock = new Mock <IChalk>(MockBehavior.Strict); 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; }); 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(), 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.Killed, Mutation = mutation }, } }); target.OnAllMutantsTested(folder); chalkMock.Verify(x => x.Green(It.IsAny <string>()), Times.Exactly(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", RelativePathToProjectFile = "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 ┌─────────────┬──────────┬──────────┬───────────┬────────────┬──────────┬─────────┐ │ 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 │ └─────────────┴──────────┴──────────┴───────────┴────────────┴──────────┴─────────┘ "); chalkMock.Verify(x => x.DarkGray(It.IsAny <string>()), Times.Exactly(2)); }
public void ClearTextReporter_ShouldPrintGreenAboveThresholdHigh() { 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 console = new TestConsole().EmitAnsiSequences().Width(160); var target = new ClearTextReporter(new StrykerOptions(), console); 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.Killed, Mutation = mutation }, } }); target.OnAllMutantsTested(folder); console.Output.GreenSpanCount().ShouldBe(2); }
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); 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); }
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)); }