private static List<PatchEntryChanges> GetPossibleSpecs(PatchEntryChanges testablePatchEntryChange, List<PatchEntryChanges> specs) { var expectedSpecFilename = Path.GetFileNameWithoutExtension(testablePatchEntryChange.Path) + "Spec.cs"; var possibleSpecs = specs.Where(specPatchEntryChange => specPatchEntryChange.Path.EndsWith(expectedSpecFilename)).ToList(); return possibleSpecs; }
private static bool IsTested(PatchEntryChanges testablePatchEntryChange, List<PatchEntryChanges> possibleSpecs) { const string usingName = "usingName"; const string speccedTypeName = "speccedType"; const string usingRegex = @"using\s+(?<" + usingName + @">\S+)\;"; const string speccedTypeRegex = @"\s+Spec\<(?<" + speccedTypeName + @">\S+)\>"; var testableName = ExtractFullClassName(testablePatchEntryChange); foreach (var possibleSpec in possibleSpecs) { var content = File.ReadAllText(possibleSpec.Path); var usingNamespaces = Regex.Matches(content, usingRegex, RegexOptions.Singleline).Cast<Match>().Select(match => match.Groups).Select(group => group[usingName]).ToList(); var speccedType = Regex.Match(content, speccedTypeRegex, RegexOptions.Singleline).Groups[speccedTypeName]; if (usingNamespaces.Select(usingNamespace => usingNamespace + "." + speccedType).Any(fullySpeccedName => testableName == fullySpeccedName)) { return true; } } return false; }
public PatchEntry(int offset, int length, Patch patch, PatchEntryChanges changes, IReadOnlyList<PatchHunk> hunks) { Offset = offset; Length = length; Patch = patch; Changes = changes; Hunks = hunks; }
private static bool IsInterface(PatchEntryChanges patchEntryChanges) { const string interfaceRegex = @"\s+(internal|public)\s+interface\s+I.*"; var content = File.ReadAllText(patchEntryChanges.Path); var result = Regex.IsMatch(content, interfaceRegex); return result; }
private static string ExtractFullClassName(PatchEntryChanges patchEntryChanges) { const string namespaceName = "namespaceName"; const string className = "className"; const string fullNameRegex = @"namespace\s+(?<"+ namespaceName + @">\S*).*\sclass\s+(?<" + className + @">\S+)"; var content = File.ReadAllText(patchEntryChanges.Path); var match = Regex.Match(content, fullNameRegex, RegexOptions.Singleline); return match.Groups[namespaceName] + "." + match.Groups[className]; }
private Change BuildChange(PatchEntryChanges change) { var fileChange = new Change(); fileChange.Name = change.Path; switch (change.Status) { case ChangeKind.Added: fileChange.ChangeType = ChangeType.Added; break; case ChangeKind.Copied: fileChange.ChangeType =ChangeType.Copied; break; case ChangeKind.Deleted: fileChange.ChangeType =ChangeType.Deleted; break; case ChangeKind.Modified: fileChange.ChangeType =ChangeType.Modified; break; case ChangeKind.Renamed: fileChange.ChangeType =ChangeType.Renamed; break; case ChangeKind.TypeChanged: fileChange.ChangeType =ChangeType.TypeChanged; break; case ChangeKind.Unmodified: fileChange.ChangeType =ChangeType.Unmerged; break; } return fileChange; }
private static bool IsTestable(PatchEntryChanges patchEntryChanges) { return patchEntryChanges.Path.EndsWith(".cs") && !IsSkipped(patchEntryChanges) && !IsSpec(patchEntryChanges) && !IsInterface(patchEntryChanges); }
private static bool IsSpec(PatchEntryChanges patchEntryChanges) { return patchEntryChanges.Path.EndsWith("Spec.cs"); }
private static bool IsSkipped(PatchEntryChanges patchEntryChanges) { return SkipFileNames.Any(skipFileName => patchEntryChanges.Path.EndsWith(skipFileName)); }
private static bool HasValidChangeStatus(PatchEntryChanges patchEntryChanges) { return ValidChangeStatuses.Contains(patchEntryChanges.Status); }
private string GetOldContent(PatchEntryChanges fileChanges) { return Repository.Lookup<Blob>(fileChanges.OldOid)?.GetContentText() ?? ""; }