-
Notifications
You must be signed in to change notification settings - Fork 0
/
StructureResource.Tests.ps1
104 lines (88 loc) · 3.13 KB
/
StructureResource.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# This file is derived, in part, from the Pester project. https://github.com/pester/Pester
Import-Module StructuredResource
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
$manifestPath = "$here\StructuredResource.psd1"
$changeLogPath = "$here\CHANGELOG.md"
Describe "manifest and changelog" {
$script:manifest = $null
It "has a valid manifest" {
{
$script:manifest = Test-ModuleManifest -Path $manifestPath -ErrorAction Stop -WarningAction SilentlyContinue
} | Should Not Throw
}
It "has a valid name in the manifest" {
$script:manifest.Name | Should Be StructuredResource
}
It "has a valid guid in the manifest" {
$script:manifest.Guid | Should Be 'ec7c68ce-a7f9-4bb4-b240-c3015356aa61'
}
It "has a valid version in the manifest" {
$script:manifest.Version -as [Version] | Should Not BeNullOrEmpty
}
$script:changelogVersion = $null
It "has a valid version in the changelog" {
foreach ($line in (Get-Content $changeLogPath))
{
if ($line -match "^\D*(?<Version>(\d+\.){1,3}\d+)")
{
$script:changelogVersion = $matches.Version
break
}
}
$script:changelogVersion | Should Not BeNullOrEmpty
$script:changelogVersion -as [Version] | Should Not BeNullOrEmpty
}
It "changelog and manifest versions are the same" {
$script:changelogVersion -as [Version] | Should be ( $script:manifest.Version -as [Version] )
}
}
Describe 'Style rules' {
$moduleRoot = (Get-Module StructuredResource).ModuleBase
$files = @(
Get-ChildItem $moduleRoot -Include *.ps1,*.psm1
@(
'Docs'
'dotNetTypes'
'Functions'
'IntegrationTests'
'TestResourceFunctions'
) |
% { Get-ChildItem "$moduleRoot\$_" -Include *.ps1,*.psm1 -Recurse }
)
It 'Source files contain no trailing whitespace' {
$badLines = @(
foreach ($file in $files)
{
$lines = [System.IO.File]::ReadAllLines($file.FullName)
$lineCount = $lines.Count
for ($i = 0; $i -lt $lineCount; $i++)
{
if ($lines[$i] -match '\s+$')
{
'File: {0}, Line: {1}' -f $file.FullName, ($i + 1)
}
}
}
)
if ($badLines.Count -gt 0)
{
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' {
$badFiles = @(
foreach ($file in $files)
{
$string = [System.IO.File]::ReadAllText($file.FullName)
if ($string.Length -gt 0 -and $string[-1] -ne "`n")
{
$file.FullName
}
}
)
if ($badFiles.Count -gt 0)
{
throw "The following files do not end with a newline: `r`n`r`n$($badFiles -join "`r`n")"
}
}
}