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

Validate product resource strings against resx files #4811

Merged

Conversation

JamesWTruher
Copy link
Member

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.

@iSazonov
Copy link
Collaborator

Does it make sense to check for unused ResourceId in resx files?

@JamesWTruher
Copy link
Member Author

@iSazonov re: check for unused ResourceId in resx files
it would be good to check for these. I thought about how to do that, but couldn't come up something simple, other than brute force checking all the source files.

@@ -0,0 +1,57 @@
function Test-ResourceStrings
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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")
Copy link
Member

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",
Copy link
Member

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",
Copy link
Member

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",
Copy link
Member

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")
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

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 {
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i can do that

Copy link
Member Author

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.

Copy link
Member

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

Copy link
Member

@daxian-dbw daxian-dbw left a 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"
Copy link
Member

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

Copy link
Member Author

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"
Copy link
Member

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will change

Copy link
Member

@adityapatwardhan adityapatwardhan left a 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
@JamesWTruher
Copy link
Member Author

@SteveL-MSFT updated and pushed - see my comment about using -filter and -exclude together - I double checked with PowerShell 5 and the behavior is the same. if you use -filter and -exclude no results are returned, so at least it's not a regression, although i agree the behavior is a little surprising

@iSazonov
Copy link
Collaborator

@JamesWTruher re: check for unused ResourceId in resx files

It seems @lzybkr once mentioned some tool.
As for me I think better way is to get native warning from the compiler that does still not implemented.

@lzybkr
Copy link
Member

lzybkr commented Sep 18, 2017

@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.

@iSazonov
Copy link
Collaborator

@lzybkr Thanks!
I see there is free ReSharper command tools

@TravisEz13 TravisEz13 merged commit 0229451 into PowerShell:master Sep 18, 2017
@JamesWTruher
Copy link
Member Author

@iSazonov @lzybkr I created #4860 to track

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants