-
Notifications
You must be signed in to change notification settings - Fork 905
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(GH-450) Restore pipe separator for limited list output
When other tools use choco to determine whether a package is installed they use `choco list -lo -r`. The -r is to limit output, show only the package information. At one point the output separated information with pipes, unlike the normal output. However when commit 5782a21 was introduced, it accidentally removed this very important distinction. Correct this to again us pipes. Also add integration spec scenarios to ensure this is not subject to happen again.
- Loading branch information
1 parent
02c94ef
commit 38537c3
Showing
6 changed files
with
211 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
src/chocolatey.tests.integration/scenarios/ListScenarios.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
// Copyright © 2011 - Present RealDimensions Software, LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
namespace chocolatey.tests.integration.scenarios | ||
{ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using NuGet; | ||
using Should; | ||
using bdddoc.core; | ||
using chocolatey.infrastructure.app.commands; | ||
using chocolatey.infrastructure.app.configuration; | ||
using chocolatey.infrastructure.app.services; | ||
using chocolatey.infrastructure.results; | ||
|
||
public class ListScenarios | ||
{ | ||
public abstract class ScenariosBase : TinySpec | ||
{ | ||
protected IList<PackageResult> Results; | ||
protected ChocolateyConfiguration Configuration; | ||
protected IChocolateyPackageService Service; | ||
|
||
public override void Context() | ||
{ | ||
Configuration = Scenario.list(); | ||
Scenario.reset(Configuration); | ||
Configuration.PackageNames = Configuration.Input = "upgradepackage"; | ||
Scenario.add_packages_to_source_location(Configuration, Configuration.Input + "*" + Constants.PackageExtension); | ||
Scenario.add_packages_to_source_location(Configuration, "installpackage*" + Constants.PackageExtension); | ||
Scenario.add_packages_to_source_location(Configuration, "badpackage*" + Constants.PackageExtension); | ||
Scenario.install_package(Configuration, "installpackage", "1.0.0"); | ||
Scenario.install_package(Configuration, "upgradepackage", "1.0.0"); | ||
Configuration.SkipPackageInstallProvider = true; | ||
Scenario.install_package(Configuration, "badpackage", "1.0"); | ||
Configuration.SkipPackageInstallProvider = false; | ||
|
||
Service = NUnitSetup.Container.GetInstance<IChocolateyPackageService>(); | ||
} | ||
|
||
public bool has_expected_message(string expectedMessage) | ||
{ | ||
bool messageFound = false; | ||
foreach (var messageLevel in MockLogger.Messages) | ||
{ | ||
foreach (var message in messageLevel.Value.or_empty_list_if_null()) | ||
{ | ||
if (message.Contains(expectedMessage)) messageFound = true; | ||
} | ||
} | ||
|
||
return messageFound; | ||
} | ||
|
||
public bool has_expected_message(string expectedMessage, LogLevel level) | ||
{ | ||
bool messageFound = false; | ||
foreach (var message in MockLogger.MessagesFor(level).or_empty_list_if_null()) | ||
{ | ||
if (message.Contains(expectedMessage)) messageFound = true; | ||
} | ||
|
||
return messageFound; | ||
} | ||
} | ||
|
||
[Concern(typeof(ChocolateyListCommand))] | ||
public class when_listing_local_packages_happy_path : ScenariosBase | ||
{ | ||
public override void Because() | ||
{ | ||
MockLogger.reset(); | ||
Results = Service.list_run(Configuration).ToList(); | ||
} | ||
|
||
[Fact] | ||
public void should_contain_packages_and_versions_with_a_space_between_them() | ||
{ | ||
has_expected_message("upgradepackage 1.1.0").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_not_contain_packages_and_versions_with_a_pipe_between_them() | ||
{ | ||
has_expected_message("upgradepackage|1.1.0").ShouldBeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void should_contain_a_summary() | ||
{ | ||
has_expected_message("packages installed").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_contain_debugging_messages() | ||
{ | ||
has_expected_message("Searching for package information", LogLevel.Debug).ShouldBeTrue(); | ||
has_expected_message("Running list with the following filter", LogLevel.Debug).ShouldBeTrue(); | ||
has_expected_message("Start of List", LogLevel.Debug).ShouldBeTrue(); | ||
has_expected_message("End of List", LogLevel.Debug).ShouldBeTrue(); | ||
} | ||
} | ||
|
||
[Concern(typeof(ChocolateyListCommand))] | ||
public class when_listing_local_packages_limiting_output : ScenariosBase | ||
{ | ||
public override void Context() | ||
{ | ||
base.Context(); | ||
Configuration.RegularOutput = false; | ||
} | ||
|
||
public override void Because() | ||
{ | ||
MockLogger.reset(); | ||
Results = Service.list_run(Configuration).ToList(); | ||
} | ||
|
||
[Fact] | ||
public void should_contain_packages_and_versions_with_a_pipe_between_them() | ||
{ | ||
has_expected_message("upgradepackage|1.1.0").ShouldBeTrue(); | ||
} | ||
|
||
[Fact] | ||
public void should_only_have_messages_related_to_package_information() | ||
{ | ||
var count = MockLogger.Messages.SelectMany(messageLevel => messageLevel.Value.or_empty_list_if_null()).Count(); | ||
count.ShouldEqual(1); | ||
} | ||
|
||
[Fact] | ||
public void should_not_contain_packages_and_versions_with_a_space_between_them() | ||
{ | ||
has_expected_message("upgradepackage 1.1.0").ShouldBeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void should_not_contain_a_summary() | ||
{ | ||
has_expected_message("packages installed").ShouldBeFalse(); | ||
} | ||
|
||
[Fact] | ||
public void should_not_contain_debugging_messages() | ||
{ | ||
has_expected_message("Searching for package information", LogLevel.Debug).ShouldBeFalse(); | ||
has_expected_message("Running list with the following filter", LogLevel.Debug).ShouldBeFalse(); | ||
has_expected_message("Start of List", LogLevel.Debug).ShouldBeFalse(); | ||
has_expected_message("End of List", LogLevel.Debug).ShouldBeFalse(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters