-
Notifications
You must be signed in to change notification settings - Fork 117
Expand file tree
/
Copy pathManifest.tests.ps1
More file actions
96 lines (78 loc) · 3.46 KB
/
Manifest.tests.ps1
File metadata and controls
96 lines (78 loc) · 3.46 KB
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
BeforeAll {
if ($null -eq $env:BHProjectPath) {
$path = Join-Path -Path $PSScriptRoot -ChildPath '..\build.ps1'
. $path -Task Build
}
# NEW: Pre-Specify RegEx Matching Patterns
# Matches semantic versioning with optional pre-release and build metadata
# Examples: 1.0.0, 2.0.0-alpha, 2.0.0-alpha.1, 2.0.0+build.123
$gitTagMatchRegEx = 'tag:\s?.(\d+(?:\.\d+)*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?'
$changelogTagMatchRegEx = "^##\s\[(?<Version>(\d+\.){2}\d+)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?\]"
$moduleName = $env:BHProjectName
$manifest = Import-PowerShellDataFile -Path $env:BHPSModuleManifest
$outputDir = Join-Path -Path $ENV:BHProjectPath -ChildPath 'Output'
$outputModDir = Join-Path -Path $outputDir -ChildPath $env:BHProjectName
$outputModVerDir = Join-Path -Path $outputModDir -ChildPath $manifest.ModuleVersion
$outputManifestPath = Join-Path -Path $outputModVerDir -Child "$($moduleName).psd1"
$manifestData = Test-ModuleManifest -Path $outputManifestPath -Verbose:$false -ErrorAction Stop -WarningAction SilentlyContinue
$changelogPath = Join-Path -Path $env:BHProjectPath -Child 'CHANGELOG.md'
$changelogVersion = Get-Content $changelogPath | ForEach-Object {
if ($_ -match $changelogTagMatchRegEx) {
$changelogVersion = $matches.Version
break
}
}
$script:manifest = $null
}
Describe 'Module manifest' {
Context 'Validation' {
It 'Has a valid manifest' {
$manifestData | Should -Not -BeNullOrEmpty
}
It 'Has a valid name in the manifest' {
$manifestData.Name | Should -Be $moduleName
}
It 'Has a valid root module' {
$manifestData.RootModule | Should -Be "$($moduleName).psm1"
}
It 'Has a valid version in the manifest' {
$manifestData.Version -as [Version] | Should -Not -BeNullOrEmpty
}
It 'Has a valid description' {
$manifestData.Description | Should -Not -BeNullOrEmpty
}
It 'Has a valid author' {
$manifestData.Author | Should -Not -BeNullOrEmpty
}
It 'Has a valid guid' {
{ [guid]::Parse($manifestData.Guid) } | Should -Not -Throw
}
It 'Has a valid copyright' {
$manifestData.CopyRight | Should -Not -BeNullOrEmpty
}
It 'Has a valid version in the changelog' {
$changelogVersion | Should -Not -BeNullOrEmpty
$changelogVersion -as [Version] | Should -Not -BeNullOrEmpty
}
It 'Changelog and manifest versions are the same' {
$changelogVersion -as [Version] | Should -Be ( $manifestData.Version -as [Version] )
}
}
}
Describe 'Git tagging' -Skip {
BeforeAll {
$gitTagVersion = $null
# Ensure to only pull in a single git executable (in case multiple git's are found on path).
if ($git = (Get-Command git -CommandType Application -ErrorAction SilentlyContinue)[0]) {
$thisCommit = & $git log --decorate --oneline HEAD~1..HEAD
if ($thisCommit -match $gitTagMatchRegEx) { $gitTagVersion = $matches[1] }
}
}
It 'Is tagged with a valid version' {
$gitTagVersion | Should -Not -BeNullOrEmpty
$gitTagVersion -as [Version] | Should -Not -BeNullOrEmpty
}
It 'Matches manifest version' {
$manifestData.Version -as [Version] | Should -Be ( $gitTagVersion -as [Version])
}
}