-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix complex multiline examples, refactor test suite (#121) [release]
* Fix comments in code blocks being detected as markdown headers * Initial version of Bootstrap.ps for integration tests * Refactors Powershell7NativeMultiLineCode integration test * Add generic path to bootstrap file * Hardens SeperateHeaders * Refactors CrossVersionCodeExamples integration test * Refactors PlaceholderExamples integration test * Test suite cleanup * Fix PowerShell casing * Fix PowerShell casing * Fix complex code examples as used by Pester * Add tests for SeparateMarkdownHeadings * Rename empty line to blank line * Move module .LINKS to README
- Loading branch information
1 parent
2e23f01
commit 70ff132
Showing
32 changed files
with
695 additions
and
236 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function IndentLineBelowOpeningBracket() { | ||
<# | ||
.SYNOPSIS | ||
Indent line directly below line with opening curly bracket. | ||
.NOTES | ||
Because PlatyPS sometimes gets the indentation wrong with complex examples. | ||
.LINK | ||
https://regex101.com/r/eMCf3E/1 | ||
#> | ||
param( | ||
[Parameter(Mandatory = $True)][System.IO.FileSystemInfo]$MarkdownFile | ||
) | ||
|
||
GetCallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState | ||
|
||
Write-Verbose "Removing blank lines above closing curly bracket" | ||
|
||
$content = ReadFile -MarkdownFile $MarkdownFile | ||
|
||
$regex = [regex]::new('({\n)([^\s+].+)') | ||
|
||
$content = $content -replace $regex, "`$1 `$2" | ||
|
||
# replace file | ||
WriteFile -MarkdownFile $MarkdownFile -Content $content | ||
} |
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,50 @@ | ||
function IndentLineWithOpeningBracket() { | ||
<# | ||
.SYNOPSIS | ||
Corrects indentation for lines with opening curly brackets and incorrect indentation | ||
by comparing indentation of the line below (and recalculating if things are amiss). | ||
.NOTES | ||
Skips correcting if the line below has 4-space indentation | ||
.NOTES | ||
The regex gives us three useful matching groups: | ||
- Group 1 is the full first without the line feed | ||
- Group 2 is the full second line without the line feed | ||
- Group 3 contains the leading spaces of the second line | ||
.LINK | ||
https://regex101.com/r/mT2jLC/1 | ||
#> | ||
param( | ||
[Parameter(Mandatory = $True)][System.IO.FileSystemInfo]$MarkdownFile | ||
) | ||
|
||
GetCallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState | ||
|
||
Write-Verbose "Removing blank lines above closing curly bracket" | ||
|
||
$content = ReadFile -MarkdownFile $MarkdownFile | ||
|
||
$regex = [regex]::new('(?m)^([^\s].+{)\n((\s+)(.+))') | ||
|
||
$callback = { | ||
param($match) | ||
|
||
# do nothing if next line starts with 4 spaces | ||
if ($match.Groups[3].Value.Length -eq 4) { | ||
return $match | ||
} | ||
|
||
# divide spacing of next line by 2 and use that as correct indentation | ||
[string]$fixedIndentation = "" | ||
$fixedIndentation.PadRight(($match.Groups[3].Value.Length / 2 - 1), " ") | ||
|
||
$fixedIndentation + $match.Groups[1] + "`n" + $match.Groups[2] | ||
} | ||
|
||
$content = $regex.replace($content, $callback) | ||
|
||
# replace file | ||
WriteFile -MarkdownFile $MarkdownFile -Content $content | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
function RemoveEmptyLinesAboveClosingBracket() { | ||
<# | ||
.SYNOPSIS | ||
Removes blank lines below lines ending with a closing curly bracket. | ||
.NOTES | ||
Required so following steps can trust formatting. | ||
.LINK | ||
https://regex101.com/r/xvEd2O/1 | ||
#> | ||
param( | ||
[Parameter(Mandatory = $True)][System.IO.FileSystemInfo]$MarkdownFile | ||
) | ||
|
||
GetCallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState | ||
|
||
Write-Verbose "Removing blank lines above closing curly bracket" | ||
|
||
$content = ReadFile -MarkdownFile $MarkdownFile | ||
|
||
$regex = [regex]::new('(\n\n+\s+}|\n\n})') | ||
|
||
$content = $content -replace $regex, "`n}" | ||
|
||
# replace file | ||
WriteFile -MarkdownFile $MarkdownFile -Content $content | ||
} |
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,28 @@ | ||
function RemoveEmptyLinesBelowOpeningBracket() { | ||
<# | ||
.SYNOPSIS | ||
Removes blank lines below lines ending with an opening curly bracket. | ||
.NOTES | ||
Required so following steps can trust formatting. | ||
.LINK | ||
https://regex101.com/r/LlSt8t/1 | ||
#> | ||
param( | ||
[Parameter(Mandatory = $True)][System.IO.FileSystemInfo]$MarkdownFile | ||
) | ||
|
||
GetCallerPreference -Cmdlet $PSCmdlet -SessionState $ExecutionContext.SessionState | ||
|
||
Write-Verbose "Removing blank lines below opening curly bracket" | ||
|
||
$content = ReadFile -MarkdownFile $MarkdownFile | ||
|
||
$regex = [regex]::new('({\n+\n)') | ||
|
||
$content = $content -replace $regex, "{`n" | ||
|
||
# replace file | ||
WriteFile -MarkdownFile $MarkdownFile -Content $content | ||
} |
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: 6 additions & 6 deletions
12
Source/Private/SeparateHeaders.ps1 → Source/Private/SeparateMarkdownHeadings.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<# | ||
.SYNOPSIS | ||
DRY helper for logic shared by all tests. | ||
.NOTES | ||
Every integration test follows the same logic: | ||
- Imports the TestModule | ||
- Uses the Alt-module to generate Docusaurus files in $env:Temp | ||
- Makes sure the generated files exists | ||
- Compares the generated mdx file to the expected mdx | ||
#> | ||
param( | ||
[Parameter(Mandatory = $True)][System.IO.FileInfo]$TestFolder | ||
) | ||
|
||
$test = @{ | ||
Name = $TestFolder.Directory.Name | ||
Folder = $TestFolder.Directory | ||
Module = Join-Path -Path $TestFolder.Directory -ChildPath "TestModule.psm1" | ||
TempFolder = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath $TestFolder.Directory.Name | ||
MdxFile = Join-Path -Path ([System.IO.Path]::GetTempPath()) -ChildPath $TestFolder.Directory.Name | | ||
Join-Path -ChildPath "commands" | | ||
Join-Path -ChildPath "Test-$($TestFolder.Directory.Name).mdx" | ||
} | ||
|
||
# unload the Test-Module | ||
if (Get-Module -Name "TestModule") { | ||
Remove-Module -Name "TestModule" -Force -Verbose:$False | ||
} |
This file was deleted.
Oops, something went wrong.
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
42 changes: 42 additions & 0 deletions
42
Tests/Integration/CrossVersionCodeExamples/Integration.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,42 @@ | ||
BeforeDiscovery { | ||
if (-not(Get-Module Alt3.Docusaurus.PowerShell)) { | ||
throw "Required module 'Alt3.Docusaurus.Powershell' is not loaded." | ||
} | ||
} | ||
|
||
BeforeAll { | ||
. "$((Get-Item -Path $PSCommandPath).Directory.Parent)/Bootstrap.ps1" -TestFolder (Get-Item -Path $PSCommandPath) | ||
Import-Module $test.Module -Force -DisableNameChecking -Verbose:$False -Scope Global | ||
|
||
# generate and read Docusaurus files in $env:Temp | ||
InModuleScope Alt3.Docusaurus.PowerShell -Parameters @{testModule = $test.Module; tempFolder = $test.TempFolder } { | ||
New-DocusaurusHelp -Module $testModule -DocsFolder $tempFolder | ||
} | ||
|
||
$generatedMdx = Get-Content -Path $test.MdxFile | ||
$expectedMdx = Get-Content (Join-Path -Path $test.Folder -ChildPath "Expected.mdx") | ||
} | ||
|
||
Describe "Integration Test to ensure all supported Code Example variants render identically on all PowerShell versions" { | ||
It "Mdx file generated for test should exist" { | ||
$test.MdxFile | Should -Exist | ||
} | ||
|
||
It "Mdx file generated for test should have content" { | ||
$generatedMdx | Should -Not -BeNullOrEmpty | ||
} | ||
|
||
It "Mdx file generated for test should not contain CRLF" { | ||
(Get-Content -Path $test.MdxFile -Raw) -match "`r`n" | Should -Be $False | ||
} | ||
|
||
It "Content of generated mdx file is identical to that of expected fixture" { | ||
$generatedMdx | Should -BeExactly $expectedMdx | ||
} | ||
} | ||
|
||
AfterAll { | ||
if (Get-Module Alt3.Docusaurus.PowerShell) { | ||
Remove-Item $test.TempFolder -Recurse -Force | ||
} | ||
} |
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 @@ | ||
# CrossVersionCodeExamples | ||
|
||
This test assures: | ||
|
||
- That all `Get-Help` examples render identically on **all** PowerShell versions | ||
|
||
Additional information: | ||
|
||
- Logic described at https://github.com/alt3/Docusaurus.PowerShell/issues/14#issuecomment-568552556 |
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
Oops, something went wrong.