Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#158) Relegate the -lo/-li warning to log-file-only #3167

Merged
merged 2 commits into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void Should_output_warning_message_about_unsupported_argument(string argu
_because();
MockLogger.Messages.Keys.ShouldContain("Warn");
MockLogger.Messages["Warn"].ShouldContain(@"
UNSUPPORTED ARGUMENT: Ignoring the argument {0}. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!".FormatWith(argument));
Ignoring the argument {0}. This argument is unsupported for locally installed packages.".FormatWith(argument));
}

[NUnit.Framework.TestCase("-li")]
Expand All @@ -157,7 +157,7 @@ public void Should_output_warning_message_about_unsupported_argument_and_set_inc
_because();
MockLogger.Messages.Keys.ShouldContain("Warn");
MockLogger.Messages["Warn"].ShouldContain(@"
UNSUPPORTED ARGUMENT: Ignoring the argument {0}. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!".FormatWith(argument));
Ignoring the argument {0}. This argument is unsupported for locally installed packages.".FormatWith(argument));
Configuration.ListCommand.IncludeRegistryPrograms.ShouldBeTrue();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,18 +148,18 @@ public virtual int Count(ChocolateyConfiguration config)
public virtual void ParseAdditionalArguments(IList<string> unparsedArguments, ChocolateyConfiguration configuration)
{
var argumentsWithoutLocalOnly = new List<string>(unparsedArguments.Count);
const string unsupportedArgumentMessage = @"
Ignoring the argument {0}. This argument is unsupported for locally installed packages.";

foreach (var argument in unparsedArguments)
{
if (_unsupportedArguments.Contains(argument, StringComparer.OrdinalIgnoreCase))
{
this.Log().Warn(ChocolateyLoggers.Important, @"
UNSUPPORTED ARGUMENT: Ignoring the argument {0}. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!", argument);
this.Log().Warn(ChocolateyLoggers.LogFileOnly, unsupportedArgumentMessage, argument);
}
else if (_unsupportedIncludeRegistryProgramsArguments.Contains(argument, StringComparer.OrdinalIgnoreCase))
{
this.Log().Warn(ChocolateyLoggers.Important, @"
UNSUPPORTED ARGUMENT: Ignoring the argument {0}. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!", argument);
this.Log().Warn(ChocolateyLoggers.LogFileOnly, unsupportedArgumentMessage, argument);
configuration.ListCommand.IncludeRegistryPrograms = true;
}
else
Expand Down
18 changes: 15 additions & 3 deletions tests/chocolatey-tests/commands/choco-list.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,29 @@ Describe "choco list" -Tag Chocolatey, ListCommand {
}
}

Context "Listing local packages with unsupported argument outputs warning" -ForEach @('-l', '-lo', '--lo', '--local', '--localonly', '--local-only', '--order-by-popularity', '-a', '--all', '--allversions', '--all-versions', '-li', '-il', '-lai', '-lia', '-ali', '-ail', '-ial', '-ila') {
Context "Listing local packages with unsupported argument outputs warning to log file only" -ForEach @('-l', '-lo', '--lo', '--local', '--localonly', '--local-only', '--order-by-popularity', '-a', '--all', '--allversions', '--all-versions', '-li', '-il', '-lai', '-lia', '-ali', '-ail', '-ial', '-ila') {
BeforeAll {
$LogPath = "$env:ChocolateyInstall\logs\chocolatey.log"
$OldLogContent = Get-Content $LogPath
Remove-Item -Path $LogPath

$Output = Invoke-Choco list $_
$LogFile = Get-Content -Path $LogPath

# Logs are picked up by CI for investigation if needed, so we'll keep both full sets of logs.
@(
$OldLogContent
$LogFile
) | Set-Content -Path $LogPath
}

It "Exits with Success (0)" {
$Output.ExitCode | Should -Be 0
}

It "Should contain expected warning message" {
$Output.Lines | Should -Contain "UNSUPPORTED ARGUMENT: Ignoring the argument $_. This argument is unsupported for locally installed packages, and will be treated as a package name in Chocolatey CLI v3!"
It "Should contain expected warning message in the logs" {
@($LogFile) -match "Ignoring the argument $_. This argument is unsupported for locally installed packages." |
Should -Not -BeNullOrEmpty
}
}
}