Ejemplo n.º 1
0
        public void ShouldOnlyMutateChangedFiles()
        {
            // Arrange
            var options = new StrykerOptions(diff: true);

            var baselineProvider = new Mock <IBaselineProvider>();
            var diffProvider     = new Mock <IDiffProvider>(MockBehavior.Loose);
            var branchProvider   = new Mock <IGitInfoProvider>();

            string myFile = Path.Combine("C:/test/", "myfile.cs");;

            diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult()
            {
                ChangedSourceFiles = new Collection <string>()
                {
                    myFile
                }
            });
            var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, branchProvider.Object);
            var file   = new CsharpFileLeaf {
                FullPath = myFile
            };

            var mutant = new Mutant();

            // Act
            var filterResult = target.FilterMutants(new List <Mutant>()
            {
                mutant
            }, file.ToReadOnly(), options);

            // Assert
            filterResult.ShouldContain(mutant);
        }
        public void FilterMutants_should_filter_included_and_excluded_files(
            string[] patterns,
            string filePath,
            int spanStart,
            int spanEnd,
            bool shouldKeepFile)
        {
            // Arrange
            var options = new StrykerOptions(mutate: patterns);
            var file    = new CsharpFileLeaf {
                RelativePath = filePath, FullPath = Path.Combine("C:/test/", filePath)
            };

            // Create token with the correct text span
            var syntaxToken = SyntaxFactory.Identifier(
                new SyntaxTriviaList(Enumerable.Range(0, spanStart).Select(x => SyntaxFactory.Space)),
                new string('a', spanEnd - spanStart),
                SyntaxTriviaList.Empty);

            var mutant = new Mutant
            {
                Mutation = new Mutation {
                    OriginalNode = SyntaxFactory.IdentifierName(syntaxToken)
                }
            };

            var sut = new FilePatternMutantFilter();

            // Act
            var result = sut.FilterMutants(new[] { mutant }, file.ToReadOnly(), options);

            // Assert
            result.Contains(mutant).ShouldBe(shouldKeepFile);
        }
Ejemplo n.º 3
0
        public void ShouldNotFilterMutantsWhereCoveringTestsContainsChangedTestFile()
        {
            // Arrange
            string testProjectPath = "C:/MyTests";
            var    options         = new StrykerOptions();

            var baselineProvider = new Mock <IBaselineProvider>();
            var diffProvider     = new Mock <IDiffProvider>(MockBehavior.Loose);
            var branchProvider   = new Mock <IGitInfoProvider>();

            // If a file inside the test project is changed, a test has been changed
            string myTest = Path.Combine(testProjectPath, "myTest.cs");;

            diffProvider.Setup(x => x.ScanDiff()).Returns(new DiffResult()
            {
                ChangedSourceFiles = new Collection <string>()
                {
                    myTest
                },
                ChangedTestFiles = new Collection <string>()
                {
                    myTest
                }
            });
            var target = new DiffMutantFilter(options, diffProvider.Object, baselineProvider.Object, branchProvider.Object);

            // check the diff result for a file not inside the test project
            var file = new CsharpFileLeaf {
                FullPath = Path.Combine("C:/NotMyTests", "myfile.cs")
            };

            var mutant = new Mutant();

            mutant.CoveringTests.Add(new TestDescription(Guid.NewGuid().ToString(), "name", myTest));

            // Act
            var filterResult = target.FilterMutants(new List <Mutant>()
            {
                mutant
            }, file.ToReadOnly(), options);

            // Assert
            filterResult.ShouldContain(mutant);
        }