Skip to content
Merged
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
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@

## Unreleased

- Fix PositionMessage cannot be found on this object. [#63](https://github.com/BernieWhite/PSDocs/issues/63)
- Fix handling of null metadata hashtable. [#60](https://github.com/BernieWhite/PSDocs/issues/60)

## v0.6.1

- Fix null reference for table columns with undefined properties [#53](https://github.com/BernieWhite/PSDocs/issues/53)
- Fix null reference for table columns with undefined properties. [#53](https://github.com/BernieWhite/PSDocs/issues/53)

## v0.6.0

Expand Down
15 changes: 9 additions & 6 deletions src/PSDocs/PSDocs.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -600,16 +600,17 @@ function Include {
}

function Metadata {

[CmdletBinding()]
param (
[Parameter(Position = 0, Mandatory = $True)]
[AllowNull()]
[System.Collections.IDictionary]$Body
)

process {

# Process eaxch key value pair in the supplied dictionary/hashtable
if ($Null -eq $Body) {
return;
}
# Process each key value pair in the supplied dictionary/hashtable
foreach ($kv in $Body.GetEnumerator()) {
$Document.Metadata[$kv.Key] = $kv.Value;
}
Expand Down Expand Up @@ -1307,8 +1308,10 @@ function InvokeTemplate {
$baseException = $_.Exception.GetBaseException();
$positionMessage = $Null;

if ($baseException -is [System.Management.Automation.IContainsErrorRecord]) {
$positionMessage = $baseException.ErrorRecord.InvocationInfo.PositionMessage
if ($baseException -is [System.Management.Automation.IContainsErrorRecord] -and $Null -ne $baseException.ErrorRecord.InvocationInfo) {
if (![String]::IsNullOrEmpty($baseException.ErrorRecord.InvocationInfo.PositionMessage)) {
$positionMessage = $baseException.ErrorRecord.InvocationInfo.PositionMessage
}
}

throw (New-Object -TypeName PSDocs.Execution.InvokeDocumentException -ArgumentList @(
Expand Down
31 changes: 21 additions & 10 deletions tests/PSDocs.Tests/PSDocs.Metadata.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ $dummyObject = New-Object -TypeName PSObject;
$Global:TestVars = @{ };

Describe 'PSDocs -- Metadata keyword' {

Context 'Metadata single entry' {

# Define a test document with metadata content
document 'MetadataSingleEntry' {

Metadata ([ordered]@{
title = 'Test'
})
Expand All @@ -51,10 +48,8 @@ Describe 'PSDocs -- Metadata keyword' {
}

Context 'Metadata multiple entries' {

# Define a test document with metadata content
document 'MetadataMultipleEntry' {

Metadata ([ordered]@{
value1 = 'ABC'
value2 = 'EFG'
Expand All @@ -74,10 +69,8 @@ Describe 'PSDocs -- Metadata keyword' {
}

Context 'Metadata multiple blocks' {

# Define a test document with metadata content
document 'MetadataMultipleBlock' {

Metadata ([ordered]@{
value1 = 'ABC'
})
Expand All @@ -104,10 +97,8 @@ Describe 'PSDocs -- Metadata keyword' {
}

Context 'Document without Metadata block' {

# Define a test document without metadata content
document 'NoMetdata' {

Section 'Test' {
'A test section.'
}
Expand All @@ -125,8 +116,28 @@ Describe 'PSDocs -- Metadata keyword' {
}
}

Context 'Document null Metadata block' {
# Define a test document with null metadata content
document 'NullMetdata' {
Metadata $Null
Section 'Test' {
'A test section.'
}
}

$outputDoc = "$outputPath\NullMetdata.md";
NullMetdata -InputObject $dummyObject -OutputPath $outputPath;

It 'Should have generated output' {
Test-Path -Path $outputDoc | Should be $True;
}

It 'Should match expected format' {
Get-Content -Path $outputDoc -Raw | Should not match '---\r\n';
}
}

Context 'Get Metadata header' {

$result = Get-PSDocumentHeader -Path $outputPath;

It 'Should have data' {
Expand Down