public void ShouldParseCommandLineParametersWithColons() { var parser = new CommandLineParameterParser(); var parms = parser.ParseCommandLineParameters(new[] {"zero", @"/one:c:\two", "/three:4", "http://five"}); AssertArgumentsParsed(parms); }
public static void TestParameter_MTA_And_STA_Mutually_Exclusive(params string[] commandLine) { Skip.IfNot(Platform.IsWindows); var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal((uint)ConsoleHost.ExitCodeBadCommandLineParameter, cpp.ExitCode); Assert.Equal(CommandLineParameterParserStrings.MtaStaMutuallyExclusive, cpp.ErrorMessage); }
public static void TestParameter_MTA_Not_IsWindowsDesktop(params string[] commandLine) { Skip.If(Platform.IsWindowsDesktop); var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal((uint)ConsoleHost.ExitCodeBadCommandLineParameter, cpp.ExitCode); Assert.Equal(CommandLineParameterParserStrings.MTANotImplemented, cpp.ErrorMessage); }
public static void TestParameter_SettingsFile_Not_Exists(params string[] commandLine) { var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal((uint)ConsoleHost.ExitCodeBadCommandLineParameter, cpp.ExitCode); Assert.Equal( string.Format(CommandLineParameterParserStrings.SettingsFileNotExists, Path.GetFullPath("noexistfilename")), cpp.ErrorMessage); }
public static void TestDefaultParameterIsFileName_Not_Exist(params string[] commandLine) { var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.False(cpp.NoExit); Assert.True(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal(CommandLineParameterParser.NormalizeFilePath("noexistfilename"), cpp.File); Assert.Equal( string.Format(CommandLineParameterParserStrings.ArgumentFileDoesNotExist, "noexistfilename"), cpp.ErrorMessage); }
public static void TestParameter_InputFormat_With_Right_Value(params string[] commandLine) { var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.Equal(commandLine[1], cpp.InputFormat.ToString()); Assert.False(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.True(cpp.ShowBanner); Assert.Equal(Microsoft.PowerShell.Serialization.DataFormat.XML, cpp.InputFormat); Assert.Equal((uint)ConsoleHost.ExitCodeSuccess, cpp.ExitCode); Assert.Null(cpp.ErrorMessage); }
public static void TestParameter_WindowsStyle_With_Right_Value(params string[] commandLine) { Skip.IfNot(Platform.IsWindows); var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.False(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.True(cpp.ShowBanner); Assert.Equal((uint)ConsoleHost.ExitCodeSuccess, cpp.ExitCode); Assert.Null(cpp.ErrorMessage); }
public static void TestParameter_WindowsStyle_No_Value(params string[] commandLine) { Skip.IfNot(Platform.IsWindows); var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal((uint)ConsoleHost.ExitCodeBadCommandLineParameter, cpp.ExitCode); Assert.Equal(CommandLineParameterParserStrings.MissingWindowStyleArgument, cpp.ErrorMessage); }
public static void TestParameter_WorkingDirectory_RemoveTrailingCharacter(params string[] commandLine) { Skip.IfNot(Platform.IsWindows); var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.False(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.True(cpp.ShowBanner); Assert.Equal(commandLine[1].Remove(commandLine[1].Length - 1), cpp.WorkingDirectory); Assert.Null(cpp.ErrorMessage); }
public static void TestParameter_MTA(params string[] commandLine) { Skip.IfNot(Platform.IsWindows); var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.False(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.True(cpp.ShowBanner); Assert.False(cpp.StaMode); Assert.Null(cpp.ErrorMessage); }
public static void TestDefaultParameterIsFileName_Exist() { var fileName = System.IO.Path.GetTempFileName(); var cpp = new CommandLineParameterParser(); cpp.Parse(new string[] { fileName }); Assert.False(cpp.AbortStartup); Assert.False(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal(CommandLineParameterParser.NormalizeFilePath(fileName), cpp.File); Assert.Null(cpp.ErrorMessage); }
public static void TestDefaults() { var cpp = new CommandLineParameterParser(); cpp.Parse(System.Array.Empty <string>()); Assert.False(cpp.AbortStartup); Assert.Empty(cpp.Args); Assert.Null(cpp.ConfigurationName); Assert.Null(cpp.ConfigurationFile); Assert.Null(cpp.CustomPipeName); Assert.Null(cpp.ErrorMessage); Assert.Null(cpp.ExecutionPolicy); Assert.Equal((uint)ConsoleHost.ExitCodeSuccess, cpp.ExitCode); Assert.False(cpp.ExplicitReadCommandsFromStdin); Assert.Null(cpp.File); Assert.Null(cpp.InitialCommand); Assert.Equal(Microsoft.PowerShell.Serialization.DataFormat.Text, cpp.InputFormat); Assert.False(cpp.NamedPipeServerMode); Assert.True(cpp.NoExit); Assert.False(cpp.NonInteractive); Assert.False(cpp.NoPrompt); Assert.Equal(Microsoft.PowerShell.Serialization.DataFormat.Text, cpp.OutputFormat); Assert.False(cpp.OutputFormatSpecified); #if !UNIX Assert.False(cpp.RemoveWorkingDirectoryTrailingCharacter); #endif Assert.False(cpp.ServerMode); Assert.True(cpp.ShowBanner); Assert.False(cpp.ShowShortHelp); Assert.False(cpp.ShowVersion); Assert.False(cpp.SkipProfiles); Assert.False(cpp.SocketServerMode); Assert.False(cpp.SSHServerMode); if (Platform.IsWindows) { Assert.True(cpp.StaMode); } else { Assert.False(cpp.StaMode); } Assert.False(cpp.ThrowOnReadAndPrompt); Assert.False(cpp.WasInitialCommandEncoded); Assert.Null(cpp.WorkingDirectory); Assert.False(cpp.NonInteractive); }
public static void TestParameter_EncodedCommand_With_Dash_And_ConsoleInputRedirected(params string[] commandLine) { var cpp = new CommandLineParameterParser(); cpp.InputRedirectedTestHook = true; cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.True(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal((uint)ConsoleHost.ExitCodeBadCommandLineParameter, cpp.ExitCode); Assert.False(cpp.ExplicitReadCommandsFromStdin); Assert.Equal(CommandLineParameterParserStrings.BadCommandValue, cpp.ErrorMessage); }
public static void TestParameter_InputFormat_With_Wrong_Value(params string[] commandLine) { var index = CommandLineParameterParserStrings.BadFormatParameterValue.IndexOf('.'); var errorMessage = CommandLineParameterParserStrings.BadFormatParameterValue.Substring(0, index); var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.True(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal((uint)ConsoleHost.ExitCodeBadCommandLineParameter, cpp.ExitCode); Assert.Equal(errorMessage, cpp.ErrorMessage.Substring(0, index)); }
public static void TestParameter_Command_With_Dash_And_Not_ConsoleInputRedirected(params string[] commandLine) { var cpp = new CommandLineParameterParser(); cpp.InputRedirectedTestHook = false; cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.True(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.True(cpp.NoPrompt); Assert.True(cpp.ExplicitReadCommandsFromStdin); Assert.Equal(CommandLineParameterParserStrings.StdinNotRedirected, cpp.ErrorMessage); }
public static void TestParameter_Wrong_Dash_And_Slash(params string[] commandLine) { var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.False(cpp.NoExit); Assert.False(cpp.NonInteractive); Assert.False(cpp.ShowBanner); Assert.True(cpp.ShowShortHelp); Assert.False(cpp.NoPrompt); Assert.False(cpp.ShowVersion); Assert.False(cpp.SkipProfiles); Assert.Contains(commandLine[0], cpp.ErrorMessage); }
public static void TestParameter_CustomPipeName_With_Too_Long_Name(params string[] commandLine) { Skip.If(Platform.IsWindows); var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.True(cpp.AbortStartup); Assert.True(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); Assert.Equal((uint)ConsoleHost.ExitCodeBadCommandLineParameter, cpp.ExitCode); Assert.Equal( string.Format( CommandLineParameterParserStrings.CustomPipeNameTooLong, CommandLineParameterParser.MaxNameLength(), commandLine[1], commandLine[1].Length), cpp.ErrorMessage); }
public static void TestParameter_LastParameterIsFileName_Exist(params string[] commandLine) { var cpp = new CommandLineParameterParser(); cpp.Parse(commandLine); Assert.False(cpp.AbortStartup); Assert.False(cpp.NoExit); Assert.False(cpp.ShowShortHelp); Assert.False(cpp.ShowBanner); if (Platform.IsWindows) { Assert.True(cpp.StaMode); } else { Assert.False(cpp.StaMode); } Assert.Equal(CommandLineParameterParser.NormalizeFilePath(commandLine[commandLine.Length - 1]), cpp.File); Assert.Null(cpp.ErrorMessage); }
public ParsedCommandLineParameters ParseCommandLineArguments(string [] args) { var parser = new CommandLineParameterParser(); return parser.ParseCommandLineParameters(args); }
public static void Test_ARGS_With_Null(params string[] commandLine) { var cpp = new CommandLineParameterParser(); Assert.Throws <System.ArgumentNullException>(() => cpp.Parse(commandLine)); }