private static IFilter BuildFilter(CommandLineParser parser) { var filter = new Filter(); // apply filters if (!parser.NoDefaultFilters) { filter.AddFilter("-[mscorlib]*"); filter.AddFilter("-[mscorlib.*]*"); filter.AddFilter("-[System]*"); filter.AddFilter("-[System.*]*"); filter.AddFilter("-[Microsoft.VisualBasic]*"); } if (parser.Filters.Count == 0) { filter.AddFilter("+[*]*"); } else { parser.Filters.ForEach(filter.AddFilter); } filter.AddAttributeExclusionFilters(parser.AttributeExclusionFilters.ToArray()); filter.AddFileExclusionFilters(parser.FileExclusionFilters.ToArray()); filter.AddTestFileFilters(parser.TestFilters.ToArray()); return filter; }
public void ThrowsExceptionWhenArgumentUnrecognised() { // arrange var parser = new CommandLineParser(new[]{"-bork"}); // act Assert.Throws<InvalidOperationException>(parser.ExtractAndValidateArguments); // assert }
public void ExtractsHideSkipped_DefaultsToAll() { // arrange var parser = new CommandLineParser(new[] { "-hideskipped", RequiredArgs }); parser.ExtractAndValidateArguments(); // assert Assert.AreEqual(5, parser.HideSkipped.Distinct().Count()); }
public void Detects_EnablePerformanceCounters_Argument() { // arrange var parser = new CommandLineParser(new[] { "-enableperformancecounters", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.IsTrue(parser.EnablePerformanceCounters); }
public void DetectsServiceArgument() { // arrange var parser = new CommandLineParser(new[] { "-service", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.IsTrue(parser.Service); }
public void HandlesFilterArgument() { // arrange var parser = new CommandLineParser(new[]{"-filter:XYZ ABC", RequiredArgs}); // act parser.ExtractAndValidateArguments(); // assert Assert.AreEqual(2, parser.Filters.Count); }
public void HandlesNoDefaultFiltersArgument() { // arrange var parser = new CommandLineParser(new[]{"-nodefaultfilters" , RequiredArgs}); // act parser.ExtractAndValidateArguments(); // assert Assert.IsTrue(parser.NoDefaultFilters); }
public void DetectsOldStyleArgument() { // arrange var parser = new CommandLineParser(new[] { "-oldstyle", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.IsTrue(parser.OldStyleInstrumentation); }
public void HandlesReturnTargetCodeArgument() { // arrange var parser = new CommandLineParser(new[] { "-returntargetcode", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.IsTrue(parser.ReturnTargetCode); }
public void HandlesAnInvalidTypeArgument() { // arrange var parser = new CommandLineParser(new[]{"-type:method,boris" , RequiredArgs}); // act var ex = Assert.Catch<Exception>(parser.ExtractAndValidateArguments); // assert Assert.IsNotNull(ex); }
public void HandlesMergeByHashArgument() { // arrange var parser = new CommandLineParser(new[] { "-mergebyhash", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.IsTrue(parser.MergeByHash); }
public void HandlesTheRegisterArgumentWithPath32Value() { // arrange var parser = new CommandLineParser(new[] { "-register:path32", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.IsTrue(parser.Register); Assert.AreEqual(Registration.Path32, parser.Registration); }
public void HandlesExcludeByAttributeArgument_WithValue() { // arrange var parser = new CommandLineParser(new[] { "-excludebyattribute:wibble", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.AreEqual(1, parser.AttributeExclusionFilters.Count); Assert.AreEqual("wibble", parser.AttributeExclusionFilters[0]); }
private static IPerfCounters CreatePerformanceCounter(CommandLineParser parser) { if (parser.EnablePerformanceCounters) { if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { return new PerfCounters(); } Logger.Error("You must be running as an Administrator to enable performance counters."); throw new ExitApplicationWithoutReportingException(); } return new NullPerfCounter(); }
public void HandlesCoverByTestArgument_WithMultipleValues() { // arrange var parser = new CommandLineParser(new[] { "-coverbytest:wibble;wobble;woop", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.AreEqual(3, parser.TestFilters.Count); Assert.AreEqual("wibble", parser.TestFilters[0]); Assert.AreEqual("wobble", parser.TestFilters[1]); Assert.AreEqual("woop", parser.TestFilters[2]); }
public void ExtractsHideSkipped_Handles_Multiple_Arg() { // arrange var parser = new CommandLineParser(new[] { "-hideskipped:File;Filter;MissingPdb;Attribute", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.AreEqual(4, parser.HideSkipped.Distinct().Count()); Assert.AreEqual(SkippedMethod.File, parser.HideSkipped[0]); Assert.AreEqual(SkippedMethod.Filter, parser.HideSkipped[1]); Assert.AreEqual(SkippedMethod.MissingPdb, parser.HideSkipped[2]); Assert.AreEqual(SkippedMethod.Attribute, parser.HideSkipped[3]); }
private static IPerfCounters CreatePerformanceCounter(CommandLineParser parser) { if (parser.EnablePerformanceCounters) { if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) { return new PerfCounters(); } else { throw new InvalidCredentialException( "You must be running as an Administrator to enable performance counters."); } } else { return new NullPerfCounter(); } }
private static IFilter BuildFilter(CommandLineParser parser) { var filter = new Filter(); // apply filters if (!parser.NoDefaultFilters) { filter.AddFilter("-[mscorlib]*"); filter.AddFilter("-[mscorlib.*]*"); filter.AddFilter("-[System]*"); filter.AddFilter("-[System.*]*"); filter.AddFilter("-[Microsoft.VisualBasic]*"); } if (parser.Filters.Count == 0 && string.IsNullOrEmpty(parser.FilterFile)) { filter.AddFilter("+[*]*"); } else { if (!string.IsNullOrEmpty(parser.FilterFile)) { if (!File.Exists(parser.FilterFile)) System.Console.WriteLine("FilterFile '{0}' cannot be found - have you specified your arguments correctly?", parser.FilterFile); else { var filters = File.ReadAllLines(parser.FilterFile); filters.ToList().ForEach(filter.AddFilter); } } if (parser.Filters.Count > 0) { parser.Filters.ForEach(filter.AddFilter); } } filter.AddAttributeExclusionFilters(parser.AttributeExclusionFilters.ToArray()); filter.AddFileExclusionFilters(parser.FileExclusionFilters.ToArray()); filter.AddTestFileFilters(parser.TestFilters.ToArray()); return filter; }
private static IFilter BuildFilter(CommandLineParser parser) { var filter = Filter.BuildFilter(parser); if (!string.IsNullOrWhiteSpace(parser.FilterFile)) { if (!File.Exists(parser.FilterFile.Trim())) System.Console.WriteLine("FilterFile '{0}' cannot be found - have you specified your arguments correctly?", parser.FilterFile); else { var filters = File.ReadAllLines(parser.FilterFile); filters.ToList().ForEach(filter.AddFilter); } } else { if (parser.Filters.Count == 0) filter.AddFilter("+[*]*"); } return filter; }
public void ParserHasKnownDefaultArguments() { // arrange // act var parser = new CommandLineParser(new[]{string.Empty}); // assert Assert.IsFalse(parser.Register); Assert.AreEqual(Registration.Normal, parser.Registration); Assert.IsFalse(parser.NoDefaultFilters); Assert.IsFalse(parser.Service); Assert.IsFalse(parser.ShowUnvisited); Assert.IsFalse(parser.MergeByHash); Assert.IsFalse(parser.EnablePerformanceCounters); Assert.IsFalse(parser.TraceByTest); Assert.IsFalse(parser.SkipAutoImplementedProperties); Assert.IsFalse(parser.RegExFilters); Assert.IsFalse(parser.PrintVersion); Assert.AreEqual(new TimeSpan(0, 0, 30), parser.ServiceStartTimeout); }
private static Filter BuildFilter(CommandLineParser parser) { var filter = new Filter(); // apply filters if (!parser.NoDefaultFilters) { filter.AddFilter("-[mscorlib]*"); filter.AddFilter("-[System]*"); filter.AddFilter("-[System.*]*"); filter.AddFilter("-[Microsoft.VisualBasic]*"); } if (parser.Filters.Count == 0) { filter.AddFilter("+[*]*"); } else { parser.Filters.ForEach(filter.AddFilter); } return filter; }
private static bool GetFullOutputFile(CommandLineParser parser, out string outputFile) { outputFile = Path.Combine(Environment.CurrentDirectory, Environment.ExpandEnvironmentVariables(parser.OutputFile)); if (!Directory.Exists(Path.GetDirectoryName(outputFile))) { System.Console.WriteLine( "Output folder does not exist; please create it and make sure appropriate permissions are set."); return true; } return false; }
private static bool ParseCommandLine(string[] args, out CommandLineParser parser) { try { parser = new CommandLineParser(args); } catch (Exception) { throw new InvalidOperationException( "An error occurred whilst parsing the command line; try /? for command line arguments."); } try { parser.ExtractAndValidateArguments(); if (parser.PrintUsage) { System.Console.WriteLine(parser.Usage()); return true; } if (!File.Exists(Environment.ExpandEnvironmentVariables(parser.Target))) { System.Console.WriteLine("Target {0} cannot be found - have you specified your arguments correctly?"); return true; } } catch (Exception ex) { System.Console.WriteLine("Incorrect Arguments: {0}", ex.Message); System.Console.WriteLine(parser.Usage()); return true; } return false; }
public void InvalidThresholdArgumentValue_ThrowsException() { // arrange var parser = new CommandLineParser(new[] { "-threshold:wibble", RequiredArgs }); // assert Assert.Throws<InvalidOperationException>(parser.ExtractAndValidateArguments); }
public void HandlesTheTargetArgsArgumentWithSuppliedValueWithMultipleTimes() { // arrange var parser = new CommandLineParser(new[] { "-targetargs:XXX", "-targetargs:YYY", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.AreEqual("XXX YYY", parser.TargetArgs); }
public void InvalidReturnTargetCodeArgumentValue_ThrowsException() { // arrange var parser = new CommandLineParser(new[] { "-returntargetcode:wibble", RequiredArgs }); // act, assert Assert.Throws<InvalidOperationException>(parser.ExtractAndValidateArguments); }
public void HandlesThresholdArgument_WithValue() { // arrange var parser = new CommandLineParser(new[] { "-threshold:127", RequiredArgs }); // act parser.ExtractAndValidateArguments(); // assert Assert.AreEqual(127, parser.Threshold); }
public void HandlesTheUsageArgument() { // arrange var parser = new CommandLineParser(new[]{"-?"}); // act parser.ExtractAndValidateArguments(); // assert Assert.AreEqual(true, parser.PrintUsage); Assert.IsFalse(string.IsNullOrWhiteSpace(parser.Usage())); }
public void HandlesTheTargetDirArgumentWithSuppliedValue() { // arrange var parser = new CommandLineParser(new[]{"-targetdir:XXX" , RequiredArgs}); // act parser.ExtractAndValidateArguments(); // assert Assert.AreEqual("XXX", parser.TargetDir); }
public void HandlesTheTargetArgumentThrowsExceptionWithMissingValue() { // arrange var parser = new CommandLineParser(new[]{"-target"}); // act var ex = Assert.Catch<Exception>(parser.ExtractAndValidateArguments); // assert Assert.IsNotNull(ex); }