Fix tests

This commit is contained in:
Stephen Maunder 2017-11-19 20:08:31 +00:00
parent 587fc5b755
commit 4dface3fa7
2 changed files with 28 additions and 65 deletions

17
.vscode/launch.json vendored
View file

@ -1,17 +1,6 @@
{ {
"version": "0.2.0", "version": "0.2.0",
<<<<<<< HEAD
"configurations": [{ "configurations": [{
=======
"configurations": [
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Interactive Session",
"cwd": "${workspaceRoot}"
},
{
>>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f
"type": "PowerShell", "type": "PowerShell",
"request": "launch", "request": "launch",
"name": "PowerShell Pester Tests", "name": "PowerShell Pester Tests",
@ -26,7 +15,6 @@
"script": "${file}", "script": "${file}",
"args": [], "args": [],
"cwd": "${file}" "cwd": "${file}"
<<<<<<< HEAD
}, },
{ {
"type": "PowerShell", "type": "PowerShell",
@ -43,8 +31,3 @@
} }
] ]
} }
=======
}
]
}
>>>>>>> 13ec3a62ac71275ec2bbe0bbf993130e9f53589f

View file

@ -8,7 +8,7 @@ $manifestFile = "$moduleRoot\SnipeitPS.psd1"
$changelogFile = "$projectRoot\CHANGELOG.md" $changelogFile = "$projectRoot\CHANGELOG.md"
$appveyorFile = "$projectRoot\appveyor.yml" $appveyorFile = "$projectRoot\appveyor.yml"
$publicFunctions = "$moduleRoot\Public" $publicFunctions = "$moduleRoot\Public"
#$internalFunctions = "$moduleRoot\Private" $internalFunctions = "$moduleRoot\Internal"
Describe "SnipeitPS" { Describe "SnipeitPS" {
Context "All required tests are present" { Context "All required tests are present" {
@ -31,18 +31,22 @@ Describe "SnipeitPS" {
$script:manifest = $null $script:manifest = $null
foreach ($line in (Get-Content $changelogFile)) { foreach ($line in (Get-Content $changelogFile))
if ($line -match "^\D*(?<Version>(\d+\.){1,3}\d+)") { {
if ($line -match "^\D*(?<Version>(\d+\.){1,3}\d+)")
{
$changelogVersion = $matches.Version $changelogVersion = $matches.Version
break break
} }
} }
foreach ($line in (Get-Content $appveyorFile)) { foreach ($line in (Get-Content $appveyorFile))
{
# (?<Version>()) - non-capturing group, but named Version. This makes it # (?<Version>()) - non-capturing group, but named Version. This makes it
# easy to reference the inside group later. # easy to reference the inside group later.
if ($line -match '^\D*(?<Version>(\d+\.){1,3}\d+).\{build\}') { if ($line -match '^\D*(?<Version>(\d+\.){1,3}\d+).\{build\}')
{
$appveyorVersion = $matches.Version $appveyorVersion = $matches.Version
break break
} }
@ -99,44 +103,11 @@ Describe "SnipeitPS" {
$appveyorVersion | Should Not BeNullOrEmpty $appveyorVersion | Should Not BeNullOrEmpty
$appveyorVersion -as [Version] | Should Not BeNullOrEmpty $appveyorVersion -as [Version] | Should Not BeNullOrEmpty
} }
}
# The CI changes I'm testng now will render this section obsolete,
# as it should automatically patch the module manifest file with all
# exported function names.
# Leaving the code here for the moment while I can ensure those
# features are working correctly.
#
# Context "Function checking" {
# $functionFiles = Get-ChildItem $publicFunctions -Filter *.ps1 |
# Select-Object -ExpandProperty BaseName |
# Where-Object { $_ -notlike "*.Tests" }
# $internalFiles = Get-ChildItem $privateFunctions -Filter *.ps1 |
# Select-Object -ExpandProperty BaseName |
# Where-Object { $_ -notlike "*.Tests" }
# #$exportedFunctions = $script:manifest.ExportedFunctions.Values.Name
# $exportedFunctions = $script:manifest.FunctionsToExport
# foreach ($f in $functionFiles) {
# It "Exports $f" {
# $exportedFunctions -contains $f | Should Be $true
# }
# }
# foreach ($f in $internalFiles) {
# It "Does not export $f" {
# $exportedFunctions -contains $f | Should Be $false
# }
# }
# }
It "Appveyor version matches manifest version" { It "Appveyor version matches manifest version" {
$appveyorVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] ) $appveyorVersion -as [Version] | Should Be ( $script:manifest.ModuleVersion -as [Version] )
} }
}
# The CI changes I'm testng now will render this section obsolete, # The CI changes I'm testng now will render this section obsolete,
# as it should automatically patch the module manifest file with all # as it should automatically patch the module manifest file with all
@ -182,34 +153,41 @@ Describe "SnipeitPS" {
It 'Source files contain no trailing whitespace' { It 'Source files contain no trailing whitespace' {
$badLines = @( $badLines = @(
foreach ($file in $files) { foreach ($file in $files)
{
$lines = [System.IO.File]::ReadAllLines($file.FullName) $lines = [System.IO.File]::ReadAllLines($file.FullName)
$lineCount = $lines.Count $lineCount = $lines.Count
for ($i = 0; $i -lt $lineCount; $i++) { for ($i = 0; $i -lt $lineCount; $i++)
if ($lines[$i] -match '\s+$') { {
if ($lines[$i] -match '\s+$')
{
'File: {0}, Line: {1}' -f $file.FullName, ($i + 1) 'File: {0}, Line: {1}' -f $file.FullName, ($i + 1)
} }
} }
} }
) )
if ($badLines.Count -gt 0) { if ($badLines.Count -gt 0)
{
throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")" throw "The following $($badLines.Count) lines contain trailing whitespace: `r`n`r`n$($badLines -join "`r`n")"
} }
} }
It 'Source files all end with a newline' { It 'Source files all end with a newline' {
$badFiles = @( $badFiles = @(
foreach ($file in $files) { foreach ($file in $files)
{
$string = [System.IO.File]::ReadAllText($file.FullName) $string = [System.IO.File]::ReadAllText($file.FullName)
if ($string.Length -gt 0 -and $string[-1] -ne "`n") { if ($string.Length -gt 0 -and $string[-1] -ne "`n")
{
$file.FullName $file.FullName
} }
} }
) )
if ($badFiles.Count -gt 0) { if ($badFiles.Count -gt 0)
{
throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")" throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")"
} }
} }
@ -219,9 +197,11 @@ Describe "SnipeitPS" {
$analysis = Invoke-ScriptAnalyzer -Path "$moduleRoot" -Recurse $analysis = Invoke-ScriptAnalyzer -Path "$moduleRoot" -Recurse
$scriptAnalyzerRules = Get-ScriptAnalyzerRule $scriptAnalyzerRules = Get-ScriptAnalyzerRule
forEach ($rule in $scriptAnalyzerRules) { forEach ($rule in $scriptAnalyzerRules)
{
It "Should pass $rule" { It "Should pass $rule" {
If (($analysis) -and ($analysis.RuleName -contains $rule)) { If (($analysis) -and ($analysis.RuleName -contains $rule))
{
$analysis | $analysis |
Where-Object RuleName -EQ $rule -OutVariable failures | Where-Object RuleName -EQ $rule -OutVariable failures |
Out-Default Out-Default