From fceed17acaf5597b608548ea9dbef65c48358248 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Thu, 9 Aug 2018 14:30:05 +0200 Subject: [PATCH 01/12] Changes to Meta.Tests.ps1 - Adding opt-in common test for spellchecking markdown files. Opt-in by adding "Common Tests - Spellcheck Markdown Files" in the file .MetaTestOptIn.json (issue #211). --- Meta.Tests.ps1 | 220 +++++++++++++++++++++++++++++++++++++------------ README.md | 6 ++ 2 files changed, 172 insertions(+), 54 deletions(-) diff --git a/Meta.Tests.ps1 b/Meta.Tests.ps1 index 14f6c9c1..e824e2ef 100644 --- a/Meta.Tests.ps1 +++ b/Meta.Tests.ps1 @@ -903,68 +903,70 @@ Describe 'Common Tests - Validate Markdown Files' -Tag 'Markdown' { } } - if (Test-Path -Path (Join-Path -Path $repoRootPath -ChildPath '.markdownlint.json')) - { - Write-Verbose -Message ('Using markdownlint settings file from repository folder ''{0}''.' -f $repoRootPath) -Verbose - $markdownlintSettingsFilePath = Join-Path -Path $repoRootPath -ChildPath '.markdownlint.json' - } - else - { - Write-Verbose -Message 'Using markdownlint settings file from DscResource.Test repository.' -Verbose - $markdownlintSettingsFilePath = $null - } - - It "Should not have errors in any markdown files" { - - $mdErrors = 0 - try + Context 'When there are markdown files' { + if (Test-Path -Path (Join-Path -Path $repoRootPath -ChildPath '.markdownlint.json')) { + Write-Verbose -Message ('Using markdownlint settings file from repository folder ''{0}''.' -f $repoRootPath) -Verbose + $markdownlintSettingsFilePath = Join-Path -Path $repoRootPath -ChildPath '.markdownlint.json' + } + else + { + Write-Verbose -Message 'Using markdownlint settings file from DscResource.Test repository.' -Verbose + $markdownlintSettingsFilePath = $null + } - $gulpArgumentList = @( - 'test-mdsyntax', - '--silent', - '--rootpath', - $repoRootPath, - '--dscresourcespath', - $dscResourcesFolderFilePath - ) + It "Should not have errors in any markdown files" { - if ($markdownlintSettingsFilePath) + $mdErrors = 0 + try { - $gulpArgumentList += @( - '--settingspath', - $markdownlintSettingsFilePath + + $gulpArgumentList = @( + 'test-mdsyntax', + '--silent', + '--rootpath', + $repoRootPath, + '--dscresourcespath', + $dscResourcesFolderFilePath ) - } - Start-Process -FilePath "gulp" -ArgumentList $gulpArgumentList ` - -Wait -WorkingDirectory $PSScriptRoot -PassThru -NoNewWindow - Start-Sleep -Seconds 3 - $mdIssuesPath = Join-Path -Path $PSScriptRoot -ChildPath "markdownissues.txt" + if ($markdownlintSettingsFilePath) + { + $gulpArgumentList += @( + '--settingspath', + $markdownlintSettingsFilePath + ) + } - if ((Test-Path -Path $mdIssuesPath) -eq $true) - { - Get-Content -Path $mdIssuesPath | ForEach-Object -Process { - if ([string]::IsNullOrEmpty($_) -eq $false) - { - Write-Warning -Message $_ - $mdErrors ++ + Start-Process -FilePath 'gulp' -ArgumentList $gulpArgumentList ` + -Wait -WorkingDirectory $PSScriptRoot -PassThru -NoNewWindow + Start-Sleep -Seconds 3 + $mdIssuesPath = Join-Path -Path $PSScriptRoot -ChildPath 'markdownissues.txt' + + if ((Test-Path -Path $mdIssuesPath) -eq $true) + { + Get-Content -Path $mdIssuesPath | ForEach-Object -Process { + if ([string]::IsNullOrEmpty($_) -eq $false) + { + Write-Warning -Message $_ + $mdErrors ++ + } } } + Remove-Item -Path $mdIssuesPath -Force -ErrorAction SilentlyContinue + } + catch [System.Exception] + { + Write-Warning -Message ('Unable to run gulp to test markdown files. Please ' + ` + 'be sure that you have installed nodejs and have ' + ` + 'run ''npm install -g gulp'' in order to have this ' + ` + 'test execute.') } - Remove-Item -Path $mdIssuesPath -Force -ErrorAction SilentlyContinue - } - catch [System.Exception] - { - Write-Warning -Message ("Unable to run gulp to test markdown files. Please " + ` - "be sure that you have installed nodejs and have " + ` - "run 'npm install -g gulp' in order to have this " + ` - "text execute.") - } - if ($optIn) - { - $mdErrors | Should -Be 0 + if ($optIn) + { + $mdErrors | Should -Be 0 + } } } @@ -1032,9 +1034,119 @@ Describe 'Common Tests - Validate Markdown Files' -Tag 'Markdown' { } else { - Write-Warning -Message ("Unable to run gulp to test markdown files. Please " + ` - "be sure that you have installed nodejs and npm in order " + ` - "to have this text execute.") + Write-Warning -Message ('Unable to run gulp to test markdown files. Please ' + ` + 'be sure that you have installed nodejs and npm in order ' + ` + 'to have this text execute.') + } +} + +Describe 'Common Tests - Spellcheck Files' -Tag 'Spellcheck' { + BeforeAll { + $npmParametersForStartProcess = @{ + FilePath = 'npm' + ArgumentList = '' + WorkingDirectory = $PSScriptRoot + Wait = $true + WindowStyle = 'Hidden' + } + } + + if ((Get-Command -Name 'npm' -ErrorAction SilentlyContinue)) + { + $skipDependency = $false + } + else + { + Write-Warning -Message ('Unable to run cSpell to spellcheck markdown files. Please ' + ` + 'be sure that you have installed nodejs and npm in order ' + ` + 'to have this text execute.') + + $skipDependency = $true + } + + Context 'When installing spellcheck dependencies' { + It 'Should not throw an error when installing package cSpell in global scope' -Skip:$skipDependency { + { + # More information about cSpell: https://www.npmjs.com/package/cspell + $npmParametersForStartProcess['ArgumentList'] = 'install -g cspell' + Start-Process @npmParametersForStartProcess + } | Should -Not -Throw + } + } + + # If npm wasn't installed then we can't run this test. + $optIn = -not $skipDependency -and (Get-OptInStatus -OptIns $optIns -Name 'Common Tests - Spellcheck Markdown Files') + + Context 'When there are markdown files' { + $errorFileName = 'SpellingErrors.txt' + + It 'Should not have spelling errors in any markdown files' -Skip:(!$optIn) { + $spellcheckSettingsFilePath = Join-Path -Path $repoRootPath -ChildPath '.vscode\cSpell.json' + if (Test-Path -Path $spellcheckSettingsFilePath) + { + Write-Info -Message ('Using spellcheck settings file ''{0}''.' -f $spellcheckSettingsFilePath) + } + else + { + $spellcheckSettingsFilePath = $null + } + + $cSpellArgumentList = @( + '"**/*.md"', + '--no-color' + ) + + if ($spellcheckSettingsFilePath) + { + $cSpellArgumentList += @( + '--config', + $spellcheckSettingsFilePath + ) + } + + # This must be last, we send output to the error file. + $cSpellArgumentList += @( + ('>{0}' -f $errorFileName) + ) + + $startProcessParameters = @{ + FilePath = 'cspell' + ArgumentList = $cSpellArgumentList + Wait = $true + PassThru = $true + NoNewWindow = $true + } + + $process = Start-Process @startProcessParameters + $process.ExitCode | Should -Be 0 + } -ErrorVariable itBlockError + + # If the It-block did not pass the test, output the spelling errors. + if ($itBlockError.Count -ne 0) + { + $misspelledErrors = Get-Content -Path $errorFileName + + foreach ($misspelledError in $misspelledErrors) + { + $message = '{0}' -f $misspelledError + Write-Host -BackgroundColor Yellow -ForegroundColor Black -Object $message + } + } + + # Make sure we always remove the file if it exist. + if (Test-Path $errorFileName) + { + Remove-Item -Path $errorFileName -Force + } + } + + Context 'When uninstalling spellcheck dependencies' { + It 'Should not throw an error when uninstalling package cSpell in global scope' -Skip:$skipDependency { + { + $npmParametersForStartProcess['ArgumentList'] = 'uninstall -g cspell' + Start-Process @npmParametersForStartProcess + } | Should -Not -Throw + } } } diff --git a/README.md b/README.md index 2690fbdd..04f4e563 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,9 @@ The following opt-in flags are available: DSC resource module. - **Common Tests - Validate Markdown Links**: fails tests if a link in a markdown file is broken. +* **Common Tests - Spellcheck Markdown Files**: fail test if there are any + spelling errors in the markdown files. There is the possibility to add + or override words in the `.vscode\cSpell.json` file. #### Common Tests - Validate Markdown Links @@ -1019,6 +1022,9 @@ Contributors that add or change an example to be published must make sure that ([issue #188](https://github.com/PowerShell/DscResource.Tests/issues/188)). - Add new opt-in common test for markdown link linting ([issue #211](https://github.com/PowerShell/DscResource.Tests/issues/211)). +* Adding opt-in common test for spellchecking markdown files. Opt-in by + adding "Common Tests - Spellcheck Markdown Files" in the file + .MetaTestOptIn.json ([issue #211](https://github.com/PowerShell/DscResource.Tests/issues/211)). ### 0.2.0.0 From 15804e9ad27ec8849050bfebe26e86092b809d93 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 10 Aug 2018 18:28:42 +0200 Subject: [PATCH 02/12] Opt-in for "Common Tests - Spellcheck Markdown Files" --- .MetaTestOptIn.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.MetaTestOptIn.json b/.MetaTestOptIn.json index 188b4db8..412f8547 100644 --- a/.MetaTestOptIn.json +++ b/.MetaTestOptIn.json @@ -2,5 +2,6 @@ "Common Tests - Validate Module Files", "Common Tests - Validate Markdown Files", "Common Tests - Validate Example Files", - "Common Tests - Validate Script Files" + "Common Tests - Validate Script Files", + "Common Tests - Spellcheck Markdown Files" ] From ad874eaf4c56d7b1f75f4a99a34a836045e6f368 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 10 Aug 2018 18:51:32 +0200 Subject: [PATCH 03/12] Opt-in for the test "Common Tests - Spellcheck Markdown Files", and added the settings file `.vscode\cSpell.json`. --- .vscode/cSpell.json | 43 +++++++++++++++++++++++++++++++++++++++++++ README.md | 33 ++++++++++++++++++--------------- 2 files changed, 61 insertions(+), 15 deletions(-) create mode 100644 .vscode/cSpell.json diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json new file mode 100644 index 00000000..adf21f6c --- /dev/null +++ b/.vscode/cSpell.json @@ -0,0 +1,43 @@ +{ + "ignorePaths": [ + ".git/*", + ".vscode/*" + ], + "language": "en", + "dictionaries": [ + "powershell" + ], + "words": [ + "markdownlint", + "codecov", + "HQRM", + "GUIDs", + "unstaged" + ], + "ignoreRegExpList": [ + "AppVeyor", + "opencode@microsoft.com", + "\\.PRIVATEDATA", + "\\.COMPANYNAME", + "\\.LICENSEURI", + "\\.PROJECTURI", + "\\.ICONURI", + "\\.EXTERNALMODULEDEPENDENCIES", + "\\.REQUIREDSCRIPTS", + "\\.EXTERNALSCRIPTDEPENDENCIES", + "\\.RELEASENOTES", + "gulpfile.js", + "MSFT_", + "microsoft/windowsservercore", + "unittest_Transcript.txt", + "unittest_TestResults.xml", + "unittest_TestResults.json", + "unittest_DockerLog.txt", + "core\\.autocrlf=input", + "core\\.autocrlf true", + "2016-Datacenter", + "2016-Datacenter-Server-Core", + "HKLM:\\\\", + "\\.gitattributes" + ] +} diff --git a/README.md b/README.md index 04f4e563..4e47a52a 100644 --- a/README.md +++ b/README.md @@ -191,9 +191,9 @@ fails, you should be able to run `ConvertTo-UTF8` fixer from [MetaFixers.psm1](M The test helper module (TestHelper.psm1) contains the following functions: -- **New-Nuspec**: Creates a new nuspec file for nuget package. +- **New-Nuspec**: Creates a new nuspec file for NuGet package. - **Install-ResourceDesigner**: Will attempt to download the - xDSCResourceDesignerModule using Nuget package and return the module. + xDSCResourceDesignerModule using NuGet package and return the module. - **Initialize-TestEnvironment**: Initializes an environment for running unit or integration tests on a DSC resource. - **Restore-TestEnvironment**: Restores the environment after running unit or @@ -743,7 +743,7 @@ Contributors that add or change an example to be published must make sure that - Added more test helper functions - Cleaned MetaFixers and TestRunner - Updated common test output format -- Added ```Install-NugetExe``` to TestHelper.psm1 +- Added ```Install-NuGetExe``` to TestHelper.psm1 - Fixed up Readme.md to remove markdown violations and resolve duplicate information - Added ```AppVeyor.psm1``` module - Added ```DscResource.DocumentationHelper``` modules @@ -795,8 +795,9 @@ Contributors that add or change an example to be published must make sure that - Added new common test so that script files (.ps1) are checked for Byte Order Mark (BOM) ([issue #160](https://github.com/PowerShell/DscResource.Tests/issues/160)). This test is opt-in using .MetaTestOptIn.json. -- Added minimum viable product for applying custom PSSA rules to check adherence to - DSC Resource Kit style guidelines ([issue #86](https://github.com/PowerShell/DscResource.Tests/issues/86)). +- Added minimum viable product for applying custom PS Script Analyzer rules to + check adherence to DSC Resource Kit style guidelines + ([issue #86](https://github.com/PowerShell/DscResource.Tests/issues/86)). The current rules checks the [Parameter()] attribute format is correct in all parameter blocks. - Fixed Byte Order Mark (BOM) in files; DscResource.AnalyzerRules.psd1, DscResource.AnalyzerRules.psm1 and en-US/DscResource.AnalyzerRules.psd1 @@ -840,7 +841,7 @@ Contributors that add or change an example to be published must make sure that - When common tests are running on another repository than DscResource.Tests the DscResource.Tests unit and integration tests are removed from the list of tests to run ([issue #189](https://github.com/PowerShell/DscResource.Tests/issues/189)). -- Fix ModuleVersion number value inserted into manifest in Nuget package produced +- Fix ModuleVersion number value inserted into manifest in NuGet package produced in Invoke-AppveyorAfterTestTask ([issue #193](https://github.com/PowerShell/DscResource.Tests/issues/193)). - Fix TestRunner.Tests.ps1 to make compatible with Pester 4.0.7 ([issue #196](https://github.com/PowerShell/DscResource.Tests/issues/196)). - Improved WikiPages.psm1 to include the EmbeddedInstance to the datatype in the @@ -874,13 +875,13 @@ Contributors that add or change an example to be published must make sure that - Added module DscResource.Container which contain logic to handle the container testing when unit tests are run in a Docker Windows container. - Added Get-OptInStatus function to enable retrieving of an opt-in status - by name. This is required for implementation of PSSA opt-in rules where - the describe block contains multiple opt-ins in a single block. + by name. This is required for implementation of PS Script Analyzer opt-in rules + where the describe block contains multiple opt-ins in a single block. - Added new opt-in flags to allow enforcement of script analyzer rules ([issue #161](https://github.com/PowerShell/DscResource.Tests/issues/161)) - Updated year in DscResources.Tests.psd1 manifest to 2018. - Fixed bug where common test would throw an error if there were no .MetaTestOptIn.json file or it was empty (no opt-ins). -- Added more tests for custom Script Analazyer rules to increased code coverage. +- Added more tests for custom PS Script Analyzer rules to increased code coverage. These new tests call the Measure-functions directly. - Changed so that DscResource.Tests repository can analyze code coverage for the helper modules ([issue #208](https://github.com/PowerShell/DscResource.Tests/issues/208)). @@ -891,7 +892,7 @@ Contributors that add or change an example to be published must make sure that - Changed Get-PSModulePathItem to trim end back slash ([issue #217](https://github.com/PowerShell/DscResource.Tests/issues/217)) - Updated to support running unit tests on PowerShell Core: - Updated helper function Test-FileHasByteOrderMark to use `AsByteStream`. - - Install-PackageProvider will only run if `Find-PackageProvider -Name 'Nuget'` + - Install-PackageProvider will only run if `Find-PackageProvider -Name 'NuGet'` returns a package. Currently it is not found on the AppVeyor build worker for PowerShell Core. - Adding tests to AppVeyor test pane is done by using the RestAPI because the @@ -949,7 +950,7 @@ Contributors that add or change an example to be published must make sure that opt-in ([issue #234](https://github.com/PowerShell/DscResource.Tests/issues/234)). - Added new opt-in common test 'Common Tests - Validate Example Files To Be Published'. This common test verifies that the examples those name ending with '*Config' - passes testing of script meta data, and that there are no duplicate GUID's in + passes testing of script meta data, and that there are no duplicate GUIDs in the script meta data (within the examples in the repository). - Fix bug in `Invoke-AppveyorAfterTestTask` to prevent Wiki generation function from getting documentation files from variable `$MainModulePath` defined in @@ -965,7 +966,7 @@ Contributors that add or change an example to be published must make sure that in unit tests. - Make sure the latest PowerShellGet is installed on the AppVeyor Build Worker ([issue #252](https://github.com/PowerShell/DscResource.Tests/issues/252)). -- Update the example pusblishing example to not use `.EXTERNALMODULEDEPENDENCIES` +- Update the example publishing example to not use `.EXTERNALMODULEDEPENDENCIES` (only #Requires is needed). `.EXTERNALMODULEDEPENDENCIES` is used for external dependencies (outside of PowerShell Gallery). - Example publishing can now use a filename without number prefix @@ -1004,8 +1005,8 @@ Contributors that add or change an example to be published must make sure that ([issue #274](https://github.com/PowerShell/DscResource.Tests/issues/274)). - Excluding tag 'Examples' when calling `Invoke-AppveyorTestScriptTask` since this repository will never have examples. -- Added Rule Name to PS Script Analyzer custom rules -- Added PsScript Analyzer Rule Name to Write-Warning output in meta.tests +- Added Rule Name to PS Script Analyzer custom rules. +- Added PS Script Analyzer Rule Name to Write-Warning output in meta.tests. - Removed sections 'Goals' and 'Git and Unicode' as they have become redundant. - Add a new parameter `-CodeCoveragePath` in the function `Invoke-AppveyorTestScriptTask` to be able to add one or more relative @@ -1022,9 +1023,11 @@ Contributors that add or change an example to be published must make sure that ([issue #188](https://github.com/PowerShell/DscResource.Tests/issues/188)). - Add new opt-in common test for markdown link linting ([issue #211](https://github.com/PowerShell/DscResource.Tests/issues/211)). -* Adding opt-in common test for spellchecking markdown files. Opt-in by +- Adding opt-in common test for spellchecking markdown files. Opt-in by adding "Common Tests - Spellcheck Markdown Files" in the file .MetaTestOptIn.json ([issue #211](https://github.com/PowerShell/DscResource.Tests/issues/211)). +- Opt-in for the test "Common Tests - Spellcheck Markdown Files", and added the + settings file `.vscode\cSpell.json`. ### 0.2.0.0 From dee994c2f9069c6c12c21a26b7c0259dc8b5d5b6 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 10 Aug 2018 19:39:53 +0200 Subject: [PATCH 04/12] Update README.md with description of settings file --- .vscode/cSpell.json | 2 +- Meta.Tests.ps1 | 11 +++++++++ README.md | 56 ++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json index adf21f6c..c4004b04 100644 --- a/.vscode/cSpell.json +++ b/.vscode/cSpell.json @@ -9,7 +9,7 @@ ], "words": [ "markdownlint", - "codecov", + "Codecov", "HQRM", "GUIDs", "unstaged" diff --git a/Meta.Tests.ps1 b/Meta.Tests.ps1 index e824e2ef..50ee429f 100644 --- a/Meta.Tests.ps1 +++ b/Meta.Tests.ps1 @@ -1124,6 +1124,17 @@ Describe 'Common Tests - Spellcheck Files' -Tag 'Spellcheck' { # If the It-block did not pass the test, output the spelling errors. if ($itBlockError.Count -ne 0) { + $message = @" +There were spelling errors. If these are false negatives, then please add the +word or phrase to the settings file '/.vscode/cSpell.json' in the repository. +See this section for more information. +https://github.com/PowerShell/DscResource.Tests/#common-tests-spellcheck-markdownfiles + +"@ + + Write-Host -BackgroundColor Yellow -ForegroundColor Black -Object $message + Write-Host -ForegroundColor White -Object '' + $misspelledErrors = Get-Content -Path $errorFileName foreach ($misspelledError in $misspelledErrors) diff --git a/README.md b/README.md index 4e47a52a..77a71dce 100644 --- a/README.md +++ b/README.md @@ -298,7 +298,61 @@ The following opt-in flags are available: a markdown file is broken. * **Common Tests - Spellcheck Markdown Files**: fail test if there are any spelling errors in the markdown files. There is the possibility to add - or override words in the `.vscode\cSpell.json` file. + or override words in the `\.vscode\cSpell.json` file. + +#### Common Tests - Spellcheck Markdown Files + +When opt-in for this test, if there are any spelling errors in markdown files, +the tests will fail. + +>**Note:** The spell checker is case-insensitive, so the words 'AppVeyor' and +>'appveyor' is equal and both allowed. + +If the spell checker ([cSpell](https://www.npmjs.com/package/cspell)) does not +recognize the word, but the word are correct, or maybe there are a specific phrase +that should always be allowed. Then it possible to add those to a dictionary, or +tell it to ignore words or phrases. + +By adding a file `\.vscode\cSpell.json` in the repository, the spell checker +will follow the settings in this file. + +The simplest form of the file `\.vscode\cSpell.json` is this (see +[cSpell](https://www.npmjs.com/package/cspell) for more settings). + +>This settings file will also work together with the Visual Studio Code extension +>[Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker). +>By using the extension the spelling errors can be caught in real-time. + +```json +{ + "ignorePaths": [ + ".git/*", + ".vscode/*" + ], + "language": "en", + "dictionaries": [ + "powershell" + ], + "words": [ + "markdownlint", + "Codecov" + ], + "ignoreRegExpList": [ + "AppVeyor", + "opencode@microsoft.com", + "\\.gitattributes" + ] +} +``` + +The key `words` should have the words that are normally used when writing text. + +The key `ignoreRegExpList` is better to use to ignore phrases or combination of +words, like 'AppVeyor', it will detect that word as two different words, since +it consist of two words with upper-case letter. +So for it to ignore 'AppVeyor', as we know it's correct, we can add a regular +expression to `ignoreRegExpList`, in this case `AppVeyor`. That will ignore part +of the text that matches the regular expression. #### Common Tests - Validate Markdown Links From bd220d1daab38996a55109b16d7ca8c4c5b591db Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 13 Aug 2018 10:27:39 +0200 Subject: [PATCH 05/12] Add more text about cSpell.json --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 77a71dce..4c0686af 100644 --- a/README.md +++ b/README.md @@ -321,7 +321,13 @@ The simplest form of the file `\.vscode\cSpell.json` is this (see >This settings file will also work together with the Visual Studio Code extension >[Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker). ->By using the extension the spelling errors can be caught in real-time. +>By using this extension the spelling errors can be caught in real-time. +>When a cSpell.json exists in the .vscode folder, the individual setting in the +>cSpell.json file will override the corresponding setting in the +>Visual Studio Code *User settings* or *Workspace settings* file. This differs +>from adding a *Code Spell Checker* setting to the Visual Studio Code +>*Workspace settings* file, as the *Workspace settings* file will override all +>the settings in the *User settings*. ```json { From bfba0c043e95e1109ea1e0a52effb4e16d7a5496 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 13 Aug 2018 21:43:37 +0200 Subject: [PATCH 06/12] Update README.md --- .vscode/cSpell.json | 13 +++++++++++-- README.md | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json index c4004b04..c94daf3b 100644 --- a/.vscode/cSpell.json +++ b/.vscode/cSpell.json @@ -12,7 +12,9 @@ "Codecov", "HQRM", "GUIDs", - "unstaged" + "unstaged", + "PSSA", + "Dism" ], "ignoreRegExpList": [ "AppVeyor", @@ -38,6 +40,13 @@ "2016-Datacenter", "2016-Datacenter-Server-Core", "HKLM:\\\\", - "\\.gitattributes" + "\\.gitattributes", + "#psscriptanalyzer-rules", + "#metafixers-module", + "#testhelper-module", + "#example-usage-of-dscresourcetests-in-appveyoryml", + "#codecoverage-reporting-with-codecovio", + "#enable-reporting-to-codecovio", + "#configure-codecovio" ] } diff --git a/README.md b/README.md index 4c0686af..ea336c73 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ This branch is used by DSC Resource Kit modules for running common tests. - [Encrypt Credentials in Integration Tests](#encrypt-credentials-in-integration-tests) - [CodeCoverage reporting with CodeCov.io](#codecoverage-reporting-with-codecovio) - [Ensure Code Coverage is enabled](#ensure-code-coverage-is-enabled) - - [Enable reporting to CodeCove.io](#enable-reporting-to-codecoveio) + - [Enable reporting to CodeCov.io](#enable-reporting-to-codecovio) - [Configure CodeCov.io](#configure-codecovio) - [Add the badge to the Readme](#add-the-badge-to-the-readme) - [Documentation Helper Module](#documentation-helper-module) @@ -475,7 +475,7 @@ Defaults to the relative paths 'DSCResources', 'DSCClassResources', and 'Modules 1. Make sure you are properly generating pester code coverage in the repository harness code. -### Enable reporting to CodeCove.io +### Enable reporting to CodeCov.io 1. On the call to `Invoke-AppveyorTestScriptTask`, specify `-CodeCovIo`. This will enable reporting to [codecov.io](http://codecov.io) From b5a0acf35df187ecb0935df24696903e2afaeb1e Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Mon, 13 Aug 2018 21:49:30 +0200 Subject: [PATCH 07/12] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ea336c73..b088dbb6 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,7 @@ The following opt-in flags are available: DSC resource module. - **Common Tests - Validate Markdown Links**: fails tests if a link in a markdown file is broken. -* **Common Tests - Spellcheck Markdown Files**: fail test if there are any +- **Common Tests - Spellcheck Markdown Files**: fail test if there are any spelling errors in the markdown files. There is the possibility to add or override words in the `\.vscode\cSpell.json` file. From 279a47735d84efd2b3ff226d706c119bab802d16 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 15 Aug 2018 09:38:27 +0200 Subject: [PATCH 08/12] Changes to README.md - Move section Phased Meta test Opt-In in the README.md, and renamed it to Common Meta test Opt-In (issue #281). --- README.md | 238 +++++++++++++++++++++++++++--------------------------- 1 file changed, 121 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index b088dbb6..3830977b 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,9 @@ This branch is used by DSC Resource Kit modules for running common tests. - [DSC Resource Common Meta Tests](#dsc-resource-common-meta-tests) + - [Common Meta Test Opt-In](#common-meta-test-opt-in) + - [Common Tests - Validate Markdown Links](#common-tests---validate-markdown-links) + - [Common Tests - Spellcheck Markdown Files](#common-tests---spellcheck-markdown-files) - [Markdown Testing](#markdown-testing) - [Example Testing](#example-testing) - [PSScriptAnalyzer Rules](#psscriptanalyzer-rules) @@ -40,8 +43,6 @@ This branch is used by DSC Resource Kit modules for running common tests. - [Example Test Usage](#example-test-usage) - [Example Usage of DSCResource.Tests in AppVeyor.yml](#example-usage-of-dscresourcetests-in-appveyoryml) - [AppVeyor Module](#appveyor-module) - - [Phased Meta test Opt-In](#phased-meta-test-opt-in) - - [Common Tests - Validate Markdown Links](#common-tests---validate-markdown-links) - [Using AppVeyor.psm1 with the default shared model](#using-appveyorpsm1-with-the-default-shared-model) - [Using AppVeyor.psm1 with harness model](#using-appveyorpsm1-with-harness-model) - [Encrypt Credentials in Integration Tests](#encrypt-credentials-in-integration-tests) @@ -63,6 +64,120 @@ This branch is used by DSC Resource Kit modules for running common tests. > Meta.Tests.ps1 +### Common Meta Test Opt-In + +New tests may run but only produce errors. Once you fix the test, please copy +`.MetaTestOptIn.json` from this repo to the root of your repo. If there is +any new problem in the area, this will cause the tests to fail, not just warn. + +The following opt-in flags are available: + +- **Common Tests - Validate Module Files**: run tests to validate module files + have correct BOM. +- **Common Tests - Validate Markdown Files**: run tests to validate markdown + files do not violate markdown rules. Markdown rules can be suppressed in + .markdownlint.json file. +- **Common Tests - Validate Example Files**: run tests to validate that examples + can be compiled without error. +- **Common Tests - Validate Example Files To Be Published**: run tests to + validate that examples can be published successfully to PowerShell Gallery. + See requirements under + [Publish examples to PowerShell Gallery](#publish-examples-to-powershell-gallery). +- **Common Tests - Validate Script Files**: run tests to validate script files + have correct BOM. +- **Common Tests - Required Script Analyzer Rules**: fail tests if any required + script analyzer rules are violated. +- **Common Tests - Flagged Script Analyzer Rules**: fail tests if any flagged + script analyzer rules are violated. +- **Common Tests - New Error-Level Script Analyzer Rules**: fail tests if any + new error-level script analyzer rules are violated. +- **Common Tests - Custom Script Analyzer Rules**: fail tests if any + custom script analyzer rules are violated. +- **Common Tests - Relative Path Length**: fail tests if the length of the + relative full path, from the root of the module, exceeds the max hard limit of + 129 characters. 129 characters is the current (known) maximum for a relative + path to be able to compile a configuration in Azure Automation using a + DSC resource module. +- **Common Tests - Validate Markdown Links**: fails tests if a link in + a markdown file is broken. +- **Common Tests - Spellcheck Markdown Files**: fail test if there are any + spelling errors in the markdown files. There is the possibility to add + or override words in the `\.vscode\cSpell.json` file. + +#### Common Tests - Validate Markdown Links + +The test validates the links in markdown files. Any valid GitHub markdown link +will pass the linter. + +>**NOTE!** There is currently a bug in the markdown link linter that makes it +>unable to recognize absolute paths where the absolute link starts in a parent +>folder. +>For example, if a markdown file `/Examples/README.md`, +>contains an absolute link pointing to `/Examples/Resources/SqlAG`, +>that link will fail the test. Changing the link to a relative link from the +>README.md file's folder, e.g `Resources/SqlAG` will pass the test. +>See issue [vors/MarkdownLinkCheck#5](https://github.com/vors/MarkdownLinkCheck/issues/5). + +#### Common Tests - Spellcheck Markdown Files + +When opt-in for this test, if there are any spelling errors in markdown files, +the tests will fail. + +>**Note:** The spell checker is case-insensitive, so the words 'AppVeyor' and +>'appveyor' is equal and both allowed. + +If the spell checker ([cSpell](https://www.npmjs.com/package/cspell)) does not +recognize the word, but the word are correct, or maybe there are a specific phrase +that should always be allowed. Then it possible to add those to a dictionary, or +tell it to ignore words or phrases. + +By adding a file `\.vscode\cSpell.json` in the repository, the spell checker +will follow the settings in this file. + +The simplest form of the file `\.vscode\cSpell.json` is this (see +[cSpell](https://www.npmjs.com/package/cspell) for more settings). + +>This settings file will also work together with the Visual Studio Code extension +>[Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker). +>By using this extension the spelling errors can be caught in real-time. +>When a cSpell.json exists in the .vscode folder, the individual setting in the +>cSpell.json file will override the corresponding setting in the +>Visual Studio Code *User settings* or *Workspace settings* file. This differs +>from adding a *Code Spell Checker* setting to the Visual Studio Code +>*Workspace settings* file, as the *Workspace settings* file will override all +>the settings in the *User settings*. + +```json +{ + "ignorePaths": [ + ".git/*", + ".vscode/*" + ], + "language": "en", + "dictionaries": [ + "powershell" + ], + "words": [ + "markdownlint", + "Codecov" + ], + "ignoreRegExpList": [ + "AppVeyor", + "opencode@microsoft.com", + "\\.gitattributes" + ] +} +``` + +The key `words` should have the words that are normally used when writing text. + +The key `ignoreRegExpList` is better to use to ignore phrases or combination of +words, like 'AppVeyor', it will detect that word as two different words, since +it consist of two words with upper-case letter. +So for it to ignore 'AppVeyor', as we know it's correct, we can add a regular +expression to `ignoreRegExpList`, in this case `AppVeyor`. That will ignore part +of the text that matches the regular expression. + ### Markdown Testing > .markdownlint.json @@ -260,120 +375,6 @@ This module provides functions for building and testing DSC Resources in AppVeyo keyword in the *appveyor.yml*). - [Publish examples to PowerShell Gallery](#publish-examples-to-powershell-gallery)). -### Phased Meta Test Opt-In - -New tests may run but only produce errors. Once you fix the test, please copy -`.MetaTestOptIn.json` from this repo to the root of your repo. If there is -any new problem in the area, this will cause the tests to fail, not just warn. - -The following opt-in flags are available: - -- **Common Tests - Validate Module Files**: run tests to validate module files - have correct BOM. -- **Common Tests - Validate Markdown Files**: run tests to validate markdown - files do not violate markdown rules. Markdown rules can be suppressed in - .markdownlint.json file. -- **Common Tests - Validate Example Files**: run tests to validate that examples - can be compiled without error. -- **Common Tests - Validate Example Files To Be Published**: run tests to - validate that examples can be published successfully to PowerShell Gallery. - See requirements under - [Publish examples to PowerShell Gallery](#publish-examples-to-powershell-gallery). -- **Common Tests - Validate Script Files**: run tests to validate script files - have correct BOM. -- **Common Tests - Required Script Analyzer Rules**: fail tests if any required - script analyzer rules are violated. -- **Common Tests - Flagged Script Analyzer Rules**: fail tests if any flagged - script analyzer rules are violated. -- **Common Tests - New Error-Level Script Analyzer Rules**: fail tests if any - new error-level script analyzer rules are violated. -- **Common Tests - Custom Script Analyzer Rules**: fail tests if any - custom script analyzer rules are violated. -- **Common Tests - Relative Path Length**: fail tests if the length of the - relative full path, from the root of the module, exceeds the max hard limit of - 129 characters. 129 characters is the current (known) maximum for a relative - path to be able to compile a configuration in Azure Automation using a - DSC resource module. -- **Common Tests - Validate Markdown Links**: fails tests if a link in - a markdown file is broken. -- **Common Tests - Spellcheck Markdown Files**: fail test if there are any - spelling errors in the markdown files. There is the possibility to add - or override words in the `\.vscode\cSpell.json` file. - -#### Common Tests - Spellcheck Markdown Files - -When opt-in for this test, if there are any spelling errors in markdown files, -the tests will fail. - ->**Note:** The spell checker is case-insensitive, so the words 'AppVeyor' and ->'appveyor' is equal and both allowed. - -If the spell checker ([cSpell](https://www.npmjs.com/package/cspell)) does not -recognize the word, but the word are correct, or maybe there are a specific phrase -that should always be allowed. Then it possible to add those to a dictionary, or -tell it to ignore words or phrases. - -By adding a file `\.vscode\cSpell.json` in the repository, the spell checker -will follow the settings in this file. - -The simplest form of the file `\.vscode\cSpell.json` is this (see -[cSpell](https://www.npmjs.com/package/cspell) for more settings). - ->This settings file will also work together with the Visual Studio Code extension ->[Code Spell Checker](https://marketplace.visualstudio.com/items?itemName=streetsidesoftware.code-spell-checker). ->By using this extension the spelling errors can be caught in real-time. ->When a cSpell.json exists in the .vscode folder, the individual setting in the ->cSpell.json file will override the corresponding setting in the ->Visual Studio Code *User settings* or *Workspace settings* file. This differs ->from adding a *Code Spell Checker* setting to the Visual Studio Code ->*Workspace settings* file, as the *Workspace settings* file will override all ->the settings in the *User settings*. - -```json -{ - "ignorePaths": [ - ".git/*", - ".vscode/*" - ], - "language": "en", - "dictionaries": [ - "powershell" - ], - "words": [ - "markdownlint", - "Codecov" - ], - "ignoreRegExpList": [ - "AppVeyor", - "opencode@microsoft.com", - "\\.gitattributes" - ] -} -``` - -The key `words` should have the words that are normally used when writing text. - -The key `ignoreRegExpList` is better to use to ignore phrases or combination of -words, like 'AppVeyor', it will detect that word as two different words, since -it consist of two words with upper-case letter. -So for it to ignore 'AppVeyor', as we know it's correct, we can add a regular -expression to `ignoreRegExpList`, in this case `AppVeyor`. That will ignore part -of the text that matches the regular expression. - -#### Common Tests - Validate Markdown Links - -The test validates the links in markdown files. Any valid GitHub markdown link -will pass the linter. - ->**NOTE!** There is currently a bug in the markdown link linter that makes it ->unable to recognize absolute paths where the absolute link starts in a parent ->folder. ->For example, if a markdown file `/Examples/README.md`, ->contains an absolute link pointing to `/Examples/Resources/SqlAG`, ->that link will fail the test. Changing the link to a relative link from the ->README.md file's folder, e.g `Resources/SqlAG` will pass the test. ->See issue [vors/MarkdownLinkCheck#5](https://github.com/vors/MarkdownLinkCheck/issues/5). - ### Using AppVeyor.psm1 with the default shared model For an example of a AppVeyor.yml file for using the default shared model with a @@ -1067,7 +1068,8 @@ Contributors that add or change an example to be published must make sure that this repository will never have examples. - Added Rule Name to PS Script Analyzer custom rules. - Added PS Script Analyzer Rule Name to Write-Warning output in meta.tests. -- Removed sections 'Goals' and 'Git and Unicode' as they have become redundant. +- Removed sections 'Goals' and 'Git and Unicode' as they have become redundant + ([issue #282](https://github.com/PowerShell/DscResource.Tests/issues/282)). - Add a new parameter `-CodeCoveragePath` in the function `Invoke-AppveyorTestScriptTask` to be able to add one or more relative paths which will be searched for PowerShell modules files (.psm1) to be used @@ -1088,6 +1090,8 @@ Contributors that add or change an example to be published must make sure that .MetaTestOptIn.json ([issue #211](https://github.com/PowerShell/DscResource.Tests/issues/211)). - Opt-in for the test "Common Tests - Spellcheck Markdown Files", and added the settings file `.vscode\cSpell.json`. +- Move section Phased Meta test Opt-In in the README.md, and renamed it to + Common Meta test Opt-In ([issue #281](https://github.com/PowerShell/DscResource.Tests/issues/281)). ### 0.2.0.0 From 223ebdaacf0cf74d0448bfaaad82581b19477eaf Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 17 Aug 2018 09:18:31 +0200 Subject: [PATCH 09/12] Fix spelling --- .vscode/cSpell.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json index c94daf3b..17ea03be 100644 --- a/.vscode/cSpell.json +++ b/.vscode/cSpell.json @@ -14,7 +14,9 @@ "GUIDs", "unstaged", "PSSA", - "Dism" + "Dism", + "vors", + "subfolders" ], "ignoreRegExpList": [ "AppVeyor", From 15d381f97588b6b6faaa98593721e5287a5e6af5 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 17 Aug 2018 09:55:01 +0200 Subject: [PATCH 10/12] Fix review comments at r1 --- Meta.Tests.ps1 | 3 ++- README.md | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Meta.Tests.ps1 b/Meta.Tests.ps1 index 50ee429f..dde5b500 100644 --- a/Meta.Tests.ps1 +++ b/Meta.Tests.ps1 @@ -1082,6 +1082,7 @@ Describe 'Common Tests - Spellcheck Files' -Tag 'Spellcheck' { It 'Should not have spelling errors in any markdown files' -Skip:(!$optIn) { $spellcheckSettingsFilePath = Join-Path -Path $repoRootPath -ChildPath '.vscode\cSpell.json' + if (Test-Path -Path $spellcheckSettingsFilePath) { Write-Info -Message ('Using spellcheck settings file ''{0}''.' -f $spellcheckSettingsFilePath) @@ -1147,7 +1148,7 @@ https://github.com/PowerShell/DscResource.Tests/#common-tests-spellcheck-markdow # Make sure we always remove the file if it exist. if (Test-Path $errorFileName) { - Remove-Item -Path $errorFileName -Force + Remove-Item -Path $errorFileName -Force | Out-Null } } diff --git a/README.md b/README.md index 3830977b..641caa03 100644 --- a/README.md +++ b/README.md @@ -120,21 +120,19 @@ will pass the linter. #### Common Tests - Spellcheck Markdown Files -When opt-in for this test, if there are any spelling errors in markdown files, +When opt-in to this test, if there are any spelling errors in markdown files, the tests will fail. >**Note:** The spell checker is case-insensitive, so the words 'AppVeyor' and ->'appveyor' is equal and both allowed. +>'appveyor' are equal and both are allowed. If the spell checker ([cSpell](https://www.npmjs.com/package/cspell)) does not -recognize the word, but the word are correct, or maybe there are a specific phrase -that should always be allowed. Then it possible to add those to a dictionary, or -tell it to ignore words or phrases. +recognize the word, but the word is correct or a specific phrase is not recognized +but should be allowed, then it is possible to add these to a dictionary or tell it to +ignore the word of phrases. This is done by adding a `\.vscode\cSpell.json` in +the repository. -By adding a file `\.vscode\cSpell.json` in the repository, the spell checker -will follow the settings in this file. - -The simplest form of the file `\.vscode\cSpell.json` is this (see +The following JSON is the simplest form of the file `\.vscode\cSpell.json` (see [cSpell](https://www.npmjs.com/package/cspell) for more settings). >This settings file will also work together with the Visual Studio Code extension @@ -171,12 +169,13 @@ The simplest form of the file `\.vscode\cSpell.json` is this (see The key `words` should have the words that are normally used when writing text. -The key `ignoreRegExpList` is better to use to ignore phrases or combination of -words, like 'AppVeyor', it will detect that word as two different words, since -it consist of two words with upper-case letter. -So for it to ignore 'AppVeyor', as we know it's correct, we can add a regular -expression to `ignoreRegExpList`, in this case `AppVeyor`. That will ignore part -of the text that matches the regular expression. +The key `ignoreRegExpList` is used to ignore phrases or combinations of words, +such as `AppVeyor`, which will be detected as two different words since it consists +of two words starting with upper-case letters. +To configure [cSpell](https://www.npmjs.com/package/cspell) +to ignore the work combination `AppVeyor`, then we can add a regular expression, +in this case `AppVeyor`. This will cause [cSpell](https://www.npmjs.com/package/cspell) +to ignore part of the text that matches the regular expression. ### Markdown Testing From 57ae2fe718e26662c7bd717c2a99ced93f162872 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Fri, 17 Aug 2018 09:57:22 +0200 Subject: [PATCH 11/12] Fx typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 641caa03..a66df83f 100644 --- a/README.md +++ b/README.md @@ -173,7 +173,7 @@ The key `ignoreRegExpList` is used to ignore phrases or combinations of words, such as `AppVeyor`, which will be detected as two different words since it consists of two words starting with upper-case letters. To configure [cSpell](https://www.npmjs.com/package/cspell) -to ignore the work combination `AppVeyor`, then we can add a regular expression, +to ignore the word combination `AppVeyor`, then we can add a regular expression, in this case `AppVeyor`. This will cause [cSpell](https://www.npmjs.com/package/cspell) to ignore part of the text that matches the regular expression. From be07e4274d75b9337e51228c4abe578effe20e20 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Wed, 29 Aug 2018 09:55:43 +0200 Subject: [PATCH 12/12] Fix review comment at r2 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a66df83f..b0fd66cc 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ the tests will fail. If the spell checker ([cSpell](https://www.npmjs.com/package/cspell)) does not recognize the word, but the word is correct or a specific phrase is not recognized but should be allowed, then it is possible to add these to a dictionary or tell it to -ignore the word of phrases. This is done by adding a `\.vscode\cSpell.json` in +ignore the word or phrases. This is done by adding a `\.vscode\cSpell.json` in the repository. The following JSON is the simplest form of the file `\.vscode\cSpell.json` (see