public void SetUp() { _fileSystem = new MockFileSystem(); _config = ConfigCreator.CreateConfig(_fileSystem); _dependency = new TestRunnerDependencyFilesHandler(_fileSystem); _mutationDocument = new MutationDocumentCreator().CreateMutations(_config).First(); }
public void LogBeforeMutation(MutationDocument mutationDocument) { foreach (var mutationRunLogger in _mutationRunLoggers) { mutationRunLogger.LogBeforeMutation(mutationDocument); } }
public void LogAfterMutation(MutationDocument mutationDocument, List <MutationDocumentResult> results, int mutationsRemainingCount) { foreach (var mutationRunLogger in _mutationRunLoggers) { mutationRunLogger.LogAfterMutation(mutationDocument, results, mutationsRemainingCount); } }
public MutationDocumentDetailsView(MutationDocument document, UnimaConfig config) { InitializeComponent(); var dataContext = DataContext as MutationDocumentDetailsViewModel; dataContext.Initialize(document, config); }
public void Initialize(MutationDocument document, UnimaConfig config) { _config = config; _document = document; FileName = document.FileName; Title = $"{document.FileName} - {document.MutationDetails.Location})"; ShowFullCode(false); }
public void LogAfterMutation(MutationDocument mutationDocument, List <MutationDocumentResult> results, int mutationsRemainingCount) { var survived = results.Count(r => r.Survived && (r.CompilationResult != null && r.CompilationResult.IsSuccess) && r.UnexpectedError == null); var killed = results.Count(r => !r.Survived && (r.CompilationResult != null && r.CompilationResult.IsSuccess) && r.UnexpectedError == null); var compileErrors = results.Count(r => r.CompilationResult != null && !r.CompilationResult.IsSuccess); var unknownErrors = results.Count(r => r.UnexpectedError != null); Log.Info($"Current progress: {{ Survived: {survived}, Killed: {killed}, CompileErrors: {compileErrors}, UnknownErrors: {unknownErrors}, MutationsLeft: {mutationsRemainingCount} }}"); }
private void MutationDocumentStarted(MutationDocument mutationDocument) { var testRunDocument = RunningDocuments.FirstOrDefault(r => r.Document == mutationDocument); if (testRunDocument != null) { MutationsInQueueCount--; testRunDocument.Status = TestRunDocument.TestRunStatusEnum.Running; } }
public void MutationDocumentStarted(MutationDocument mutationDocument) { _environmentService.JoinableTaskFactory.RunAsync(async() => { await _environmentService.JoinableTaskFactory.SwitchToMainThreadAsync(); var testRunDocument = _mutations.FirstOrDefault(r => r.Document == mutationDocument); if (testRunDocument != null) { testRunDocument.Status = MutationRunItem.TestRunStatusEnum.Running; testRunDocument.InfoText = "Running.."; } }); }
private static bool ShouldIgnoreTestProject(MutationDocument mutationDocument, IList <MutationProject> mutationProjects, TestProject testProject) { var mutationProject = mutationProjects.FirstOrDefault(m => m.Project.Name == mutationDocument.ProjectName); if (mutationProject?.MappedTestProjects != null && mutationProject.MappedTestProjects.Any()) { if (mutationProject.MappedTestProjects.All(m => m != testProject.Project.Name)) { Log.Info($"Skipping tests in the the test project \"{testProject.Project.Name}\" as " + $"it didn't match the mapping list"); return(true); } } return(false); }
public async Task <CompilationResult> CompileAsync(string path, MutationDocument document) { Log.Info($"Compiling mutation {document.MutationName} to {path}"); var mutatedDocument = await document.CreateMutatedDocumentAsync(); var compilation = await mutatedDocument.Project.GetCompilationAsync(); var result = EmitCompilation(path, mutatedDocument.Project.AssemblyName, mutatedDocument.Project.FilePath, compilation); if (result.IsSuccess) { Log.Info($"Compiled {document.MutationName} successfully."); } else { var errors = result.Errors.Select(e => new { Location = e.Location, Message = e.Message }); Log.Info($"Failed to Compile {document.MutationName}: {JObject.FromObject(new { orginal = document.MutationDetails.Original.ToString(), mutation = document.MutationDetails.Mutation.ToString(), errors })}"); } return(result); }
public async Task <MutationDocumentResult> ExecuteMutationAsync( MutationConfig config, MutationDocument mutationDocument, CancellationToken cancellationToken = default(CancellationToken)) { var mutationResult = new MutationDocumentResult { Id = mutationDocument.Id, MutationName = mutationDocument.MutationName, ProjectName = mutationDocument.ProjectName, FileName = mutationDocument.FileName, Location = mutationDocument.MutationDetails.Location, Orginal = mutationDocument.MutationDetails.Original.ToFullString(), FullOrginal = mutationDocument.MutationDetails.FullOriginal.ToFullString(), Mutation = mutationDocument.MutationDetails.Mutation.ToFullString(), FullMutation = mutationDocument.MutationDetails.FullMutation.ToFullString(), Category = mutationDocument.MutationDetails.Category }; mutationResult.GenerateHash(); Log.Info($"Running mutation: \"{mutationDocument.MutationName}\""); var results = new List <TestSuiteResult>(); // Create the temporary "head" mutation directory to run all tests var mutationDirectoryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestRun", mutationDocument.Id.ToString()); // Where we should save our compiled mutation var mutationDllPath = Path.Combine(mutationDirectoryPath, $"{config.MutationProjects.FirstOrDefault(m => m.Project.Name == mutationDocument.ProjectName).Project.OutputFileName}"); _fileSystem.Directory.DeleteDirectoryAndCheckForException(mutationDirectoryPath); try { cancellationToken.ThrowIfCancellationRequested(); _fileSystem.Directory.CreateDirectory(mutationDirectoryPath); mutationResult.CompilationResult = await _compiler.CompileAsync(mutationDllPath, mutationDocument); if (!mutationResult.CompilationResult.IsSuccess) { return(mutationResult); } foreach (var testProject in config.TestProjects) { cancellationToken.ThrowIfCancellationRequested(); if (ShouldIgnoreTestProject(mutationDocument, config.MutationProjects, testProject)) { continue; } var baseline = config.BaselineInfos.FirstOrDefault(b => b.TestProjectName.Equals(testProject.Project.Name, StringComparison.OrdinalIgnoreCase)); var result = await RunTestAsync( testProject, mutationDirectoryPath, mutationDllPath, config.DotNetPath, baseline?.GetTestProjectTimeout() ?? TimeSpan.FromMinutes(config.MaxTestTimeMin), cancellationToken); results.Add(result); if (results.Any(r => !r.IsSuccess)) { break; } } var final = CombineResult(mutationDocument.FileName, results); if (final.TestResults.Count == 0) { throw new MutationDocumentException($"Unknown error when running, we should not have 0 tests. Also make sure that you don't have bad project mapping. Error: \"{final.Name}\""); } Log.Info($"\"{mutationDocument.MutationName}\" done. Ran {final.TestResults.Count} tests and {final.TestResults.Count(t => !t.IsSuccess)} failed."); mutationResult.FailedTests = final.TestResults.Where(t => !t.IsSuccess).ToList(); mutationResult.TestsRunCount = final.TestResults.Count; } catch (OperationCanceledException) { Log.Info("Cancellation requested (single mutation)"); mutationResult.UnexpectedError = "Mutation cancelled"; } catch (Exception) { throw; } finally { _fileSystem.Directory.DeleteDirectoryAndCheckForException(mutationDirectoryPath); } return(mutationResult); }
public async Task <MutationDocumentResult> ExecuteMutationAsync(UnimaConfig config, MutationDocument mutationDocument) { var mutationResult = new MutationDocumentResult { Id = mutationDocument.Id, MutationName = mutationDocument.MutationName, ProjectName = mutationDocument.ProjectName, FileName = mutationDocument.FileName, Location = mutationDocument.MutationDetails.Location, Orginal = mutationDocument.MutationDetails.Orginal.ToFullString(), FullOrginal = mutationDocument.MutationDetails.FullOrginal.ToFullString(), Mutation = mutationDocument.MutationDetails.Mutation.ToFullString(), FullMutation = mutationDocument.MutationDetails.FullMutation.ToFullString() }; mutationResult.GenerateHash(); LogTo.Info($"Running mutation: \"{mutationDocument.MutationName}\""); var results = new List <TestSuiteResult>(); // Create the temporary "head" mutation directory to run all tests var mutationDirectoryPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "TestRun", mutationDocument.Id.ToString()); // Where we should save our compiled mutation var mutationDllPath = Path.Combine(mutationDirectoryPath, $"{config.MutationProjects.FirstOrDefault(m => m.Name == mutationDocument.ProjectName).OutputFileName}"); Directory.CreateDirectory(mutationDirectoryPath); mutationResult.CompilationResult = await _compiler.CompileAsync(mutationDllPath, mutationDocument); if (!mutationResult.CompilationResult.IsSuccess) { return(mutationResult); } foreach (var testProject in config.TestProjects) { var baseline = config.BaselineInfos.FirstOrDefault(b => b.TestProjectName.Equals(testProject.Project.Name, StringComparison.OrdinalIgnoreCase)); var result = await RunTestAsync(testProject, mutationDirectoryPath, mutationDllPath, config.DotNetPath, baseline?.GetTestProjectTimeout() ?? TimeSpan.FromMinutes(config.MaxTestTimeMin)); results.Add(result); if (results.Any(r => !r.IsSuccess)) { break; } } try { Directory.Delete(mutationDirectoryPath, true); } catch (Exception ex) { LogTo.Error($"Failed to delete test directory: {ex.Message}"); } var final = CombineResult(mutationDocument.FileName, results); LogTo.Info($"\"{mutationDocument.MutationName}\" done. Ran {final.TestResults.Count} tests and {final.TestResults.Count(t => !t.IsSuccess)} failed."); mutationResult.FailedTests = final.TestResults.Where(t => !t.IsSuccess).ToList(); mutationResult.TestsRunCount = final.TestResults.Count; return(mutationResult); }
public void LogBeforeMutation(MutationDocument mutationDocument) { throw new NotImplementedException(); }
public Task <CompilationResult> CompileAsync(string path, MutationDocument document) { _fileSystem.File.AppendAllText(path, "test"); return(Task.FromResult(_compilationResult)); }
public void LogAfterMutation(MutationDocument mutationDocument, List <MutationDocumentResult> results, int mutationsRemainingCount) { throw new NotImplementedException(); }
private int GetDocumentLine(MutationDocument mutationDocument) { var line = mutationDocument.MutationDetails.Location.Line.Split(new[] { "@(", ":" }, StringSplitOptions.RemoveEmptyEntries).First(); return(int.Parse(line)); }
public void LogBeforeMutation(MutationDocument mutationDocument) { }
private void MutationSelected(MutationDocument obj) { _tabOpener.OpenDocumentDetailsTab(obj, _config); }
public void OpenDocumentDetailsTab(MutationDocument document, UnimaConfig config) { _mainTabContainer.AddTab(new MutationDocumentDetailsView(document, config)); }
public void LogAfterMutation(MutationDocument mutationDocument, List <MutationDocumentResult> results, int mutationsRemainingCount) { LogProgress(mutationsRemainingCount); }
public ExecuteMutationCommand(UnimaConfig config, MutationDocument mutation) { Config = config; Mutation = mutation; }