From 4f19c05547240d98822f60641a2ec61d4beca204 Mon Sep 17 00:00:00 2001 From: Steve Lee Date: Tue, 15 Nov 2022 17:57:03 -0800 Subject: [PATCH] Ensure `HelpInfo.Category` is consistently a string (#18254) --- .../help/MamlClassHelpInfo.cs | 2 +- .../help/MamlCommandHelpInfo.cs | 2 +- test/powershell/engine/Help/HelpSystem.Tests.ps1 | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/System.Management.Automation/help/MamlClassHelpInfo.cs b/src/System.Management.Automation/help/MamlClassHelpInfo.cs index 042ab21e70..579d72c87f 100644 --- a/src/System.Management.Automation/help/MamlClassHelpInfo.cs +++ b/src/System.Management.Automation/help/MamlClassHelpInfo.cs @@ -86,7 +86,7 @@ namespace System.Management.Automation internal MamlClassHelpInfo Copy(HelpCategory newCategoryToUse) { MamlClassHelpInfo result = new MamlClassHelpInfo(_fullHelpObject.Copy(), newCategoryToUse); - result.FullHelp.Properties["Category"].Value = newCategoryToUse; + result.FullHelp.Properties["Category"].Value = newCategoryToUse.ToString(); return result; } diff --git a/src/System.Management.Automation/help/MamlCommandHelpInfo.cs b/src/System.Management.Automation/help/MamlCommandHelpInfo.cs index 81a9a4a743..d1c52e66cc 100644 --- a/src/System.Management.Automation/help/MamlCommandHelpInfo.cs +++ b/src/System.Management.Automation/help/MamlCommandHelpInfo.cs @@ -441,7 +441,7 @@ namespace System.Management.Automation internal MamlCommandHelpInfo Copy(HelpCategory newCategoryToUse) { MamlCommandHelpInfo result = new MamlCommandHelpInfo(_fullHelpObject.Copy(), newCategoryToUse); - result.FullHelp.Properties["Category"].Value = newCategoryToUse; + result.FullHelp.Properties["Category"].Value = newCategoryToUse.ToString(); return result; } diff --git a/test/powershell/engine/Help/HelpSystem.Tests.ps1 b/test/powershell/engine/Help/HelpSystem.Tests.ps1 index e34cd95607..05d3d086a1 100644 --- a/test/powershell/engine/Help/HelpSystem.Tests.ps1 +++ b/test/powershell/engine/Help/HelpSystem.Tests.ps1 @@ -45,6 +45,16 @@ function GetCurrentUserHelpRoot { return $userHelpRoot } +Describe 'Validate HelpInfo type' -Tags @('CI') { + + It 'Category should be a string' { + $help = Get-Help * + $category = $help | ForEach-Object { $_.Category.GetType().FullName } | Select-Object -Unique + $category.Count | Should -Be 1 -Because 'All help categories should be strings, >1 indicates a type mismatch' + $category | Should -BeExactly 'System.String' + } +} + Describe "Validate that //default.help.txt is present" -Tags @('CI') { It "Get-Help returns information about the help system" {