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

Improve checking of module markdown files in GetMarkdownFilesFromPath #456

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/platyPS/platyPS.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1512,7 +1512,20 @@ function GetMarkdownFilesFromPath
}
}

return $MarkdownFiles
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are going this route of the more intelligent heuristic, we should remove the old dash-based heuristic.

$MarkdownFilesFiltered = @()

If ($IncludeModulePage) {
$MarkdownFilesFiltered = $MarkdownFiles
} Else {
ForEach ($File in $MarkdownFiles) {
$Matches = [regex]::Match((Get-Content $File.FullName -Raw), "# $($File.BaseName) Module").Captures.Groups
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't understand that line, can you add a comment that explains the intention here?

if ($Matches.Length -eq 0) {
$MarkdownFilesFiltered += $File
}
}
}

return $MarkdownFilesFiltered
}

function GetParserMode
Expand Down
84 changes: 84 additions & 0 deletions test/Pester/PlatyPs.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,90 @@ Describe 'New-ExternalHelp' {
$xml = [xml] (Get-Content (Join-Path $TestDrive 'TestOrderFunction.xml'))
$xml.helpItems.namespaceuri | Should Be 'http://msh'
}

It "Checks if external help files are generated correctly" {
New-Item -ItemType Directory -Path (Join-Path $TestDrive "\docs\")
New-Item -ItemType Directory -Path (Join-Path $TestDrive "\en-US\")

Set-Content -Path (Join-Path $TestDrive "\docs\TestModule.md") -Value @'
---
Module Name: TestModule
Module Guid: 3790ec3e-4ec0-41cb-9ebf-ae083b883b74
Download Help Link: https://test.com/release/TestModule/docs/TestModule.md
Help Version: 0.1.0
Locale: en-US
---

# TestModule Module
## Description
Blablablabla

## TestModule Cmdlets
### [Invoke-Test](Invoke-Test.md)
TBD



'@

Set-Content -Path (Join-Path $TestDrive "\docs\Invoke-Test.md") -Value @'
---
external help file: TestModule-help.xml
Module Name: TestModule
online version: https://test.com
schema: 2.0.0
---

# Invoke-Test

## SYNOPSIS
TBD

## SYNTAX

```
Invoke-Test [<CommonParameters>]
```

## DESCRIPTION
TBD

## EXAMPLES

### EXAMPLE 1
```
TBD
```

## PARAMETERS

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).

## INPUTS

## OUTPUTS

## NOTES
Author: Bart

## RELATED LINKS

[https://test.com](https://test.com)


'@
Copy link
Member

Choose a reason for hiding this comment

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

All the "setup" steps in this It should be moved to BeforeAll, especially because the files are used in another It.


(New-ExternalHelp -Path "$TestDrive\docs" -OutputPath "$TestDrive\en-US" -Force)[0].Name | Should Be 'TestModule-help.xml'
}

It "Checks if external help files are generated correctly with dash in module markdown file" {
Rename-Item -Path (Join-Path $TestDrive "\docs\TestModule.md") -NewName "Test-Module.md"
(Get-Content "$TestDrive\docs\Test-Module.md") -replace "TestModule", "Test-Module" | Set-Content "$TestDrive\docs\Test-Module.md"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it needed, why we cannot create it directly?


(New-ExternalHelp -Path "$TestDrive\docs" -OutputPath "$TestDrive\en-US" -Force)[0].Name | Should Be 'TestModule-help.xml'
}
}

Describe 'New-ExternalHelp -ErrorLogFile' {
Expand Down