diff --git a/src/chocolatey.tests/infrastructure/commandline/InteractivePromptSpecs.cs b/src/chocolatey.tests/infrastructure/commandline/InteractivePromptSpecs.cs index 10730a9543..29c8fb2e13 100644 --- a/src/chocolatey.tests/infrastructure/commandline/InteractivePromptSpecs.cs +++ b/src/chocolatey.tests/infrastructure/commandline/InteractivePromptSpecs.cs @@ -495,17 +495,42 @@ public void should_error_when_the_prompt_input_is_null() choices = new List { "bob" }; prompt_value = null; bool errored = false; + string errorMessage = string.Empty; console.Setup(c => c.ReadLine()).Returns(""); //Enter pressed try { prompt(); } - catch (Exception) + catch (Exception ex) { errored = true; + errorMessage = ex.Message; + } + + errored.ShouldBeTrue(); + errorMessage.ShouldContain("Value for prompt cannot be null."); + console.Verify(c => c.ReadLine(), Times.Never); + } + + [Fact] + public void should_error_when_the_choicelist_contains_empty_values() + { + choices = new List { "bob", "" }; + bool errored = false; + string errorMessage = string.Empty; + console.Setup(c => c.ReadLine()).Returns(""); //Enter pressed + try + { + prompt(); + } + catch (Exception ex) + { + errored = true; + errorMessage = ex.Message; } errored.ShouldBeTrue(); + errorMessage.ShouldContain("Some choices are empty."); console.Verify(c => c.ReadLine(), Times.Never); } @@ -527,7 +552,7 @@ public void should_error_when_the_choicelist_has_multiple_items_with_same_first_ } errored.ShouldBeTrue(); - errorMessage.ShouldContain("Multiple choices have the same first letter. Please ensure you pass choices with different first letters."); + errorMessage.ShouldContain("Multiple choices have the same first letter."); console.Verify(c => c.ReadLine(), Times.Never); } } diff --git a/src/chocolatey/infrastructure/commandline/InteractivePrompt.cs b/src/chocolatey/infrastructure/commandline/InteractivePrompt.cs index ddb3688baf..33a05dab35 100644 --- a/src/chocolatey/infrastructure/commandline/InteractivePrompt.cs +++ b/src/chocolatey/infrastructure/commandline/InteractivePrompt.cs @@ -49,6 +49,11 @@ public static string prompt_for_confirmation_short(string prompt, IEnumerable c.Any(), (name, value) => { throw new ApplicationException("No choices passed in. Please ensure you pass choices."); }); + Ensure + .that(() => choices) + .meets( + c => !c.Any(String.IsNullOrWhiteSpace), + (name, value) => { throw new ApplicationException("Some choices are empty. Please ensure you provide no empty choices."); }); Ensure .that(() => choices) .meets( @@ -65,7 +70,7 @@ public static string prompt_for_confirmation_short(string prompt, IEnumerable