public MuTestOptions Build() { var muTestOptions = new MuTestOptions { TestSolution = GetOption(TestSolution.Value(), CliOptions.TestSolution), SourceClass = GetOption(SourceClass.Value(), CliOptions.SourceClass), SourceHeader = GetOption(SourceHeader.Value(), CliOptions.SourceHeader), TestProject = GetOption(TestProject.Value(), CliOptions.TestProject), TestClass = GetOption(TestClass.Value(), CliOptions.TestClass), EnableDiagnostics = GetOption(Diagnostics.Value(), CliOptions.EnableDiagnostics), ConcurrentTestRunners = GetOption(Parallel.Value(), CliOptions.Parallel), MutantsPerLine = GetOption(MutantsPerLine.Value(), CliOptions.MutantsPerLine), SurvivedThreshold = GetOption(SurvivedThreshold.Value(), CliOptions.SurvivedThreshold), KilledThreshold = GetOption(KilledThreshold.Value(), CliOptions.KilledThreshold), InIsolation = GetOption(InIsolation.Value(), CliOptions.InIsolation), DisableBuildOptimization = GetOption(DisableBuildOptimization.Value(), CliOptions.DisableBuildOptimization), IncludeBuildEvents = GetOption(IncludeBuildEvents.Value(), CliOptions.IncludeBuildEvents), OutputPath = GetOption(OutputPath.Value(), CliOptions.OutputPath), Configuration = GetOption(Configuration.Value(), CliOptions.BuildConfiguration), Platform = GetOption(Platform.Value(), CliOptions.Platform), SpecificLines = GetOption(SpecificLines.Value(), CliOptions.SpecificLineRange) }; muTestOptions.ValidateOptions(); return(muTestOptions); }
private void VerifySpecificLines() { if (!string.IsNullOrWhiteSpace(SpecificLines)) { const char separator = ':'; var range = SpecificLines.Split(separator); if (range.Length == 2) { var minValid = uint.TryParse(range[0], out var minimum); var maxValid = uint.TryParse(range[1], out var maximum); if (!minValid || !maxValid || maximum < minimum) { throw new MuTestInputException(ErrorMessage, $"Invalid Specific Line Range {CliOptions.SpecificLineRange.ArgumentDescription}"); } } } }
public void Mutate(string sourceFile) { Mutants = new Collection <CppMutant>(); if (sourceFile == null || !File.Exists(sourceFile)) { return; } var codeLines = File.ReadAllLines(sourceFile); var skipList = new List <string> { "//", "#", BlockOpen, BlockClosed, "};", "});", ")", "public:", "private:", "protected:", Extern, VoId, Using, Catch, Namespace, Typedef, Static, Class, Trace, Delete }; const char separator = ':'; var lineNumber = 0; string line; var insideCommentedCode = false; var id = 0; var minimum = -1; var maximum = int.MaxValue; if (!string.IsNullOrWhiteSpace(SpecificLines)) { var range = SpecificLines.Split(separator); minimum = Convert.ToInt32(range[0]); maximum = Convert.ToInt32(range[1]); } for (var lineIndex = 0; lineIndex < codeLines.Length; lineIndex++) { lineNumber++; line = codeLines[lineIndex].Trim(); if (lineNumber < minimum || lineNumber > maximum) { continue; } if (string.IsNullOrWhiteSpace(line) || skipList.Any(x => line.StartsWith(x, StringComparison.InvariantCultureIgnoreCase)) || line.EndsWith("):")) { continue; } if (line.StartsWith("/*") || line.EndsWith("/*")) { insideCommentedCode = true; } if (line.EndsWith("*/")) { insideCommentedCode = false; continue; } if (!insideCommentedCode) { var codeLine = new CodeLine { Line = line, LineNumber = lineNumber, EndLineNumber = lineNumber }; AddStringsInsideLines(line, codeLine); AddCommentsInsideLine(line, codeLine); AddIfBlocks(line, codeLine, lineIndex, codeLines); foreach (var mutator in Mutators) { var cppMutants = mutator.Mutate(codeLine).ToList(); foreach (var mutant in cppMutants) { mutant.Id = id++; mutant.Mutation.EndLineNumber = codeLine.EndLineNumber; Mutants.Add(mutant); } } } } }