Пример #1
0
        protected void Given_some_mutants_will_survive()
        {
            var baseSlnDir = Path.Combine(TestContext.CurrentContext.TestDirectory, "..", "..", "..", "..");

            var survivingMutant = new SurvivingMutant
            {
                SourceFilePath = Path.Combine(baseSlnDir, "someclass.cs"),
                SourceLine     = 123,
                OriginalLine   = "a+b",
                MutatedLine    = "a-b"
            };

            MockMutationTestRunner
            .Setup(r => r.Run(It.IsAny <Config>()))
            .Callback(() =>
            {
                // Raise events that a real MutationTestRunner would raise.
                var classFilePath = Path.Combine(baseSlnDir, "someclass.cs");
                eventListener.BeginMutationOfFile(classFilePath, baseSlnDir, 0, 1);
                eventListener.MemberMutating("System.Void SomeProject.SomeOtherNamespace.SomeClass::SomeMethod(System.Int32)");
                eventListener.SyntaxNodeMutating(0, 1);
                eventListener.MutantSurvived(survivingMutant);
                eventListener.EndMutationOfFile(classFilePath);
            })
            .Returns(Task.FromResult(new MutationTestResult().WithSurvivingMutants(new [] { survivingMutant })));
        }
Пример #2
0
        public async Task <IEnumerable <SurvivingMutant> > RunAll(
            ITestRunner testRunner,
            string baseTempDirectory,
            IEventListener eventListener)
        {
            var survivingMutants     = new List <SurvivingMutant>();
            var survivingSyntaxNodes = new HashSet <SyntaxNode>();
            var reportedMembers      = new HashSet <string>();

            var jobsBySourceFile = jobsWithMetadata.GroupBy(x => x.Key.SourceFilePath, x => x).ToArray();

            for (var sourceFileIndex = 0; sourceFileIndex < jobsBySourceFile.Length; sourceFileIndex++)
            {
                var jobsForSourceFile = jobsBySourceFile[sourceFileIndex];
                var sourceFilePath    = jobsForSourceFile.Key;

                eventListener.BeginMutationOfFile(
                    sourceFilePath, Path.GetDirectoryName(config.SolutionFilePath), sourceFileIndex, jobsBySourceFile.Length);

                foreach (var mutationJobAndMetadata in jobsForSourceFile)
                {
                    var metadata    = mutationJobAndMetadata.Key;
                    var mutationJob = mutationJobAndMetadata.Value;

                    var syntaxNodeAlreadyHadSurvivingMutant = survivingSyntaxNodes.Contains(mutationJob.OriginalNode);
                    if (syntaxNodeAlreadyHadSurvivingMutant)
                    {
                        continue;
                    }

                    if (!reportedMembers.Contains(metadata.MemberName))
                    {
                        eventListener.MemberMutating(metadata.MemberName);
                        reportedMembers.Add(metadata.MemberName);
                    }
                    eventListener.SyntaxNodeMutating(metadata.SyntaxNodeIndex, metadata.SyntaxNodesTotal);

                    var survivingMutant = await mutationJob.Run(testRunner, baseTempDirectory, eventListener);

                    if (survivingMutant != null)
                    {
                        survivingMutants.Add(survivingMutant);

                        survivingSyntaxNodes.Add(mutationJob.OriginalNode);
                        eventListener.MutantSurvived(survivingMutant);
                    }
                }

                eventListener.EndMutationOfFile(sourceFilePath);
            }

            return(survivingMutants);
        }