forked from PowerShell/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Validate product resource strings against resx files (PowerShell#4811)
- Loading branch information
1 parent
0770746
commit 0229451
Showing
11 changed files
with
170 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
12 changes: 12 additions & 0 deletions
12
test/powershell/engine/ResourceValidation/CimCmdletsResources.Tests.ps1
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,12 @@ | ||
. "$psscriptroot/TestRunner.ps1" | ||
|
||
$assemblyName = "Microsoft.Management.Infrastructure.CimCmdlets" | ||
|
||
# excluded resources, taken from the 'EmbeddedResource Remove' | ||
# entries in the csproj for the assembly | ||
$excludeList = @() | ||
# load the module since it isn't there by default | ||
import-module CimCmdlets | ||
|
||
# run the tests | ||
Test-ResourceStrings -AssemblyName $AssemblyName -ExcludeList $excludeList |
10 changes: 10 additions & 0 deletions
10
test/powershell/engine/ResourceValidation/ConsoleHostResources.Tests.ps1
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,10 @@ | ||
. "$psscriptroot/TestRunner.ps1" | ||
|
||
$AssemblyName = "Microsoft.PowerShell.ConsoleHost" | ||
|
||
# excluded resources, taken from the 'EmbeddedResource Remove' | ||
# entries in the csproj for the assembly | ||
$excludeList = @("HostMshSnapinResources.resx") | ||
|
||
# run the tests | ||
Test-ResourceStrings -AssemblyName $AssemblyName -ExcludeList $excludeList |
11 changes: 11 additions & 0 deletions
11
test/powershell/engine/ResourceValidation/DotNetEventingResources.Tests.ps1
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,11 @@ | ||
. "$psscriptroot/TestRunner.ps1" | ||
|
||
$assemblyName = "Microsoft.PowerShell.CoreCLR.Eventing" | ||
|
||
# excluded resources, taken from the 'EmbeddedResource Remove' | ||
# entries in the csproj for the assembly | ||
$excludeList = @() | ||
# load the module since it isn't there by default | ||
|
||
# run the tests | ||
Test-ResourceStrings -AssemblyName $AssemblyName -ExcludeList $excludeList |
17 changes: 17 additions & 0 deletions
17
test/powershell/engine/ResourceValidation/ManagementCommandsResources.Tests.ps1
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,17 @@ | ||
. "$psscriptroot/TestRunner.ps1" | ||
$AssemblyName = "Microsoft.PowerShell.Commands.Management" | ||
|
||
# excluded resources, taken from the 'EmbeddedResource Remove' | ||
# entries in the csproj for the assembly | ||
$excludeList = "EventlogResources.resx", | ||
"TransactionResources.resx", | ||
"WebServiceResources.resx", | ||
"HotFixResources.resx", | ||
"ControlPanelResources.resx", | ||
"WmiResources.resx", | ||
"ManagementMshSnapInResources.resx", | ||
"ClearRecycleBinResources.resx", | ||
"ClipboardResources.resx" | ||
|
||
# run the tests | ||
Test-ResourceStrings -AssemblyName $AssemblyName -ExcludeList $excludeList |
9 changes: 9 additions & 0 deletions
9
test/powershell/engine/ResourceValidation/SMAResources.Tests.ps1
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,9 @@ | ||
. "$psscriptroot/TestRunner.ps1" | ||
$AssemblyName = "System.Management.Automation" | ||
|
||
# excluded resources, taken from the 'EmbeddedResource Remove' | ||
# entries in the csproj for the assembly | ||
$excludeList = "CoreMshSnapinResources.resx", | ||
"ErrorPackageRemoting.resx" | ||
# run the tests | ||
Test-ResourceStrings -AssemblyName $AssemblyName -ExcludeList $excludeList |
12 changes: 12 additions & 0 deletions
12
test/powershell/engine/ResourceValidation/SecurityResources.Tests.ps1
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,12 @@ | ||
. "$psscriptroot/TestRunner.ps1" | ||
|
||
$assemblyName = "Microsoft.PowerShell.Security" | ||
|
||
# excluded resources, taken from the 'EmbeddedResource Remove' | ||
# entries in the csproj for the assembly | ||
$excludeList = @("SecurityMshSnapinResources.resx") | ||
# load the module since it isn't there by default | ||
import-module Microsoft.PowerShell.Security | ||
|
||
# run the tests | ||
Test-ResourceStrings -AssemblyName $AssemblyName -ExcludeList $excludeList |
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,56 @@ | ||
function Test-ResourceStrings | ||
{ | ||
param ( $AssemblyName, $ExcludeList ) | ||
|
||
# determine the needed resource directory. If these tests are moved | ||
# this logic will need to change | ||
$repoBase = (Resolve-Path (Join-Path $psScriptRoot ../../../..)).Path | ||
$asmBase = Join-Path $repoBase "src/$AssemblyName" | ||
$resourceDir = Join-Path $asmBase resources | ||
$resourceFiles = Get-ChildItem $resourceDir -Filter *.resx -ea stop | | ||
Where-Object { $excludeList -notcontains $_.Name } | ||
|
||
$bindingFlags = [reflection.bindingflags]"NonPublic,Static" | ||
|
||
# the resource generation is based on the file name of the .resx file | ||
# and is not in a namespace. We can find all of these classes in the | ||
# ${AssemblyName} assembly | ||
$ASSEMBLY = [appdomain]::CurrentDomain.GetAssemblies()| | ||
Where-Object { $_.FullName -match "$AssemblyName" } | ||
|
||
# Validate that the binary you're running has the proper message | ||
# based on the resource files. It is possible that -ResGen could be | ||
# skipped and the messages might become out of sync with what is in | ||
# source | ||
# | ||
# you could argue that we should be generating conditions where the message is delivered | ||
# and then test for that, but that is a check against an ErrorId while this is ensuring | ||
# that the contents of the built binary matches the resx content | ||
# | ||
# Normally you don't want to use reflection to get at the implementation details | ||
# but this tests generated code, so changes there will be consistent across | ||
# all the resource classes we generate | ||
# | ||
# This is the reason why this is not a general module for use. There is | ||
# no other way to run these tests | ||
Describe "Resources strings in $AssemblyName (was -ResGen used with Start-PSBuild)" -tag Feature { | ||
foreach ( $resourceFile in $resourceFiles ) | ||
{ | ||
# in the event that the id has a space in it, it is replaced with a '_' | ||
$classname = $resourcefile.Name -replace ".resx" | ||
It "'$classname' should be an available type and the strings should be correct" { | ||
# get the type from the assembly | ||
$resourceType = $ASSEMBLY.GetType($classname, $false, $true) | ||
# the properties themselves are static internals, so we need | ||
# to using the appropriate bindingflags | ||
$resourceType | Should Not BeNullOrEmpty | ||
|
||
# check all the resource strings | ||
$xmlData = [xml](Get-Content $resourceFile.Fullname) | ||
foreach ( $inResource in $xmlData.root.data ) { | ||
$resourceType.GetProperty($inResource.name,$bindingFlags).GetValue(0) | should be $inresource.value | ||
} | ||
} | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
test/powershell/engine/ResourceValidation/UtilityResources.Tests.ps1
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,18 @@ | ||
. "$psscriptroot/TestRunner.ps1" | ||
$AssemblyName = "Microsoft.PowerShell.Commands.Utility" | ||
|
||
# excluded resources, taken from the 'EmbeddedResource Remove' | ||
# entries in the csproj for the assembly | ||
$excludeList = "CoreMshSnapinResources.resx", | ||
"ErrorPackageRemoting.resx", | ||
"FormatAndOut_out_gridview.resx", | ||
"UtilityMshSnapinResources.resx", | ||
"OutPrinterDisplayStrings.resx", | ||
"UpdateListStrings.resx", | ||
"ConvertFromStringResources.resx", | ||
"ConvertStringResources.resx", | ||
"FlashExtractStrings.resx", | ||
"ImmutableStrings.resx" | ||
import-module Microsoft.Powershell.Utility | ||
# run the tests | ||
Test-ResourceStrings -AssemblyName $AssemblyName -ExcludeList $excludeList |
22 changes: 22 additions & 0 deletions
22
test/powershell/engine/ResourceValidation/WSManResources.Tests.ps1
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,22 @@ | ||
. "$psscriptroot/TestRunner.ps1" | ||
|
||
$assemblyName = "Microsoft.WSMan.Management" | ||
|
||
# excluded resources, taken from the 'EmbeddedResource Remove' | ||
# entries in the csproj for the assembly | ||
$excludeList = @() | ||
# load the module since it isn't there by default | ||
import-module Microsoft.WSMan.Management | ||
|
||
|
||
try { | ||
if ( ! $IsWindows ) | ||
{ | ||
$PSDefaultParameterValues["it:skip"] = $true | ||
} | ||
# run the tests | ||
Test-ResourceStrings -AssemblyName $AssemblyName -ExcludeList $excludeList | ||
} | ||
finally { | ||
$PSDefaultParameterValues.Remove("it:skip") | ||
} |