private async Task GetFromDB(string hash) { var data = await _client.GetFileDataFromStorage(hash); if (data != null) { _source = JsonConvert.DeserializeObject <SourceClassDetail>(data); _source.StoreToDb = false; } }
public async Task RunMutationTest(MuTestOptions options) { try { if (!File.Exists(MuTestSettings.MSBuildPath)) { throw new MuTestInputException($"Unable to locate MSBuild Path at {MuTestSettings.MSBuildPath}. Please update MSBuildPath in MuTest.Console.exe.config if you are using different version"); } _stopwatch = new Stopwatch(); _stopwatch.Start(); _options = options; _chalk.Default("\nPreparing Required Files...\n"); DirectoryFactory.NumberOfMutantsExecutingInParallel = _options.ConcurrentTestRunners; _cppClass = new CppClass { Configuration = _options.Configuration, SourceClass = _options.SourceClass, Platform = _options.Platform, TestClass = _options.TestClass, TestProject = _options.TestProject, Target = _options.Target, SourceHeader = _options.SourceHeader, TestSolution = _options.TestSolution, IncludeBuildEvents = _options.IncludeBuildEvents }; Context = !_options.InIsolation ? DirectoryFactory.PrepareTestFiles(_cppClass) : DirectoryFactory.PrepareSolutionFiles(_cppClass); if (Context.TestContexts.Any()) { await ExecuteBuild(); await ExecuteTests(); if (!_options.DisableBuildOptimization) { Context.EnableBuildOptimization = true; } _chalk.Default("\nRunning Mutation Analysis...\n"); var defaultMutants = CppMutantOrchestrator.GetDefaultMutants(_options.SourceClass, _options.SpecificLines).ToList(); defaultMutants = _aridNodeMutantFilterer.FilterMutants(defaultMutants).ToList(); defaultMutants = _mutantsSelector.SelectMutants(_options.MutantsPerLine, defaultMutants).ToList(); _cppClass.Mutants.AddRange(defaultMutants); if (_cppClass.CoveredLineNumbers.Any()) { foreach (var mutant in _cppClass.Mutants) { if (_cppClass.CoveredLineNumbers.All(x => x != mutant.Mutation.LineNumber)) { mutant.ResultStatus = MutantStatus.NotCovered; } else if (mutant.Mutation.EndLineNumber > mutant.Mutation.LineNumber) { if (!_cppClass.CoveredLineNumbers.Any(x => x > mutant.Mutation.LineNumber && x <= mutant.Mutation.EndLineNumber)) { mutant.ResultStatus = MutantStatus.Skipped; } } } } _chalk.Default($"\nNumber of Mutants: {_cppClass.Mutants.Count}\n"); var sourceHash = _cppClass .SourceClass .GetCodeFileContent() .ComputeHash(); var testHash = _cppClass .TestClass .GetCodeFileContent() .ComputeHash(); _cppClass.Sha256 = (sourceHash + testHash).ComputeHash(); var data = await _client.GetFileDataFromStorage(_cppClass.Sha256); _cppClass.StoreInDb = true; if (data != null) { var cppClass = JsonConvert.DeserializeObject <CppClass>(data); cppClass.StoreInDb = false; cppClass.SourceClass = _cppClass.SourceClass; cppClass.SourceHeader = _cppClass.SourceHeader; cppClass.TestClass = _cppClass.TestClass; cppClass.TestProject = _cppClass.TestProject; cppClass.Configuration = _cppClass.Configuration; cppClass.Target = _cppClass.Target; cppClass.Platform = _cppClass.Platform; cppClass.TestSolution = _cppClass.TestSolution; cppClass.IncludeBuildEvents = _cppClass.IncludeBuildEvents; _cppClass = cppClass; } MutantsExecutor = new CppMutantExecutor(_cppClass, Context, MuTestSettings) { EnableDiagnostics = _options.EnableDiagnostics, KilledThreshold = _options.KilledThreshold, SurvivedThreshold = _options.SurvivedThreshold, NumberOfMutantsExecutingInParallel = _options.ConcurrentTestRunners }; _totalMutants = _cppClass.NotRunMutants.Count; _mutantProgress = 0; if (_cppClass.Mutants.Any() && data == null) { MutantsExecutor.MutantExecuted += MutantAnalyzerOnMutantExecuted; await MutantsExecutor.ExecuteMutants(); } await GenerateReports(); } } finally { if (Context != null) { DirectoryFactory.DeleteTestFiles(Context); } } }