예제 #1
0
        public async Task <ICoverageAnalysisResult> AnalyseCoverage(Config config)
        {
            var memberIdsToNames = new Dictionary <string, string>();

            var baseTempDirectory = TempDirectory.Create();

            long memberId = 0;

            long GenerateMemberId() => ++ memberId;

            try
            {
                var copiedTestAssemblyFilePaths =
                    CopyTestAssembliesToTempDirectories(
                        config.TestAssemblyFilePaths,
                        baseTempDirectory)
                    .ToList();

                using (var workspace = MSBuildWorkspaceFactory.Create())
                {
                    var solution = await workspace.OpenSolutionAsync(config.SolutionFilePath);

                    await InstrumentThenCompileMultipleProjects(
                        solution.Projects.Where(p => Filtering.ShouldMutateProject(p, config)),
                        config,
                        baseTempDirectory,
                        copiedTestAssemblyFilePaths,
                        GenerateMemberId,
                        memberIdsToNames);

                    var result = new CoverageAnalysisResult();

                    for (int testAssemblyIndex = 0; testAssemblyIndex < config.TestAssemblyFilePaths.Length; ++testAssemblyIndex)
                    {
                        var copiedTestAssemblyFilePath = copiedTestAssemblyFilePaths[testAssemblyIndex];

                        var numTests = testFinder.FindTests(new[] { copiedTestAssemblyFilePath }).Length;

                        var runResult = testRunner.RunAllTestsAndAnalyseCoverage(
                            testAssemblyFilePaths: new [] { copiedTestAssemblyFilePath },
                            memberIdsToNames: memberIdsToNames,
                            onAnalysingTestCase: (test, index) => eventListener.BeginCoverageAnalysisOfTestCase(test, index, numTests));

                        if (runResult.Status != TestRunStatus.AllTestsPassed)
                        {
                            return(CoverageAnalysisResult.Error(runResult.Error));
                        }

                        var originalTestAssemblyFilePath = config.TestAssemblyFilePaths[testAssemblyIndex];
                        result = result.WithCoveredMembers(runResult.MembersAndCoveringTests, originalTestAssemblyFilePath);
                    }

                    return(result);
                }
            }
            finally
            {
                Directory.Delete(baseTempDirectory, recursive: true);
            }
        }
예제 #2
0
파일: Config.cs 프로젝트: tiggerite/fettle
        public async Task <Document[]> FindMutatableDocuments()
        {
            using (var workspace = MSBuildWorkspaceFactory.Create())
            {
                var solution = await workspace.OpenSolutionAsync(SolutionFilePath);

                return(solution.MutatableClasses(this));
            }
        }