public void RepeatingPathOption() { CommandLineUtilities.Option opt = default(CommandLineUtilities.Option); opt.Name = "Switch"; opt.Value = "test.dll"; Assert.True( CommandLineUtilities.ParseRepeatingPathOption(opt, ",").SequenceEqual( new string[] { Path.Combine(Directory.GetCurrentDirectory(), "test.dll") })); opt.Name = "Switch"; opt.Value = "test.dll,test2.dll"; Assert.True( CommandLineUtilities.ParseRepeatingPathOption(opt, ",").SequenceEqual( new string[] { Path.Combine(Directory.GetCurrentDirectory(), "test.dll"), Path.Combine(Directory.GetCurrentDirectory(), "test2.dll") })); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = null; CommandLineUtilities.ParseStringOption(opt); }); }
/// <inheritdoc /> public override bool HandleOption(CommandLineUtilities.Option opt) { if (string.Equals("pathFormat", opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals("p", opt.Name, StringComparison.OrdinalIgnoreCase)) { Slashes = CommandLineUtilities.ParseEnumOption <PathFixer.SlashType>(opt); switch (Slashes) { case PathFixer.SlashType.Default: case PathFixer.SlashType.Unix: case PathFixer.SlashType.Windows: break; default: throw Contract.AssertFailure("Unexpected enum value for SlashType"); } return(true); } if (string.Equals("lowerCaseDirectories", opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals("l", opt.Name, StringComparison.OrdinalIgnoreCase)) { LowerCaseDirectories = CommandLineUtilities.ParseBooleanOption(opt); return(true); } return(base.HandleOption(opt)); }
/// <inheritdoc /> public override bool HandleOption(CommandLineUtilities.Option opt) { if (string.Equals(OutputFolderOptionLong, opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals(OutputFolderOptionShort, opt.Name, StringComparison.OrdinalIgnoreCase)) { OutputFolder = CommandLineUtilities.ParsePathOption(opt); return(true); } if (string.Equals(RootLinkOptionLong, opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals(RootLinkOptionShort, opt.Name, StringComparison.OrdinalIgnoreCase)) { RootLink = CommandLineUtilities.ParseStringOption(opt); return(true); } if (string.Equals(CleanOutputOptionLong, opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals(CleanOutputOptionShort, opt.Name, StringComparison.OrdinalIgnoreCase)) { CleanOutputFolder = CommandLineUtilities.ParseBooleanOption(opt); return(true); } if (string.Equals(ModuleListOptionLong, opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals(ModuleListOptionShort, opt.Name, StringComparison.OrdinalIgnoreCase)) { ModuleList = new HashSet <string>(CommandLineUtilities.ParseStringOption(opt).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); return(true); } return(base.HandleOption(opt)); }
public void PathOption() { CommandLineUtilities.Option opt = default(CommandLineUtilities.Option); opt.Name = "Switch"; opt.Value = "test.dll"; Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), "test.dll"), CommandLineUtilities.ParsePathOption(opt)); // Paths may be wrapped in quotes opt.Value = "\"File With Spaces.dll\""; Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), "File With Spaces.dll"), CommandLineUtilities.ParsePathOption(opt)); if (!OperatingSystemHelper.IsUnixOS) { opt.Name = "Switch"; opt.Value = SpecialFolderUtilities.GetFolderPath(SpecialFolder.Windows); Assert.Equal(opt.Value, CommandLineUtilities.ParsePathOption(opt)); } Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = null; CommandLineUtilities.ParsePathOption(opt); }); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = string.Empty; CommandLineUtilities.ParsePathOption(opt); }); }
public void SingletonStringOption() { CommandLineUtilities.Option opt = default(CommandLineUtilities.Option); opt.Name = "Switch"; opt.Value = "Value"; Assert.Equal(opt.Value, CommandLineUtilities.ParseSingletonStringOption(opt, null)); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = null; CommandLineUtilities.ParseSingletonStringOption(opt, null); }); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = string.Empty; CommandLineUtilities.ParseSingletonStringOption(opt, null); }); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = "New"; CommandLineUtilities.ParseSingletonStringOption(opt, "Existing"); }); }
/// <inheritdoc /> public override bool HandleOption(CommandLineUtilities.Option opt) { if (m_outputFileOption.Match(opt.Name)) { m_outputFile = CommandLineUtilities.ParsePathOption(opt); return(true); } if (m_descriptionOption.Match(opt.Name)) { m_description = opt.Value; return(true); } if (m_alternateSymbolSeparatorOption.Match(opt.Name)) { var alternateSymbolSeparatorString = CommandLineUtilities.ParseStringOption(opt); m_alternateSymbolSeparator = alternateSymbolSeparatorString.Length != 0 ? alternateSymbolSeparatorString[0] : default; return(true); } if (m_topSortOption.Match(opt.Name)) { SerializeUsingTopSort = CommandLineUtilities.ParseBooleanOption(opt); return(true); } return(base.HandleOption(opt)); }
public void BooleanOption() { CommandLineUtilities.Option opt = default(CommandLineUtilities.Option); opt.Name = "Switch"; opt.Value = null; Assert.True(CommandLineUtilities.ParseBooleanOption(opt)); opt.Name = "Switch"; opt.Value = string.Empty; Assert.True(CommandLineUtilities.ParseBooleanOption(opt)); opt.Name = "Switch+"; opt.Value = null; Assert.True(CommandLineUtilities.ParseBooleanOption(opt)); opt.Name = "Switch+"; opt.Value = string.Empty; Assert.True(CommandLineUtilities.ParseBooleanOption(opt)); opt.Name = "Switch-"; opt.Value = null; Assert.False(CommandLineUtilities.ParseBooleanOption(opt)); opt.Name = "Switch-"; opt.Value = string.Empty; Assert.False(CommandLineUtilities.ParseBooleanOption(opt)); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch+"; opt.Value = "X"; CommandLineUtilities.ParseBooleanOption(opt); }); }
public void ReconstructArgumentWithNameAndValueWithSpaceAndQuote() { var result = new CommandLineUtilities.Option() { Name = "name", Value = "value value\"value" }.PrintCommandLineString(); Assert.Equal("/name:\"value value\\\"value\"", result); }
public void ReconstructArgumentWithJustName() { var result = new CommandLineUtilities.Option() { Name = "name" }.PrintCommandLineString(); Assert.Equal("/name", result); }
public override bool HandleOption(CommandLineUtilities.Option opt) { if (opt.Name.Equals("out", StringComparison.OrdinalIgnoreCase) || opt.Name.Equals("o", StringComparison.OrdinalIgnoreCase)) { m_outputDirectory = CommandLineUtilities.ParsePathOption(opt); return(true); } return(base.HandleOption(opt)); }
public void DblColSeparator() { CommandLineUtilities.Option option = default(CommandLineUtilities.Option); option.Name = "translateDirectory"; option.Value = m_helloTestPath + "::" + m_worldTestPath; TranslateDirectoryData tdd = Args.ParseTranslatePathOption(m_pathTable, option); XAssert.IsTrue(tdd.FromPath.ToString(m_pathTable).EndsWith(m_helloTestPath, StringComparison.OrdinalIgnoreCase)); XAssert.IsTrue(tdd.ToPath.ToString(m_pathTable).EndsWith(m_worldTestPath, StringComparison.OrdinalIgnoreCase)); }
public void LessThanSeparator() { CommandLineUtilities.Option option = default(CommandLineUtilities.Option); option.Name = "translateDirectory"; option.Value = m_helloTestPath + "<" + m_worldTestPath; TranslateDirectoryData tdd = Args.ParseTranslatePathOption(m_pathTable, option); XAssert.IsTrue(tdd.FromPath.ToString(m_pathTable).EndsWith(m_helloTestPath, OperatingSystemHelper.PathComparison)); XAssert.IsTrue(tdd.ToPath.ToString(m_pathTable).EndsWith(m_worldTestPath, OperatingSystemHelper.PathComparison)); }
/// <inheritdoc /> public override bool HandleOption(CommandLineUtilities.Option opt) { if (m_outputFileOption.Match(opt.Name)) { m_outputFile = CommandLineUtilities.ParsePathOption(opt); return(true); } if (m_descriptionOption.Match(opt.Name)) { m_description = opt.Value; return(true); } return(base.HandleOption(opt)); }
public void Int64Option() { CommandLineUtilities.Option opt = default(CommandLineUtilities.Option); opt.Name = "Switch"; opt.Value = "12"; Assert.Equal(12, CommandLineUtilities.ParseInt64Option(opt, 0, 100)); opt.Name = "Switch"; opt.Value = "0"; Assert.Equal(0, CommandLineUtilities.ParseInt64Option(opt, 0, 100)); opt.Name = "Switch"; opt.Value = "100"; Assert.Equal(100, CommandLineUtilities.ParseInt64Option(opt, 0, 100)); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = null; CommandLineUtilities.ParseInt64Option(opt, 0, 100); }); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = string.Empty; CommandLineUtilities.ParseInt64Option(opt, 0, 100); }); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = "-1"; CommandLineUtilities.ParseInt64Option(opt, 0, 100); }); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = "101"; CommandLineUtilities.ParseInt64Option(opt, 0, 100); }); }
public void VoidOption() { CommandLineUtilities.Option opt = default(CommandLineUtilities.Option); opt.Name = "Switch"; opt.Value = null; CommandLineUtilities.ParseVoidOption(opt); opt.Name = "Switch"; opt.Value = string.Empty; CommandLineUtilities.ParseVoidOption(opt); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = "X"; CommandLineUtilities.ParseVoidOption(opt); }); }
/// <inheritdoc /> public override bool HandleOption(CommandLineUtilities.Option opt) { if (string.Equals("specialAddIfFormatting", opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals("specialAddIfFormatting+", opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals("s", opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals("s+", opt.Name, StringComparison.OrdinalIgnoreCase)) { SpecialAddIfFormatting = true; return(true); } if (string.Equals("specialAddIfFormatting-", opt.Name, StringComparison.OrdinalIgnoreCase) || string.Equals("s-", opt.Name, StringComparison.OrdinalIgnoreCase)) { SpecialAddIfFormatting = false; return(true); } return(base.HandleOption(opt)); }
public void NoLessThanNoDblCol() { CommandLineUtilities.Option option = default(CommandLineUtilities.Option); option.Name = "translateDirectory"; option.Value = "Hello"; try { Args.ParseTranslatePathOption(m_pathTable, option); } catch (Exception e) { XAssert.AreEqual( "The value 'Hello' provided for the /translateDirectory argument is invalid. It should contain a '::' or '<' separator", e.GetLogEventMessage()); return; } XAssert.Fail("Should have gotten an exception."); }
public void Empty() { CommandLineUtilities.Option option = default(CommandLineUtilities.Option); option.Name = "translateDirectory"; option.Value = string.Empty; try { Args.ParseTranslatePathOption(m_pathTable, option); } catch (Exception e) { XAssert.AreEqual( "The value provided for the /translateDirectory argument is invalid.", e.GetLogEventMessage()); return; } XAssert.Fail("Should have gotten an exception."); }
public void InvalidTranslateTo() { CommandLineUtilities.Option option = default(CommandLineUtilities.Option); option.Name = "translateDirectory"; option.Value = m_helloTestPath + "<" + m_worldTestPath + "::" + m_bigTestPath; try { Args.ParseTranslatePathOption(m_pathTable, option); } catch (Exception e) { XAssert.AreEqual( "The value '" + m_worldTestPath + "::" + m_bigTestPath + "' provided for the /translateDirectory argument is invalid. It should have a valid translateTo path", e.GetLogEventMessage()); return; } if (!OperatingSystemHelper.IsUnixOS) { XAssert.Fail("Should have gotten an exception."); } }
public void SingletonPathOption() { CommandLineUtilities.Option opt = default(CommandLineUtilities.Option); opt.Name = "Switch"; opt.Value = "test.dll"; Assert.Equal(Path.Combine(Directory.GetCurrentDirectory(), "test.dll"), CommandLineUtilities.ParseSingletonPathOption(opt, null)); if (!OperatingSystemHelper.IsUnixOS) { opt.Name = "Switch"; opt.Value = SpecialFolderUtilities.GetFolderPath(SpecialFolder.Windows); Assert.Equal(opt.Value, CommandLineUtilities.ParseSingletonPathOption(opt, null)); } Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = null; CommandLineUtilities.ParseSingletonPathOption(opt, null); }); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = string.Empty; CommandLineUtilities.ParseSingletonPathOption(opt, null); }); Assert.Throws <InvalidArgumentException>(() => { opt.Name = "Switch"; opt.Value = "New"; CommandLineUtilities.ParseSingletonPathOption(opt, "Existing"); }); }
/// <summary> /// Handles a commandline option for the given analyzer /// </summary> public virtual bool HandleOption(CommandLineUtilities.Option opt) { return(false); }