public void Can_Parse_Help(string input, bool expected) { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); // When var result = parser.Parse(new[] { "build.cake", input }); // Then Assert.Equal(expected, result.ShowHelp); }
public void Should_Throw_If_Arguments_Are_Null() { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); // When var result = Record.Exception(() => parser.Parse(null)); // Then AssertEx.IsArgumentNullException(result, "args"); }
public void Can_Parse_Verbosity(string input, Verbosity value) { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); // When var result = parser.Parse(new[] { "build.cake", input }); // Then Assert.Equal(value, result.Verbosity); }
public void Should_Add_Unknown_Arguments_To_Argument_List() { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); // When var result = parser.Parse(new[] { "build.cake", "-unknown" }); // Then Assert.True(result.Arguments.ContainsKey("unknown")); }
public void Can_Parse_Empty_Parameters() { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); // When var result = parser.Parse(new string[] { }); // Then Assert.NotNull(result); }
public void Should_Throw_If_Parsing_Invalid_Verbosity(string verbosity, string expected) { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); // When var result = parser.Parse(new[] { "build.csx", verbosity }); // Then Assert.True(result.HasError); Assert.True(fixture.Log.Entries.Any(e => e.Message == expected)); }
public void Should_Return_Error_If_Multiple_Arguments_With_The_Same_Name_Exist() { // Given var fixture = new ArgumentParserFixture {Log = new FakeLog()}; var parser = new ArgumentParser(fixture.Log, fixture.FileSystem); // When var result = parser.Parse(new[] { "build.csx", "-unknown", "-unknown" }); // Then Assert.Null(result); Assert.True(fixture.Log.Messages.Contains("Multiple arguments with the same name (unknown).")); }
public void Should_Throw_If_Multiple_Build_Configurations_Are_Provided() { // Given var fixture = new ArgumentParserFixture { Log = new FakeLog() }; var parser = new ArgumentParser(fixture.Log, fixture.FileSystem); var arguments = new[] { "build1.config", "build2.config" }; // When parser.Parse(arguments); // Then Assert.Equal("More than one build script specified.", fixture.Log.Messages[0]); }
public void Can_Parse_Script(string input) { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.FileSystem); var arguments = input.Split(new[] { ' ' }, StringSplitOptions.None); // When var result = parser.Parse(arguments); // Then Assert.NotNull(result.Script); Assert.Equal("build.csx", result.Script.FullPath); }
public void Should_Throw_If_Parsing_Invalid_Verbosity(string verbosity, string expected) { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.FileSystem); // When var result = Record.Exception(() => { parser.Parse(new[] { "build.csx", verbosity }); }); // Then Assert.IsExceptionWithMessage <InvalidOperationException>(result, expected); }
public void Can_Parse_Script_With_Unix_Path(string input) { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); var arguments = input.Split(new[] { ' ' }, StringSplitOptions.None); // When var result = parser.Parse(arguments); // Then Assert.NotNull(result); Assert.NotNull(result.Script); Assert.Equal("/home/test/build.csx", result.Script.FullPath); }
public void Should_Add_Unknown_Arguments_To_Argument_List_Without_Script() { // Given var environment = FakeEnvironment.CreateUnixEnvironment(); var fakeFileSystem = new FakeFileSystem(environment); fakeFileSystem.CreateFile(new FilePath("build.cake")); var fixture = new ArgumentParserFixture { FileSystem = fakeFileSystem }; var parser = new ArgumentParser(fixture.Log, fixture.FileSystem); // When var result = parser.Parse(new[] { "-unknown" }); // Then Assert.True(result.Arguments.ContainsKey("unknown")); }
public void Should_Return_Default_Options_If_Multiple_Build_Configurations_Are_Provided() { // Given var fixture = new ArgumentParserFixture { Log = new FakeLog() }; var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); var arguments = new[] { "build1.config", "build2.config" }; // When CakeOptions options = parser.Parse(arguments); // Then AssertDefaultOptions(options); }
public void Should_Return_Error_If_Multiple_Arguments_With_The_Same_Name_Exist() { // Given var fixture = new ArgumentParserFixture { Log = new FakeLog() }; var parser = new ArgumentParser(fixture.Log, fixture.VerbosityParser); // When var result = parser.Parse(new[] { "build.csx", "--unknown", "--unknown" }); // Then Assert.NotNull(result); Assert.True(result.HasError); Assert.True(fixture.Log.Entries.Any(x => x.Message == "Multiple arguments with the same name (unknown).")); }
public void Can_Find_Default_Scripts(string scriptName) { // Given var fixture = new ArgumentParserFixture(); var parser = new ArgumentParser(fixture.Log, fixture.FileSystem); var file = Substitute.For<IFile>(); file.Exists.Returns(true); fixture.FileSystem.GetFile(Arg.Is<FilePath>(fp => fp.FullPath == scriptName)) .Returns(file); // When var result = parser.Parse(new string [] {}); // Then Assert.NotNull(result.Script); }
public void Should_Add_Unknown_Arguments_To_Argument_List_Without_Script() { // Given var fakeFileSystem = new FakeFileSystem(isCaseSensitive: false); var fakePath = new FilePath("build.cake"); var fakeFile = new FakeFile(fakeFileSystem, fakePath) { Exists = true }; var fixture = new ArgumentParserFixture { FileSystem = fakeFileSystem }; var parser = new ArgumentParser(fixture.Log, fixture.FileSystem); fakeFileSystem.Files.Add(fakePath, fakeFile); // When var result = parser.Parse(new[] { "-unknown" }); // Then Assert.True(result.Arguments.ContainsKey("unknown")); }