Skip to content

Commit

Permalink
Add regression tests for build.psd1 parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaykul committed Mar 7, 2024
1 parent 704e1fd commit c6a012e
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Tests/Integration/Parameters.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#requires -Module ModuleBuilder
. $PSScriptRoot\..\Convert-FolderSeparator.ps1

Describe "Parameters.Set in build manifest" -Tag Integration {
BeforeAll {
New-Item $PSScriptRoot\Result3\Parameters\ReadMe.md -ItemType File -Force
$Output = Build-Module $PSScriptRoot\Parameters\build.psd1
if ($Output) {
$Module = [IO.Path]::ChangeExtension($Output.Path, "psm1")
$Metadata = Import-Metadata $Output.Path
}
}

It "Passthru works" {
$Output | Should -Not -BeNullOrEmpty
}

It "The Target is Build" {
"$PSScriptRoot\Result3\Parameters\ReadMe.md" | Should -Exist
}

It "The version is set" {
$Metadata.ModuleVersion | Should -Be "3.0.0"
}

It "The PreRelease is set" {
$Metadata.PrivateData.PSData.Prerelease | Should -Be 'alpha001'
}
}
56 changes: 56 additions & 0 deletions Tests/Integration/Parameters/Parameters.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
@{
# The module version should be SemVer.org compatible
ModuleVersion = "1.0.0"

# PrivateData is where all third-party metadata goes
PrivateData = @{
# PrivateData.PSData is the PowerShell Gallery data
PSData = @{
# Prerelease string should be here, so we can set it
Prerelease = ''

# Release Notes have to be here, so we can update them
ReleaseNotes = '
A test module
'

# Tags applied to this module. These help with module discovery in online galleries.
Tags = 'Authoring','Build','Development','BestPractices'

# A URL to the license for this module.
LicenseUri = 'https://github.com/PoshCode/ModuleBuilder/blob/master/LICENSE'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/PoshCode/ModuleBuilder'

# A URL to an icon representing this module.
IconUri = 'https://github.com/PoshCode/ModuleBuilder/blob/resources/ModuleBuilder.png?raw=true'
} # End of PSData
} # End of PrivateData

# The main script module that is automatically loaded as part of this module
RootModule = 'Parameters.psm1'

# Modules that must be imported into the global environment prior to importing this module
RequiredModules = @()

# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
DefaultCommandPrefix = 'Param'

# Always define FunctionsToExport as an empty @() which will be replaced on build
FunctionsToExport = @()
AliasesToExport = @()

# ID used to uniquely identify this module
GUID = 'a264e183-e0f7-4219-bc80-c30d14e0e98e'
Description = 'A module for authoring and building PowerShell modules'

# Common stuff for all our modules:
CompanyName = 'PoshCode'
Author = 'Joel Bennett'
Copyright = "Copyright 2024 Joel Bennett"

# Minimum version of the Windows PowerShell engine required by this module
PowerShellVersion = '5.1'
CompatiblePSEditions = @('Core','Desktop')
}
7 changes: 7 additions & 0 deletions Tests/Integration/Parameters/Private/GetFinale.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using module ModuleBuilder

function GetFinale {
[CmdletBinding()]
# [Alias("gf")]
param()
}
1 change: 1 addition & 0 deletions Tests/Integration/Parameters/Private/GetMyAlias.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
New-Alias -Name 'Get-MyAlias' -Value 'Get-ChildItem'
7 changes: 7 additions & 0 deletions Tests/Integration/Parameters/Private/GetPreview.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using module ModuleBuilder

function GetPreview {
[CmdletBinding()]
# [Alias("gp")]
param()
}
13 changes: 13 additions & 0 deletions Tests/Integration/Parameters/Private/TestUnExportedAliases.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function TestUnExportedAliases {
[CmdletBinding()]
param()

New-Alias -Name 'New-NotExportedAlias1' -Value 'Write-Verbose'
Set-Alias -Name 'New-NotExportedAlias2' -Value 'Write-Verbose'
}

New-Alias -Name 'New-NotExportedAlias3' -Value 'Write-Verbose' -Scope Global
Set-Alias -Name 'New-NotExportedAlias4' -Value 'Write-Verbose' -Scope Global

New-Alias -Name 'New-NotExportedAlias5' -Value 'Write-Verbose'
Remove-Alias -Name 'New-NotExportedAlias5'
7 changes: 7 additions & 0 deletions Tests/Integration/Parameters/Public/Get-Source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using module ModuleBuilder

function Get-Source {
[CmdletBinding()]
[Alias("gs","gsou")]
param()
}
6 changes: 6 additions & 0 deletions Tests/Integration/Parameters/Public/Set-Source.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
function Set-Source {
[CmdletBinding()]
[Alias("ss", "ssou")]
param()
"sto͞o′pĭd"
}
7 changes: 7 additions & 0 deletions Tests/Integration/Parameters/build.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@{
Path = "Parameters.psd1"
OutputDirectory = "..\Result3"
SemVer = "3.0.0-alpha001"
Target = "Build"
Passthru = $true
}
Empty file.

0 comments on commit c6a012e

Please sign in to comment.