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 ClearTextTreeReporter_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 options = new StrykerOptions { Thresholds = new Thresholds { High = 90, Low = 70, Break = 0 } }; var console = new TestConsole().EmitAnsiSequences(); var target = new ClearTextTreeReporter(options, 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.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); console.Output.YellowSpanCount().ShouldBe(2); }
public void ClearTextTreeReporter_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 ClearTextTreeReporter(new StrykerOptions(thresholdHigh: 90, 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", 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 ClearTextTreeReporter_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 ClearTextTreeReporter(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($@" 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 chalkMock.Verify(x => x.Red(It.IsAny <string>()), Times.Exactly(3)); }
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); }
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 console = new TestConsole().EmitAnsiSequences(); var target = new ClearTextTreeReporter(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.RemoveAnsi().ShouldBeWithNewlineReplace($@" All mutants have been tested, and your mutation score has been calculated All files [1/1 ({1:P2})] └── SomeFile.cs [1/1 ({1:P2})] └── [Killed] This name should display on line 1 ├── [-] 0 + 8 └── [+] 0 -8 "); console.Output.GreenSpanCount().ShouldBe(3); }
public void ClearTextTreeReporter_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 ClearTextTreeReporter(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.Killed, Mutation = mutation }, } }); target.OnAllMutantsTested(folder); chalkMock.Verify(x => x.Green(It.IsAny <string>()), Times.Exactly(3)); }
public void ClearTextTreeReporter_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 ClearTextTreeReporter(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 RootFolder [0/0 (N/A)] └── SomeFile.cs [0/0 (N/A)] "); chalkMock.Verify(x => x.DarkGray(It.IsAny <string>()), Times.Exactly(2)); }
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 "); }