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

Pester v5 #26

Merged
merged 4 commits into from
May 29, 2024
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
40 changes: 23 additions & 17 deletions CI/Invoke-Test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,30 @@ param(
)
$srcPath=Resolve-Path -Path "$PSScriptRoot\..\Src"
$outputFile=[System.IO.Path]::GetTempFileName()+".xml"
$splat=@{
Script=$srcPath
PassThru=$true
OutputFormat="NUnitXml"
OutputFile=$outputFile
ExcludeTag=$ExcludeTag
Tag=$Tag
}

# https://pester-docs.netlify.app/docs/commands/New-PesterConfiguration
$pesterConfiguration=New-PesterConfiguration
$pesterConfiguration.Run.Path=$srcPath
$pesterConfiguration.Run.PassThru=$true
$pesterConfiguration.Run.Path=$srcPath
$pesterConfiguration.Filter.Tag=$Tag
$pesterConfiguration.Filter.ExcludeTag=$ExcludeTag

$pesterConfiguration.TestResult.Enabled=$true
$pesterConfiguration.TestResult.OutputFormat="NUnitXml"
$pesterConfiguration.TestResult.OutputPath=$outputFile

$pesterConfiguration.Output.Verbosity="Detailed"
#$pesterConfiguration.Output.Verbosity="Diagnostic"

if($CodeCoverage)
{
$codeCoveragePath=$outputFile.Replace(".xml",".codecoverage.xml")
$splat+=@{
CodeCoverage=Get-ChildItem -Path $srcPath -Exclude @("*.Tests.ps1","*.NotReady.ps1","Src\Tests\**") -Filter "*.ps1" -Recurse|Select-Object -ExpandProperty FullName
CodeCoverageOutputFile=$codeCoveragePath
}
$pesterConfiguration.CodeCoverage.Enabled=$true
# $pesterConfiguration.CodeCoverage.OutputFormat="JaCoCo"
$pesterConfiguration.CodeCoverage.OutputPath=$outputFile.Replace(".xml",".codecoverage.xml")
}

$pesterResult=Invoke-Pester @splat
$pesterResult=Invoke-Pester -Configuration $pesterConfiguration
if($CodeCoverage)
{
$pesterResult|Select-Object @{
Expand All @@ -51,11 +57,11 @@ if($CodeCoverage)
switch($PSCmdlet.ParameterSetName) {
'AppVeyor' {
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", $outputFile)
if ($pesterResult.FailedCount -gt 0) {
throw "$($pesterResult.FailedCount) tests failed."
}
}
'Console' {

}
}
if ($pesterResult.FailedCount -gt 0) {
throw "$($pesterResult.FailedCount) tests failed."
}
2 changes: 1 addition & 1 deletion Demo/Demo.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ $markdown+=Get-Command -Module MarkdownPS | New-MDTable -Columns ([ordered]@{Nam
#endregion

$markdown
$markdown|clip


26 changes: 13 additions & 13 deletions Src/Modules/MarkdownPS/Public/New-MDCharacterStyle.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
BeforeAll {
. $PSCommandPath.Replace('.Tests.ps1', '.ps1')
}

Describe -Tag @("MarkdownPS","Cmdlet","Public") "New-MDCharacterStyle" {
Describe -Tag @("MarkdownPS","Cmdlet","Public","New-MDCharacterStyle") "New-MDCharacterStyle" {
It "-Style Bold" {
$text="Bold characters"
New-MDCharacterStyle -Text $text -Style Bold | Should Be "**$text**"
$text | New-MDCharacterStyle -Style Bold | Should Be "**$text**"
New-MDCharacterStyle -Text $text -Style Bold | Should -Be "**$text**"
$text | New-MDCharacterStyle -Style Bold | Should -Be "**$text**"
}
It "-Style Italic" {
$text="Italic characters"
New-MDCharacterStyle -Text $text -Style Italic | Should Be "*$text*"
$text | New-MDCharacterStyle -Style Italic | Should Be "*$text*"
New-MDCharacterStyle -Text $text -Style Italic | Should -Be "*$text*"
$text | New-MDCharacterStyle -Style Italic | Should -Be "*$text*"
}
It "-Style StrikeThrough" {
$text="Strikethrough characters"
New-MDCharacterStyle -Text $text -Style StrikeThrough | Should Be "~~$text~~"
$text | New-MDCharacterStyle -Style StrikeThrough | Should Be "~~$text~~"
New-MDCharacterStyle -Text $text -Style StrikeThrough | Should -Be "~~$text~~"
$text | New-MDCharacterStyle -Style StrikeThrough | Should -Be "~~$text~~"
}
It "-Style out of range" {
{New-MDCharacterStyle -Text "H" -Style "Invalid"} | Should Throw "The argument ""Invalid"" does not belong to the set ""Bold,Italic,StrikeThrough"" specified by the ValidateSet attribute."
{New-MDCharacterStyle -Text "H" -Style "Invalid"} | Should -Throw "*The argument ""Invalid"" does not belong to the set ""Bold,Italic,StrikeThrough"" specified by the ValidateSet attribute.*"
}
It "-Text null or empty" {
{New-MDCharacterStyle -Text $null -Style Bold} | Should Throw "The argument is null or empty."
{New-MDCharacterStyle -Text "" -Style Bold} | Should Throw "The argument is null or empty."
{New-MDCharacterStyle -Text $null -Style Bold} | Should -Throw "*The argument is null or empty.*"
{New-MDCharacterStyle -Text "" -Style Bold} | Should -Throw "*The argument is null or empty.*"
}

}
44 changes: 23 additions & 21 deletions Src/Modules/MarkdownPS/Public/New-MDCode.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
BeforeAll {
. $PSCommandPath.Replace('.Tests.ps1', '.ps1')
$newLine=[System.Environment]::NewLine
}

$newLine=[System.Environment]::NewLine
Describe -Tag @("MarkdownPS","Cmdlet","Public") "New-MDCode" {
Describe -Tag @("MarkdownPS","Cmdlet","Public","New-MDCode") "New-MDCode" {
It "-Lines is null" {
{New-MDCode -Lines $null} | Should Throw "because it is null."
{New-MDCode -Lines $null} | Should -Throw "*because it is null.*"
}
It "-Lines is empty" {
{New-MDCode -Lines @()} | Should Throw "because it is an empty array."
{New-MDCode -Lines @()} | Should -Throw "*because it is an empty array.*"
}
}
Describe -Tag @("MarkdownPS","Cmdlet","Public") "New-MDCode" {
$prefix="``````"
Describe -Tag @("MarkdownPS","Cmdlet","Public","New-MDCode") "New-MDCode" {
BeforeAll{
$prefix="``````"
}
It "-Lines count is 1 & -Style is not specified" {
$expected=$prefix+$newLine+" Line 1"+$newLine+$prefix+$newLine
New-MDCode -Lines "Line 1" | Should Be $expected
New-MDCode -Lines @("Line 1") | Should Be $expected
"Line 1" | New-MDCode | Should Be $expected
@("Line 1") | New-MDCode | Should Be $expected
New-MDCode -Lines "Line 1" | Should -Be $expected
New-MDCode -Lines @("Line 1") | Should -Be $expected
"Line 1" | New-MDCode | Should -Be $expected
@("Line 1") | New-MDCode | Should -Be $expected
}
It "-Lines count is 2 & -Style not specified" {
$expected=$prefix+$newLine+" Line 1"+$newLine+" Line 2"+$newLine+$prefix+$newLine
New-MDCode -Lines @("Line 1","Line 2") | Should Be $expected
@("Line 1","Line 2") | New-MDCode | Should Be $expected
New-MDCode -Lines @("Line 1","Line 2") | Should -Be $expected
@("Line 1","Line 2") | New-MDCode | Should -Be $expected
}
It "-Lines count is 1 & -Style specified" {
$style="xml"
$expected="$prefix"+$style+$newLine+" Line 1"+$newLine+$prefix+$newLine
New-MDCode -Lines "Line 1" -Style $style | Should Be $expected
New-MDCode -Lines @("Line 1") -Style $style | Should Be $expected
"Line 1" | New-MDCode -Style $style | Should Be $expected
@("Line 1") | New-MDCode -Style $style | Should Be $expected
New-MDCode -Lines "Line 1" -Style $style | Should -Be $expected
New-MDCode -Lines @("Line 1") -Style $style | Should -Be $expected
"Line 1" | New-MDCode -Style $style | Should -Be $expected
@("Line 1") | New-MDCode -Style $style | Should -Be $expected
}
It "-Lines count is 2 & -Level provided" {
$style="javascript"
$expected=$prefix+$style+$newLine+" Line 1"+$newLine+" Line 2"+$newLine+$prefix+$newLine
New-MDCode -Lines @("Line 1","Line 2") -Style $style | Should Be $expected
@("Line 1","Line 2") | New-MDCode -Style $style | Should Be $expected
New-MDCode -Lines @("Line 1","Line 2") -Style $style | Should -Be $expected
@("Line 1","Line 2") | New-MDCode -Style $style | Should -Be $expected
}
}
46 changes: 23 additions & 23 deletions Src/Modules/MarkdownPS/Public/New-MDHeader.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
BeforeAll {
. $PSCommandPath.Replace('.Tests.ps1', '.ps1')
$newLine=[System.Environment]::NewLine
}

$newLine=[System.Environment]::NewLine
Describe -Tag @("MarkdownPS","Cmdlet","Public") "New-MDHeader" {
Describe -Tag @("MarkdownPS","Cmdlet","Public","New-MDHeader") "New-MDHeader" {
It "-Level not provided" {
$expected="# This is an H1" + $newLine
(New-MDHeader -Text "This is an H1") | Should Be $expected
"This is an H1"|New-MDHeader | Should Be $expected
@("This is an H1","This is an H1")|New-MDHeader | Should Be ($expected+$expected)
(New-MDHeader -Text "This is an H1") | Should -Be $expected
"This is an H1"|New-MDHeader | Should -Be $expected
@("This is an H1","This is an H1")|New-MDHeader | Should -Be ($expected+$expected)
}
It "-Level provided" {
New-MDHeader -Text "This is an H1" -Level 1 | Should Be ("# This is an H1"+$newLine)
New-MDHeader -Text "This is an H2" -Level 2 | Should Be ("## This is an H2"+$newLine)
New-MDHeader -Text "This is an H3" -Level 3 | Should Be ("### This is an H3"+$newLine)
New-MDHeader -Text "This is an H4" -Level 4 | Should Be ("#### This is an H4"+$newLine)
New-MDHeader -Text "This is an H5" -Level 5 | Should Be ("##### This is an H5"+$newLine)
New-MDHeader -Text "This is an H6" -Level 6 | Should Be ("###### This is an H6"+$newLine)
"This is an H2"|New-MDHeader -Level 2| Should Be ("## This is an H2"+$newLine)
@("This is an H1","This is an H2")|New-MDHeader -Level 3| Should Be ("### This is an H1"+$newLine+"### This is an H2"+$newLine)
New-MDHeader -Text "This is an H1" -Level 1 | Should -Be ("# This is an H1"+$newLine)
New-MDHeader -Text "This is an H2" -Level 2 | Should -Be ("## This is an H2"+$newLine)
New-MDHeader -Text "This is an H3" -Level 3 | Should -Be ("### This is an H3"+$newLine)
New-MDHeader -Text "This is an H4" -Level 4 | Should -Be ("#### This is an H4"+$newLine)
New-MDHeader -Text "This is an H5" -Level 5 | Should -Be ("##### This is an H5"+$newLine)
New-MDHeader -Text "This is an H6" -Level 6 | Should -Be ("###### This is an H6"+$newLine)
"This is an H2"|New-MDHeader -Level 2| Should -Be ("## This is an H2"+$newLine)
@("This is an H1","This is an H2")|New-MDHeader -Level 3| Should -Be ("### This is an H1"+$newLine+"### This is an H2"+$newLine)
}
It "-NoNewLine defined" {
$expected="# This is an H1"
New-MDHeader -Text "This is an H1" -NoNewLine | Should Be $expected
"This is an H1"|New-MDHeader -NoNewLine | Should Be $expected
@("This is an H1","This is an H1")|New-MDHeader -NoNewLine | Should Be ($expected+$newLine+$expected)
New-MDHeader -Text "This is an H1" -NoNewLine | Should -Be $expected
"This is an H1"|New-MDHeader -NoNewLine | Should -Be $expected
@("This is an H1","This is an H1")|New-MDHeader -NoNewLine | Should -Be ($expected+$newLine+$expected)
}
It "-Text null or empty" {
{New-MDHeader -Text $null } | Should Throw "The argument is null or empty."
{New-MDHeader -Text ""} | Should Throw "The argument is null or empty."
{New-MDHeader -Text $null } | Should -Throw "*The argument is null or empty.*"
{New-MDHeader -Text ""} | Should -Throw "*The argument is null or empty.*"
}
It "-Level out of range" {
{New-MDHeader -Text "H" -Level 0} | Should Throw "The 0 argument is less than the minimum allowed range of 1"
{New-MDHeader -Text "H" -Level 7} | Should Throw "The 7 argument is greater than the maximum allowed range of 6"
{New-MDHeader -Text "H" -Level 0} | Should -Throw "*The 0 argument is less than the minimum allowed range of 1*"
{New-MDHeader -Text "H" -Level 7} | Should -Throw "*The 7 argument is greater than the maximum allowed range of 6*"
}
}
42 changes: 21 additions & 21 deletions Src/Modules/MarkdownPS/Public/New-MDImage.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,82 +1,82 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\New-MDLink.ps1"
. "$here\$sut"
BeforeAll {
. $PSCommandPath.Replace('.Tests.ps1', '.ps1')
. "$PSScriptRoot\New-MDLink.ps1"
}

Describe -Tag @("MarkdownPS","Cmdlet","Public") "New-MDImage" {
Describe -Tag @("MarkdownPS","Cmdlet","Public","New-MDImage") "New-MDImage" {
Context "Parameter set Source" {
It "-Title not specified & -AltTitle not specified" {
$source="http://example.com"
$expected="![]($source)"
New-MDImage -Source $source | Should Be $expected
$source | New-MDImage | Should Be $expected
New-MDImage -Source $source | Should -Be $expected
$source | New-MDImage | Should -Be $expected
}
It "-Title specified & -AltTitle not specified" {
$source="http://example.com"
$title="Image"
$expected="![]($source ""$title"")"
New-MDImage -Source $source -Title $title | Should Be $expected
$source | New-MDImage -Title $title | Should Be $expected
New-MDImage -Source $source -Title $title | Should -Be $expected
$source | New-MDImage -Title $title | Should -Be $expected
}
It "-Title specified & -AltText specified" {
$source="http://example.com"
$title="Image"
$altText="Alt"
$expected="![$altText]($source ""$title"")"
New-MDImage -Source $source -Title $title -AltText $altText | Should Be $expected
$source | New-MDImage -Title $title -AltText $altText | Should Be $expected
New-MDImage -Source $source -Title $title -AltText $altText | Should -Be $expected
$source | New-MDImage -Title $title -AltText $altText | Should -Be $expected
}
It "-Link specified" {
$source="http://example.com"
$link=$source
$expected="[![]($source)]($link)"
New-MDImage -Source $source -Link $link | Should Be $expected
$source | New-MDImage -Link $link | Should Be $expected
New-MDImage -Source $source -Link $link | Should -Be $expected
$source | New-MDImage -Link $link | Should -Be $expected
}
It "-Source null or empty" {
{New-MDImage -Source $null } | Should Throw "The argument is null or empty."
{New-MDImage -Source "" } | Should Throw "The argument is null or empty."
{New-MDImage -Source $null } | Should -Throw "*The argument is null or empty.*"
{New-MDImage -Source "" } | Should -Throw "*The argument is null or empty.*"
}
}
Context "Parameter set Shields.io" {
It "-Subject not specified & -Status not specified" {
$color="green"
$expected="![](https://img.shields.io/badge/--$color.svg)"
New-MDImage -Color $color | Should Be $expected
New-MDImage -Color $color | Should -Be $expected
}
It "-Subject specified & -Status not specified" {
$subject="Subject"
$color="green"
$expected="![](https://img.shields.io/badge/$Subject--$color.svg)"
New-MDImage -Subject $subject -Color $color | Should Be $expected
New-MDImage -Subject $subject -Color $color | Should -Be $expected
}
It "-Subject not specified & -Status specified" {
$status="Status"
$color="green"
$expected="![](https://img.shields.io/badge/-$status-$color.svg)"
New-MDImage -Status $status -Color $color | Should Be $expected
New-MDImage -Status $status -Color $color | Should -Be $expected
}
It "-Subject specified & -Status specified" {
$subject="Subject"
$status="Status"
$color="green"
$expected="![](https://img.shields.io/badge/$subject-$status-$color.svg)"
New-MDImage -Subject $subject -Status $status -Color $color | Should Be $expected
New-MDImage -Subject $subject -Status $status -Color $color | Should -Be $expected
}
It "With special chars" {
$subject="dash-underscore_parenthesis()space ."
$status="dash-underscore_parenthesis()space ."
$color="green"
$expected="![](https://img.shields.io/badge/dash--underscore__parenthesis%28%29space%20.-dash--underscore__parenthesis%28%29space%20.-$color.svg)"
New-MDImage -Subject $subject -Status $status -Color $color | Should Be $expected
New-MDImage -Subject $subject -Status $status -Color $color | Should -Be $expected
}
It "-Link specified" {
$subject="Subject"
$status="Status"
$color="green"
$link="http://example.com"
$expected="[![](https://img.shields.io/badge/$subject-$status-$color.svg)]($link)"
New-MDImage -Subject $subject -Status $status -Color $color -Link $link| Should Be $expected
New-MDImage -Subject $subject -Status $status -Color $color -Link $link| Should -Be $expected
}

}
Expand Down
18 changes: 9 additions & 9 deletions Src/Modules/MarkdownPS/Public/New-MDInlineCode.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path).Replace(".Tests.", ".")
. "$here\$sut"
BeforeAll {
. $PSCommandPath.Replace('.Tests.ps1', '.ps1')
}

Describe -Tag @("MarkdownPS","Cmdlet","Public") "New-MDInlineCode" {
Describe -Tag @("MarkdownPS","Cmdlet","Public","New-MDInlineCode") "New-MDInlineCode" {
It "-Text provided" {
$expected="``Inline``"
New-MDInlineCode -Text "Inline" | Should Be $expected
"Inline"|New-MDInlineCode | Should Be $expected
@("Inline","Inline")|New-MDInlineCode | Should Be @($expected,$expected)
New-MDInlineCode -Text "Inline" | Should -Be $expected
"Inline"|New-MDInlineCode | Should -Be $expected
@("Inline","Inline")|New-MDInlineCode | Should -Be @($expected,$expected)
}
It "-Text null or empty" {
{New-MDInlineCode -Text $null } | Should Throw "The argument is null or empty."
{New-MDInlineCode -Text ""} | Should Throw "The argument is null or empty."
{New-MDInlineCode -Text $null } | Should -Throw "*The argument is null or empty.*"
{New-MDInlineCode -Text ""} | Should -Throw "*The argument is null or empty.*"
}
}
Loading