Skip to content
This repository was archived by the owner on Feb 24, 2021. It is now read-only.

Commit bf2e39f

Browse files
committed
Fix review comments at r1-r3
1 parent 79e07e5 commit bf2e39f

3 files changed

Lines changed: 50 additions & 43 deletions

File tree

CHANGELOG.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,22 @@
3636
use AllowClobber
3737
([issue #310](https://github.com/PowerShell/DscResource.Tests/issues/310)).
3838
- Fix MetaFixers Functions Pipeline Processing.
39-
- Add common tests for localization, these tests is opt-in ([issue #145](https://github.com/PowerShell/DscResource.Tests/issues/145)).
39+
- Added common opt-in tests for localization ([issue #145](https://github.com/PowerShell/DscResource.Tests/issues/145)).
4040
- Should have an en-US localization folder.
4141
- The en-US localization folder should have the correct casing.
42-
- Should exist a resource file with the correct name in the localization folder.
43-
- The resource or module should use all the localization string keys from the localization resource file.
44-
- The localization resource file should not be missing any localization string key that are used in the resource or module.
42+
- A resource file with the correct name should exist in the localization
43+
folder.
44+
- The resource or module should use all the localization string keys
45+
from the localization resource file.
46+
- The localization resource file should not be missing any localization
47+
string key that is used in the resource or module.
4548
- If there are other localization folders (other than en-US)
4649
- They should contain a resource file with the correct name.
4750
- The folders should use the correct casing.
48-
- All en-US resource file localized string keys must also exist in the resource file.
49-
- There should be no additional localized string keys in the resource file that does not exist in the en-US resource file.
51+
- All en-US resource file localized string keys must also exist in
52+
the resource file.
53+
- There should be no additional localized string keys in the resource
54+
file that do not exist in the en-US resource file.
5055

5156
## 0.3.0.0
5257

Meta.Tests.ps1

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,18 +1256,18 @@ Describe 'Common Tests - Validate Localization' {
12561256

12571257
Context 'When a resource or module should have localization files' {
12581258
BeforeAll {
1259-
$testCases = @()
1259+
$foldersToTest = @()
12601260

12611261
foreach ($folder in $allFolders)
12621262
{
1263-
$testCases += @{
1263+
$foldersToTest += @{
12641264
Folder = $folder.Name
12651265
Path = $folder.FullName
12661266
}
12671267
}
12681268
}
12691269

1270-
It 'Should have en-US localization folder for the resource/module <Folder>' -TestCases $testCases {
1270+
It 'Should have en-US localization folder for the resource/module <Folder>' -TestCases $foldersToTest {
12711271
param
12721272
(
12731273
[Parameter()]
@@ -1284,7 +1284,7 @@ Describe 'Common Tests - Validate Localization' {
12841284
Test-Path -Path $localizationFolderPath | Should -BeTrue -Because 'the en-US folder must exist'
12851285
}
12861286

1287-
It 'Should have en-US localization folder with the correct casing for the resource/module <Folder>' -TestCases $testCases {
1287+
It 'Should have en-US localization folder with the correct casing for the resource/module <Folder>' -TestCases $foldersToTest {
12881288
param
12891289
(
12901290
[Parameter()]
@@ -1304,7 +1304,7 @@ Describe 'Common Tests - Validate Localization' {
13041304
$localizationFolderOnDisk.Name | Should -MatchExactly 'en-US' -Because 'the en-US folder must have the correct casing'
13051305
}
13061306

1307-
It 'Should have en-US localization string resource file for the resource/module <Folder>' -TestCases $testCases {
1307+
It 'Should have en-US localization string resource file for the resource/module <Folder>' -TestCases $foldersToTest {
13081308
param
13091309
(
13101310
[Parameter()]
@@ -1318,16 +1318,16 @@ Describe 'Common Tests - Validate Localization' {
13181318

13191319
$localizationResourceFilePath = Join-Path -Path (Join-Path -Path $Path -ChildPath 'en-US') -ChildPath "$Folder.strings.psd1"
13201320

1321-
Test-Path -Path $localizationResourceFilePath | Should -BeTrue -Because 'the there must exist a string resource file in the localization folder en-US'
1321+
Test-Path -Path $localizationResourceFilePath | Should -BeTrue -Because 'there must exist a string resource file in the localization folder en-US'
13221322
}
13231323

1324-
foreach ($testCase in $testCases)
1324+
foreach ($testCase in $foldersToTest)
13251325
{
13261326
$skipTest_LocalizedKeys = $false
13271327
$skipTest_UsedLocalizedKeys = $false
13281328

13291329
$testCases_LocalizedKeys = @()
1330-
$testCases_UsedLocalizedKeys= @()
1330+
$testCases_UsedLocalizedKeys = @()
13311331

13321332
$sourceLocalizationFolderPath = Join-Path -Path $testCase.Path -ChildPath 'en-US'
13331333

@@ -1389,34 +1389,34 @@ Describe 'Common Tests - Validate Localization' {
13891389
}
13901390

13911391
Context ('When validating resource/module {0}' -f $testCase.Folder) {
1392-
It 'Should use the localized string key <LocalizedKey>, from the localization resource file' -TestCases $testCases_LocalizedKeys -Skip:$skipTest_LocalizedKeys {
1392+
It 'Should use the localized string key <LocalizedKey> from the localization resource file' -TestCases $testCases_LocalizedKeys -Skip:$skipTest_LocalizedKeys {
13931393
param
13941394
(
13951395
[Parameter()]
13961396
[System.String]
13971397
$LocalizedKey
13981398
)
13991399

1400-
$usedLocalizationKeys | Should -Contain $LocalizedKey -Because 'the key exist in the localized string resource file'
1400+
$usedLocalizationKeys | Should -Contain $LocalizedKey -Because 'the key exists in the localized string resource file so it should also exist in the code'
14011401
}
14021402

1403-
It 'Should not be missing the localized string key <LocalizedKey>, in the localization resource file' -TestCases $testCases_UsedLocalizedKeys -Skip:$skipTest_UsedLocalizedKeys {
1403+
It 'Should not be missing the localized string key <LocalizedKey> from the localization resource file' -TestCases $testCases_UsedLocalizedKeys -Skip:$skipTest_UsedLocalizedKeys {
14041404
param
14051405
(
14061406
[Parameter()]
14071407
[System.String]
14081408
$LocalizedKey
14091409
)
14101410

1411-
$englishLocalizedStrings.Keys | Should -Contain $LocalizedKey -Because 'the key is used in the resource/module script file'
1411+
$englishLocalizedStrings.Keys | Should -Contain $LocalizedKey -Because 'the key is used in the resource/module script file so it should also exist in the localized string resource files'
14121412
}
14131413
}
14141414
}
14151415
}
14161416

14171417
Context 'When a resource or module is localized to other languages' {
14181418
BeforeAll {
1419-
$testCases = @()
1419+
$otherLanguagesToTest = @()
14201420

14211421
foreach ($folder in $allFolders)
14221422
{
@@ -1431,7 +1431,7 @@ Describe 'Common Tests - Validate Localization' {
14311431

14321432
foreach ($localizationFolder in $localizationFolders)
14331433
{
1434-
$testCases += @{
1434+
$otherLanguagesToTest += @{
14351435
Folder = $folder.Name
14361436
Path = $folder.FullName
14371437
LocalizationFolder = $localizationFolder.Name
@@ -1441,16 +1441,9 @@ Describe 'Common Tests - Validate Localization' {
14411441
}
14421442

14431443
# Only run these tests if there are test cases to be tested.
1444-
if ($testCases)
1445-
{
1446-
$skipTests = $false
1447-
}
1448-
else
1449-
{
1450-
$skipTests = $true
1451-
}
1444+
$skipTests = -not $otherLanguagesToTest
14521445

1453-
It 'Should have localization string resource file for the resource/module <Folder> and localization folder <LocalizationFolder>' -TestCases $testCases -Skip:$skipTests {
1446+
It 'Should have a localization string resource file for the resource/module <Folder> and localization folder <LocalizationFolder>' -TestCases $otherLanguagesToTest -Skip:$skipTests {
14541447
param
14551448
(
14561449
[Parameter()]
@@ -1468,10 +1461,10 @@ Describe 'Common Tests - Validate Localization' {
14681461

14691462
$localizationResourceFilePath = Join-Path -Path (Join-Path -Path $Path -ChildPath $LocalizationFolder) -ChildPath "$Folder.strings.psd1"
14701463

1471-
Test-Path -Path $localizationResourceFilePath | Should -BeTrue -Because ('the there must exist a string resource file in the localization folder {0}' -f $LocalizationFolder)
1464+
Test-Path -Path $localizationResourceFilePath | Should -BeTrue -Because ('there must exist a string resource file in the localization folder {0}' -f $LocalizationFolder)
14721465
}
14731466

1474-
It 'Should have the localization folder with the correct casing for the resource/module <Folder> and localization folder <LocalizationFolder>' -TestCases $testCases -Skip:$skipTests {
1467+
It 'Should have a localization folder with the correct casing for the resource/module <Folder> and localization folder <LocalizationFolder>' -TestCases $otherLanguagesToTest -Skip:$skipTests {
14751468
param
14761469
(
14771470
[Parameter()]
@@ -1491,7 +1484,7 @@ Describe 'Common Tests - Validate Localization' {
14911484
$localizationFolderOnDisk.Name | Should -MatchExactly '[a-z]{2}-[A-Z]{2}' -Because 'the localization folder must have the correct casing'
14921485
}
14931486

1494-
foreach ($testCase in $testCases)
1487+
foreach ($testCase in $otherLanguagesToTest)
14951488
{
14961489
$testCases_CompareAgainstEnglishLocalizedKeys = @()
14971490
$testCases_MissingEnglishLocalizedKeys = @()
@@ -1545,10 +1538,13 @@ Describe 'Common Tests - Validate Localization' {
15451538
$LocalizationFolder
15461539
)
15471540

1548-
$localizedStrings.Keys | Should -Contain $LocalizedKey -Because 'the key exist in the en-US localization resource file'
1541+
$localizedStrings.Keys | Should -Contain $LocalizedKey -Because 'the key exists in the en-US localization resource file so the key should also exist in this language file'
15491542
} -ErrorVariable itBlockError
15501543

1551-
# If the It-block did not pass the test, output the a text explaining hwo to resolve the issue.
1544+
<#
1545+
If the It-block did not pass the test, output the a text
1546+
explaining how to resolve the issue.
1547+
#>
15521548
if ($itBlockError.Count -ne 0)
15531549
{
15541550
$message = @"
@@ -1561,7 +1557,7 @@ with the en-US text string.
15611557
Write-Host -ForegroundColor White -Object ''
15621558
}
15631559

1564-
It "Should not be missing the localization string key <LocalizedKey> in the english resource file for the resource/module <Folder>" -TestCases $testCases_MissingEnglishLocalizedKeys {
1560+
It "Should not be missing the localization string key <LocalizedKey> from the english resource file for the resource/module <Folder>" -TestCases $testCases_MissingEnglishLocalizedKeys {
15651561
param
15661562
(
15671563
[Parameter()]
@@ -1577,7 +1573,7 @@ with the en-US text string.
15771573
$LocalizationFolder
15781574
)
15791575

1580-
$englishLocalizedStrings.Keys | Should -Contain $LocalizedKey -Because ('the key exist in the resource file for the location folder {0}' -f $LocalizationFolder)
1576+
$englishLocalizedStrings.Keys | Should -Contain $LocalizedKey -Because ('the key exists in the resource file for the location folder {0} so it should also exist in the en-US string resource file' -f $LocalizationFolder)
15811577
}
15821578
}
15831579
}

README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,20 +185,26 @@ to ignore part of the text that matches the regular expression.
185185

186186
#### Common Tests - Validating Localization
187187

188-
These tests validate the localization folders and files, and also so that
188+
These tests validate the localization folders and files, and also that
189189
each localization string key is used and there are no missing or extra
190-
localization string keys.
190+
localization string keys. These tests will only work if the localization
191+
variable is `$script:localizedData`.
191192

192193
- Should have an en-US localization folder.
193194
- The en-US localization folder should have the correct casing.
194-
- Should exist a resource file with the correct name in the localization folder.
195-
- The resource or module should use all the localization string keys from the localization resource file.
196-
- The localization resource file should not be missing any localization string key that are used in the resource or module.
195+
- A resource file with the correct name should exist in the localization
196+
folder.
197+
- The resource or module should use all the localization string keys from
198+
the localization resource file.
199+
- The localization resource file should not be missing any localization
200+
string key that is used in the resource or module.
197201
- If there are other localization folders (other than en-US)
198202
- They should contain a resource file with the correct name.
199203
- The folders should use the correct casing.
200-
- All en-US resource file localized string keys must also exist in the resource file.
201-
- There should be no additional localized string keys in the resource file that does not exist in the en-US resource file.
204+
- All en-US resource file localized string keys must also exist in the
205+
resource file.
206+
- There should be no additional localized string keys in the resource
207+
file that does not exist in the en-US resource file.
202208

203209
### Markdown Testing
204210

0 commit comments

Comments
 (0)