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
Validate product resource strings against resx files #4811
Validate product resource strings against resx files #4811
Conversation
Does it make sense to check for unused ResourceId in resx files? |
@iSazonov re: check for unused ResourceId in resx files |
@@ -0,0 +1,57 @@ | |||
function Test-ResourceStrings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to put this into an existing module or a new test module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wanted to do it this way because I do not want to make this a general function - we shouldn't be testing internal data structures, but there's no way to do this test without it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
$AssemblyName = "Microsoft.PowerShell.ConsoleHost" | ||
|
||
# excluded resources | ||
$excludeList = @("HostMshSnapinResources.resx") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should add comment why it's being excluded
$AssemblyName = "Microsoft.PowerShell.Commands.Utility" | ||
# this list is taken from ${AssemblyName}.csproj | ||
# excluded resources | ||
$excludeList = "CoreMshSnapinResources.resx", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add comment why these are excluded
$AssemblyName = "Microsoft.PowerShell.Commands.Management" | ||
# this list is taken from ${AssemblyName}.csproj | ||
# excluded resources | ||
$excludeList = "EventlogResources.resx", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added comment why excluded
$AssemblyName = "System.Management.Automation" | ||
# this list is taken from ${AssemblyName}.csproj | ||
# excluded resources | ||
$excludeList = "CoreMshSnapinResources.resx", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment why excluded
$assemblyName = "Microsoft.PowerShell.Security" | ||
# this list is taken from ${AssemblyName}.csproj | ||
# excluded resources | ||
$excludeList = @("SecurityMshSnapinResources.resx") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment why excluded
|
||
# determine the needed resource directory. If these tests are moved | ||
# this logic will need to change | ||
$repoBase = (Resolve-Path (Join-Path $psScriptRoot ../../../..)).Path |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to use: git rev-parse --show-toplevel?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure - I'll make that change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cannot assume that we have git tools. For example, the Code Coverage machine does not have git tools.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in that case, this is fine
$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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use -Exclude
parameter for Get-ChildItem
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i can do that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
huh - it turns out that we might have a bug - get-childitem -filter *.resx -exclude <thing>
returns no results. I'll have to leave it as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that you mention it, there's a number of issues with -exclude
. Ok with leaving as-is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave 2 comments. They don't block this PR.
@@ -0,0 +1,10 @@ | |||
. "$psscriptroot/TestRunner.ps1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with other files, maybe change the file name from DotNetEventing.Tests.ps1
to ***Resource.Tests.ps1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will change
@@ -0,0 +1,17 @@ | |||
. "$psscriptroot/TestRunner.ps1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the file for management dll is ManagementCommandsResources.Tests.ps1
, Maybe change MPCUResource.Tests.ps1
to Utility.Resource.Tests.ps1
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…mbly this will validate that the messages that we emit match the resource file unsync can occur when not compiling with -ResGen, this will keep that from happening. A side effect of these tests is that it will catch resource ids which have spaces in them
Also rename some files for better consistency
46e2f48
to
0d7034a
Compare
@SteveL-MSFT updated and pushed - see my comment about using |
@JamesWTruher re: check for unused ResourceId in resx files It seems @lzybkr once mentioned some tool. |
@iSazonov - I use ReSharper to find unused references. There were some accuracy issues when the csproj file wasn't the same as how we built, but it worked fairly well anyway, so I'm guessing it's pretty accurate now. |
@lzybkr Thanks! |
These tests validate that the resource strings represent the contents of the RESX files. This essentially ensures that we've run
-ResGen
when building. Additionally, these tests will ensure that we don't have ResourceIds which have a space in them (which we did).When there's a space in the ResourceId, the tooling converts the space to an "_" which is fine, but the compiled resource doesn't have that change, so when message retrieval is attempted, an empty string is returned.
Normally we generate an error and validate the ErrorId, but this test is different. We want to be sure that the message that we're giving the user is correct and the build included the
-ResGen
parameter.