Skip to content

Commit f1becd5

Browse files
committed
Increase code coverage
Add a few extra tests to make sure we stay above 90%
1 parent eff3c22 commit f1becd5

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Source/Public/Convert-LineNumber.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ function Convert-LineNumber {
3939
$SourceFile = $Invocation.SourceFile
4040
$SourceLineNumber = $Invocation.SourceLineNumber
4141
}
42-
$PSScriptRoot = Split-Path $SourceFile
43-
4442
if(!(Test-Path $SourceFile)) {
4543
throw "'$SourceFile' does not exist"
4644
}
45+
$PSScriptRoot = Split-Path $SourceFile
4746

4847
Push-Location $PSScriptRoot
4948
try {

Tests/Public/Build-Module.Tests.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,37 @@ Describe "Build-Module" {
99
$parameters["SourcePath"].ParameterType | Should -Be ([string])
1010
$parameters["SourcePath"].Attributes.Where{$_ -is [Parameter]}.Mandatory | Should -Be $false
1111
}
12+
It "throws if the SourcePath doesn't exist" {
13+
{ Build-Module -SourcePath TestDrive:\NoSuchPath } | Should -Throw "Source must point to a valid module"
14+
}
1215

1316
It "has an optional string parameter for the OutputDirectory" {
1417
$parameters.ContainsKey("OutputDirectory") | Should -Be $true
1518
$parameters["OutputDirectory"].ParameterType | Should -Be ([string])
1619
$parameters["OutputDirectory"].Attributes.Where{$_ -is [Parameter]}.Mandatory | Should -Be $false
1720
}
1821

19-
It "has an optional parameter for setting the Version"{
22+
It "has an optional parameter for setting the Version" {
2023
$parameters.ContainsKey("Version") | Should -Be $true
2124
$parameters["Version"].ParameterType | Should -Be ([version])
2225
$parameters["Version"].ParameterSets.Keys | Should -Not -Be "__AllParameterSets"
2326
}
2427

25-
It "has an optional parameter for setting the Encoding"{
28+
It "has an optional parameter for setting the Encoding" {
2629
$parameters.ContainsKey("Encoding") | Should -Be $true
2730
# Note that in PS Core, we can't use encoding types for parameters
2831
$parameters["Encoding"].ParameterType | Should -Be ([string])
2932
$parameters["Encoding"].Attributes.Where{$_ -is [Parameter]}.Mandatory | Should -Be $false
3033
}
3134

32-
It "has an optional string parameter for a Prefix"{
35+
It "Warns if you set the encoding to anything but UTF8" {
36+
$warns = @()
37+
# Note: Using WarningAction Stop just to avoid testing anything else here ;)
38+
try { Build-Module -Encoding ASCII -WarningAction Stop -WarningVariable +warns } catch {}
39+
$warns.Message | Should -Match "recommend you build your script modules with UTF8 encoding"
40+
}
41+
42+
It "has an optional string parameter for a Prefix" {
3343
$parameters.ContainsKey("Prefix") | Should -Be $true
3444
$parameters["Prefix"].ParameterType | Should -Be ([string])
3545
$parameters["Prefix"].Attributes.Where{$_ -is [Parameter]}.Mandatory | Should -Be $false

Tests/Public/Convert-LineNumber.Tests.ps1

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ Describe "Convert-LineNumber" {
2626
}
2727
}
2828

29+
It "Should throw if the SourceFile doesn't exist" {
30+
{ Convert-LineNumber -SourceFile TestDrive:\NoSuchFile -SourceLineNumber 10 } | Should Throw "'TestDrive:\NoSuchFile' does not exist"
31+
}
32+
2933
It 'Should work with an error PositionMessage' {
3034
$line = Select-String -Path $ModulePath 'function ParseLineNumber {' | % LineNumber
3135

0 commit comments

Comments
 (0)