From d0486674d88c48119d3c20be445e4d0fe5b41eab Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Mon, 20 Sep 2021 15:50:10 -0700 Subject: [PATCH 1/2] Create a publish workflow --- .github/workflows/PesterReports.yml | 55 +- .github/workflows/actions.yml | 15 - .github/workflows/publish.yaml | 24 + .gitignore | 5 +- .vscode/settings.json | 9 +- {src => Plaster}/GetModuleExtension.ps1 | 27 +- {src => Plaster}/GetPlasterTemplate.ps1 | 76 ++- {src => Plaster}/InvokePlaster.ps1 | 4 +- {src => Plaster}/NewPlasterManifest.ps1 | 0 {src => Plaster}/Plaster.psd1 | 0 {src => Plaster}/Plaster.psm1 | 0 .../Schema/PlasterManifest-v1.xsd | 0 .../.vscode/settings.json | 0 .../PSScriptAnalyzerSettings.psd1 | 0 .../plasterManifest.xml | 0 .../NewPowerShellScriptModule/Module.psm1 | 0 .../editor/VSCode/settings.json | 0 .../editor/VSCode/tasks.json | 0 .../plasterManifest.xml | 0 .../test/Module.T.ps1 | 0 {src => Plaster}/TestPlasterManifest.ps1 | 0 {src => Plaster}/en-US/Plaster.Resources.psd1 | 0 build.ps1 | 44 +- build.settings.ps1 | 228 ------- docs/en-US/Get-PlasterTemplate.md | 460 ++++++------- docs/en-US/Invoke-Plaster.md | 356 +++++----- docs/en-US/New-PlasterManifest.md | 608 +++++++++--------- docs/en-US/Test-PlasterManifest.md | 160 ++--- githubactions.yml | 15 - psakeFile.ps1 | 132 ++++ test/ModuleManifest.Tests.ps1 | 9 - test/NewPlasterManifest.Tests.ps1 | 159 ----- test/Shared.ps1 | 37 -- test/TestPlasterManifest.Tests.ps1 | 323 ---------- {test => tests}/ConditionEval.Tests.ps1 | 44 +- .../ExpandFileSourceSpec.Tests.ps1 | 52 +- {test => tests}/GetPlasterTemplate.Tests.ps1 | 25 +- {test => tests}/InvokePlaster.Tests.ps1 | 82 ++- tests/ModuleManifest.Tests.ps1 | 6 + tests/NewPlasterManifest.Tests.ps1 | 177 +++++ test/Recurse/empty.txt => tests/Out/.gitkeep | 0 .../PlasterManifestValidation.Tests.ps1 | 114 ++-- {test => tests}/Recurse/a/b/baz.txt | 0 {test => tests}/Recurse/a/bar.txt | 0 {test => tests}/Recurse/a/c/d/gilead.txt | 0 {test => tests}/Recurse/a/c/test.ini | 0 tests/Recurse/empty.txt | 0 {test => tests}/Recurse/foo.txt | 0 {test => tests}/RequireModule.Tests.ps1 | 106 ++- .../ScriptAnalyzerSettings.psd1 | 0 {test => tests}/TemplateFile.Tests.ps1 | 41 +- tests/TestPlasterManifest.Tests.ps1 | 322 ++++++++++ 52 files changed, 1828 insertions(+), 1887 deletions(-) delete mode 100644 .github/workflows/actions.yml create mode 100644 .github/workflows/publish.yaml rename {src => Plaster}/GetModuleExtension.ps1 (84%) rename {src => Plaster}/GetPlasterTemplate.ps1 (58%) rename {src => Plaster}/InvokePlaster.ps1 (99%) rename {src => Plaster}/NewPlasterManifest.ps1 (100%) rename {src => Plaster}/Plaster.psd1 (100%) rename {src => Plaster}/Plaster.psm1 (100%) rename {src => Plaster}/Schema/PlasterManifest-v1.xsd (100%) rename {src => Plaster}/Templates/AddPSScriptAnalyzerSettings/.vscode/settings.json (100%) rename {src => Plaster}/Templates/AddPSScriptAnalyzerSettings/PSScriptAnalyzerSettings.psd1 (100%) rename {src => Plaster}/Templates/AddPSScriptAnalyzerSettings/plasterManifest.xml (100%) rename {src => Plaster}/Templates/NewPowerShellScriptModule/Module.psm1 (100%) rename {src => Plaster}/Templates/NewPowerShellScriptModule/editor/VSCode/settings.json (100%) rename {src => Plaster}/Templates/NewPowerShellScriptModule/editor/VSCode/tasks.json (100%) rename {src => Plaster}/Templates/NewPowerShellScriptModule/plasterManifest.xml (100%) rename {src => Plaster}/Templates/NewPowerShellScriptModule/test/Module.T.ps1 (100%) rename {src => Plaster}/TestPlasterManifest.ps1 (100%) rename {src => Plaster}/en-US/Plaster.Resources.psd1 (100%) delete mode 100644 build.settings.ps1 delete mode 100644 githubactions.yml create mode 100644 psakeFile.ps1 delete mode 100644 test/ModuleManifest.Tests.ps1 delete mode 100644 test/NewPlasterManifest.Tests.ps1 delete mode 100644 test/Shared.ps1 delete mode 100644 test/TestPlasterManifest.Tests.ps1 rename {test => tests}/ConditionEval.Tests.ps1 (82%) rename {test => tests}/ExpandFileSourceSpec.Tests.ps1 (77%) rename {test => tests}/GetPlasterTemplate.Tests.ps1 (61%) rename {test => tests}/InvokePlaster.Tests.ps1 (67%) create mode 100644 tests/ModuleManifest.Tests.ps1 create mode 100644 tests/NewPlasterManifest.Tests.ps1 rename test/Recurse/empty.txt => tests/Out/.gitkeep (100%) rename {test => tests}/PlasterManifestValidation.Tests.ps1 (81%) rename {test => tests}/Recurse/a/b/baz.txt (100%) rename {test => tests}/Recurse/a/bar.txt (100%) rename {test => tests}/Recurse/a/c/d/gilead.txt (100%) rename {test => tests}/Recurse/a/c/test.ini (100%) create mode 100644 tests/Recurse/empty.txt rename {test => tests}/Recurse/foo.txt (100%) rename {test => tests}/RequireModule.Tests.ps1 (89%) rename ScriptAnalyzerSettings.psd1 => tests/ScriptAnalyzerSettings.psd1 (100%) rename {test => tests}/TemplateFile.Tests.ps1 (61%) create mode 100644 tests/TestPlasterManifest.Tests.ps1 diff --git a/.github/workflows/PesterReports.yml b/.github/workflows/PesterReports.yml index 4ffd40a..4eac96c 100644 --- a/.github/workflows/PesterReports.yml +++ b/.github/workflows/PesterReports.yml @@ -1,8 +1,5 @@ -# This is a basic workflow to help you get started with Actions - name: PesterReports - -# Controls when the action will run. +# Controls when the action will run. on: # Triggers the workflow on push or pull request events but only for the master branch push: @@ -16,12 +13,48 @@ on: # A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: # This workflow contains a single job called "build" - build: - # The type of runner that the job will run on - runs-on: windows-latest - + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Runs pester test reports - - name: pester-tests-report - uses: zyborg/pester-tests-report@v1.5.0 + - uses: actions/checkout@v2 + # Setup Build Helpers + - name: SetupBuildHelpers + shell: pwsh + run: | + Install-Module BuildHelpers -Scope CurrentUser -Force | Out-Null + Install-Module PowerShellBuild -Scope CurrentUser -Force | Out-Null + Install-Module PSScriptAnalyzer -Scope CurrentUser -Force | Out-Null + Install-Module platyPS -Scope CurrentUser -Force | Out-Null + - name: Test + shell: pwsh + run: | + ./build.ps1 -Task Test + - name: Upload Unit Test Results + if: always() + uses: actions/upload-artifact@v2 + with: + name: Unit Test Results (OS ${{ matrix.os }}) + path: ./tests/out/testResults.xml + + publish-test-results: + name: "Publish Unit Tests Results" + needs: test + runs-on: ubuntu-latest + # the test job might be skipped, we don't need to run this job then + if: success() || failure() + + steps: + - name: Download Artifacts + uses: actions/download-artifact@v2 + with: + path: artifacts + + - name: Publish Unit Test Results + uses: EnricoMi/publish-unit-test-result-action@v1 + with: + files: artifacts/**/*.xml diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml deleted file mode 100644 index 6d2e5e7..0000000 --- a/.github/workflows/actions.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Pester -on: - push: - branches: [ master ] -jobs: - test-pwsh: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - name: Run Pester tests - run: | - Set-PSRepository psgallery -InstallationPolicy trusted - Install-Module -Name Pester -RequiredVersion 5.2.1 -Confirm:$false -Force - Invoke-Pester -Path "tests" - shell: pwsh diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml new file mode 100644 index 0000000..e448a12 --- /dev/null +++ b/.github/workflows/publish.yaml @@ -0,0 +1,24 @@ +name: Publish Module +on: + push: + branches: + - master +jobs: + build: + runs-on: windows-latest + steps: + - uses: actions/checkout@v2 + - name: Pre Install Modules + shell: pwsh + run: | + Install-Module BuildHelpers -Scope CurrentUser -Force | Out-Null + Install-Module PowerShellBuild -Scope CurrentUser -Force | Out-Null + Install-Module psake -Scope CurrentUser -Force | Out-Null + Install-Module PSScriptAnalyzer -Scope CurrentUser -Force | Out-Null + Install-Module platyPS -Scope CurrentUser -Force | Out-Null + - name: Build and publish + env: + NUGET_KEY: ${{ secrets.NUGET_KEY }} + shell: pwsh + run: | + ./build.ps1 -Task Publish diff --git a/.gitignore b/.gitignore index 5bb954f..b1b9ce0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.zip Release/ +Output/ examples/Out/* -test/Out/* -test/TemplateRootTemp/* +tests/Out/*.xml +tests/TemplateRootTemp/* diff --git a/.vscode/settings.json b/.vscode/settings.json index 13c2f4d..b76ef60 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,16 +1,15 @@ { //-------- Files configuration -------- - // When enabled, will trim trailing whitespace when you save a file. "files.trimTrailingWhitespace": true, - "search.exclude": { "Release": true }, - //-------- PowerShell Configuration -------- - // Use a custom PowerShell Script Analyzer settings file for this workspace. // Relative paths for this setting are always relative to the workspace root dir. - "powershell.scriptAnalysis.settingsPath": "ScriptAnalyzerSettings.psd1" + "powershell.scriptAnalysis.settingsPath": "ScriptAnalyzerSettings.psd1", + //----------Code Formatting ---------------- + "powershell.codeFormatting.preset": "OTBS", + "editor.formatOnSave": true } \ No newline at end of file diff --git a/src/GetModuleExtension.ps1 b/Plaster/GetModuleExtension.ps1 similarity index 84% rename from src/GetModuleExtension.ps1 rename to Plaster/GetModuleExtension.ps1 index bbf3b1b..29caedd 100644 --- a/src/GetModuleExtension.ps1 +++ b/Plaster/GetModuleExtension.ps1 @@ -6,23 +6,23 @@ function Get-ModuleExtension { [Version] $ModuleVersion, - + [Switch] $ListAvailable ) #Only get the latest version of each module - $modules = Get-Module -ListAvailable + $modules = Get-Module -ListAvailable if (!$ListAvailable) { - $modules = $modules | - Group-Object Name | - Foreach-Object { - $_.group | - Sort-Object Version | - Select-Object -Last 1 - } + $modules = $modules | + Group-Object Name | + Foreach-Object { + $_.group | + Sort-Object Version | + Select-Object -Last 1 + } } - + Write-Verbose "`nFound $($modules.Length) installed modules to scan for extensions." function ParseVersion($versionString) { @@ -39,8 +39,7 @@ function Get-ModuleExtension { if ($PSVersionTable.PSEdition -eq "Core") { $parsedVersion = New-Object -TypeName "System.Management.Automation.SemanticVersion" -ArgumentList $versionString - } - else { + } else { $parsedVersion = New-Object -TypeName "System.Version" -ArgumentList $versionString } } @@ -67,10 +66,10 @@ function Get-ModuleExtension { (!$maximumVersion -or $ModuleVersion -le $maximumVersion)) { # Return a new object with the extension information [PSCustomObject]@{ - Module = $module + Module = $module MinimumVersion = $minimumVersion MaximumVersion = $maximumVersion - Details = $extension.Details + Details = $extension.Details } } } diff --git a/src/GetPlasterTemplate.ps1 b/Plaster/GetPlasterTemplate.ps1 similarity index 58% rename from src/GetPlasterTemplate.ps1 rename to Plaster/GetPlasterTemplate.ps1 index 5085d2e..3f8ebea 100644 --- a/src/GetPlasterTemplate.ps1 +++ b/Plaster/GetPlasterTemplate.ps1 @@ -3,46 +3,46 @@ function Get-PlasterTemplate { [CmdletBinding()] param( - [Parameter(Position=0, - ParameterSetName="Path", - HelpMessage="Specifies a path to a folder containing a Plaster template or multiple template folders. Can also be a path to plasterManifest.xml.")] + [Parameter(Position = 0, + ParameterSetName = "Path", + HelpMessage = "Specifies a path to a folder containing a Plaster template or multiple template folders. Can also be a path to plasterManifest.xml.")] [ValidateNotNullOrEmpty()] [string] $Path, - [Parameter(Position=1, - ParameterSetName="Path", - HelpMessage="Will return templates that match the name.")] - [Parameter(Position=1, - ParameterSetName="IncludedTemplates", - HelpMessage="Will return templates that match the name.")] + [Parameter(Position = 1, + ParameterSetName = "Path", + HelpMessage = "Will return templates that match the name.")] + [Parameter(Position = 1, + ParameterSetName = "IncludedTemplates", + HelpMessage = "Will return templates that match the name.")] [ValidateNotNullOrEmpty()] [string] $Name = "*", - [Parameter(ParameterSetName="Path", - HelpMessage="Will return templates that match the tag.")] - [Parameter(ParameterSetName="IncludedTemplates", - HelpMessage="Will return templates that match the tag.")] + [Parameter(ParameterSetName = "Path", + HelpMessage = "Will return templates that match the tag.")] + [Parameter(ParameterSetName = "IncludedTemplates", + HelpMessage = "Will return templates that match the tag.")] [ValidateNotNullOrEmpty()] [string] $Tag = "*", - [Parameter(ParameterSetName="Path", - HelpMessage="Indicates that this cmdlet gets the items in the specified locations and in all child items of the locations.")] + [Parameter(ParameterSetName = "Path", + HelpMessage = "Indicates that this cmdlet gets the items in the specified locations and in all child items of the locations.")] [switch] $Recurse, - [Parameter(Position=0, - Mandatory=$true, - ParameterSetName="IncludedTemplates", - HelpMessage="Initiates a search for latest version Plaster templates inside of installed modules.")] + [Parameter(Position = 0, + Mandatory = $true, + ParameterSetName = "IncludedTemplates", + HelpMessage = "Initiates a search for latest version Plaster templates inside of installed modules.")] [switch] [Alias("IncludeModules")] $IncludeInstalledModules, - - [Parameter(ParameterSetName="IncludedTemplates", - HelpMessage="If specified, searches for Plaster templates inside of all installed module versions.")] + + [Parameter(ParameterSetName = "IncludedTemplates", + HelpMessage = "If specified, searches for Plaster templates inside of all installed module versions.")] [switch] $ListAvailable ) @@ -54,17 +54,17 @@ function Get-PlasterTemplate { $metadata = $manifestXml["plasterManifest"]["metadata"] $manifestObj = [PSCustomObject]@{ - Name = $metadata["name"].InnerText - Title = $metadata["title"].InnerText - Author = $metadata["author"].InnerText - Version = New-Object -TypeName "System.Version" -ArgumentList $metadata["version"].InnerText - Description = $metadata["description"].InnerText - Tags = $metadata["tags"].InnerText.split(",") | % { $_.Trim() } + Name = $metadata["name"].InnerText + Title = $metadata["title"].InnerText + Author = $metadata["author"].InnerText + Version = New-Object -TypeName "System.Version" -ArgumentList $metadata["version"].InnerText + Description = $metadata["description"].InnerText + Tags = $metadata["tags"].InnerText.split(",") | ForEach-Object { $_.Trim() } TemplatePath = $manifestPath.Directory.FullName } $manifestObj.PSTypeNames.Insert(0, "Microsoft.PowerShell.Plaster.PlasterTemplate") - Add-Member -MemberType ScriptMethod -InputObject $manifestObj -Name "InvokePlaster" -Value {Invoke-Plaster -TemplatePath $this.TemplatePath} + Add-Member -MemberType ScriptMethod -InputObject $manifestObj -Name "InvokePlaster" -Value { Invoke-Plaster -TemplatePath $this.TemplatePath } return $manifestObj | Where-Object Name -like $name | Where-Object Tags -like $tag } @@ -85,34 +85,32 @@ function Get-PlasterTemplate { # Use Test-PlasterManifest to load the manifest file Write-Verbose "Attempting to get Plaster template at path: $Path" CreateTemplateObjectFromManifest $Path $Name $Tag - } - else { + } else { Write-Verbose "Attempting to get Plaster templates recursively under path: $Path" GetManifestsUnderPath $Path $Recurse.IsPresent $Name $Tag } - } - else { + } else { # Return all templates included with Plaster GetManifestsUnderPath "$PSScriptRoot\Templates" $true $Name $Tag if ($IncludeInstalledModules.IsPresent) { # Search for templates in module path $GetModuleExtensionParams = @{ - ModuleName = "Plaster" + ModuleName = "Plaster" ModuleVersion = $PlasterVersion ListAvailable = $ListAvailable } - + $extensions = Get-ModuleExtension @GetModuleExtensionParams foreach ($extension in $extensions) { # Scan all module paths registered in the module foreach ($templatePath in $extension.Details.TemplatePaths) { $expandedTemplatePath = - [System.IO.Path]::Combine( - $extension.Module.ModuleBase, - $templatePath, - "plasterManifest.xml") + [System.IO.Path]::Combine( + $extension.Module.ModuleBase, + $templatePath, + "plasterManifest.xml") CreateTemplateObjectFromManifest $expandedTemplatePath $Name $Tag -ErrorAction SilentlyContinue } diff --git a/src/InvokePlaster.ps1 b/Plaster/InvokePlaster.ps1 similarity index 99% rename from src/InvokePlaster.ps1 rename to Plaster/InvokePlaster.ps1 index a107ab8..7b0644d 100644 --- a/src/InvokePlaster.ps1 +++ b/Plaster/InvokePlaster.ps1 @@ -79,7 +79,7 @@ function Invoke-Plaster { return } - $manifest = Plaster\Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null + $manifest = Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null # The user-defined parameters in the Plaster manifest are converted to dynamic parameters # which allows the user to provide the parameters via the command line. @@ -179,7 +179,7 @@ function Invoke-Plaster { } if (Test-Path -LiteralPath $manifestPath -PathType Leaf) { - $manifest = Plaster\Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null + $manifest = Test-PlasterManifest -Path $manifestPath -ErrorAction Stop 3>$null $PSCmdlet.WriteDebug("In begin, loading manifest file '$manifestPath'") } else { diff --git a/src/NewPlasterManifest.ps1 b/Plaster/NewPlasterManifest.ps1 similarity index 100% rename from src/NewPlasterManifest.ps1 rename to Plaster/NewPlasterManifest.ps1 diff --git a/src/Plaster.psd1 b/Plaster/Plaster.psd1 similarity index 100% rename from src/Plaster.psd1 rename to Plaster/Plaster.psd1 diff --git a/src/Plaster.psm1 b/Plaster/Plaster.psm1 similarity index 100% rename from src/Plaster.psm1 rename to Plaster/Plaster.psm1 diff --git a/src/Schema/PlasterManifest-v1.xsd b/Plaster/Schema/PlasterManifest-v1.xsd similarity index 100% rename from src/Schema/PlasterManifest-v1.xsd rename to Plaster/Schema/PlasterManifest-v1.xsd diff --git a/src/Templates/AddPSScriptAnalyzerSettings/.vscode/settings.json b/Plaster/Templates/AddPSScriptAnalyzerSettings/.vscode/settings.json similarity index 100% rename from src/Templates/AddPSScriptAnalyzerSettings/.vscode/settings.json rename to Plaster/Templates/AddPSScriptAnalyzerSettings/.vscode/settings.json diff --git a/src/Templates/AddPSScriptAnalyzerSettings/PSScriptAnalyzerSettings.psd1 b/Plaster/Templates/AddPSScriptAnalyzerSettings/PSScriptAnalyzerSettings.psd1 similarity index 100% rename from src/Templates/AddPSScriptAnalyzerSettings/PSScriptAnalyzerSettings.psd1 rename to Plaster/Templates/AddPSScriptAnalyzerSettings/PSScriptAnalyzerSettings.psd1 diff --git a/src/Templates/AddPSScriptAnalyzerSettings/plasterManifest.xml b/Plaster/Templates/AddPSScriptAnalyzerSettings/plasterManifest.xml similarity index 100% rename from src/Templates/AddPSScriptAnalyzerSettings/plasterManifest.xml rename to Plaster/Templates/AddPSScriptAnalyzerSettings/plasterManifest.xml diff --git a/src/Templates/NewPowerShellScriptModule/Module.psm1 b/Plaster/Templates/NewPowerShellScriptModule/Module.psm1 similarity index 100% rename from src/Templates/NewPowerShellScriptModule/Module.psm1 rename to Plaster/Templates/NewPowerShellScriptModule/Module.psm1 diff --git a/src/Templates/NewPowerShellScriptModule/editor/VSCode/settings.json b/Plaster/Templates/NewPowerShellScriptModule/editor/VSCode/settings.json similarity index 100% rename from src/Templates/NewPowerShellScriptModule/editor/VSCode/settings.json rename to Plaster/Templates/NewPowerShellScriptModule/editor/VSCode/settings.json diff --git a/src/Templates/NewPowerShellScriptModule/editor/VSCode/tasks.json b/Plaster/Templates/NewPowerShellScriptModule/editor/VSCode/tasks.json similarity index 100% rename from src/Templates/NewPowerShellScriptModule/editor/VSCode/tasks.json rename to Plaster/Templates/NewPowerShellScriptModule/editor/VSCode/tasks.json diff --git a/src/Templates/NewPowerShellScriptModule/plasterManifest.xml b/Plaster/Templates/NewPowerShellScriptModule/plasterManifest.xml similarity index 100% rename from src/Templates/NewPowerShellScriptModule/plasterManifest.xml rename to Plaster/Templates/NewPowerShellScriptModule/plasterManifest.xml diff --git a/src/Templates/NewPowerShellScriptModule/test/Module.T.ps1 b/Plaster/Templates/NewPowerShellScriptModule/test/Module.T.ps1 similarity index 100% rename from src/Templates/NewPowerShellScriptModule/test/Module.T.ps1 rename to Plaster/Templates/NewPowerShellScriptModule/test/Module.T.ps1 diff --git a/src/TestPlasterManifest.ps1 b/Plaster/TestPlasterManifest.ps1 similarity index 100% rename from src/TestPlasterManifest.ps1 rename to Plaster/TestPlasterManifest.ps1 diff --git a/src/en-US/Plaster.Resources.psd1 b/Plaster/en-US/Plaster.Resources.psd1 similarity index 100% rename from src/en-US/Plaster.Resources.psd1 rename to Plaster/en-US/Plaster.Resources.psd1 diff --git a/build.ps1 b/build.ps1 index 632433c..19b4abe 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,4 +1,44 @@ #Requires -Modules psake +[cmdletbinding(DefaultParameterSetName = 'Task')] +param( + # Build task(s) to execute + [parameter(ParameterSetName = 'task', position = 0)] + [string[]]$Task = 'default', -# Builds the module by invoking psake on the build.psake.ps1 script. -Invoke-PSake $PSScriptRoot\build.psake.ps1 -taskList Build + # Bootstrap dependencies + [switch]$Bootstrap, + + # List available build tasks + [parameter(ParameterSetName = 'Help')] + [switch]$Help, + + # Optional properties to pass to psake + [hashtable]$Properties, + + # Optional parameters to pass to psake + [hashtable]$Parameters +) + +$ErrorActionPreference = 'Stop' + +# Execute psake task(s) +$psakeFile = "$PSScriptRoot\psakeFile.ps1" +if ($PSCmdlet.ParameterSetName -eq 'Help') { + Get-PSakeScriptTasks -buildFile $psakeFile | + Format-Table -Property Name, Description, Alias, DependsOn +} else { + Set-BuildEnvironment -Force + $parameters = @{} + if ($PSGalleryApiKey) { + $parameters['galleryApiKey'] = $PSGalleryApiKey + } + $psake_splat = @{ + buildFile = $psakeFile + taskList = $Task + nologo = $True + properties = $Properties + parameters = $Parameters + } + Invoke-PSake @psake_splat + exit ([int](-not $psake.build_success)) +} \ No newline at end of file diff --git a/build.settings.ps1 b/build.settings.ps1 deleted file mode 100644 index 5da0d49..0000000 --- a/build.settings.ps1 +++ /dev/null @@ -1,228 +0,0 @@ -############################################################################### -# Customize these properties and tasks for your module. -############################################################################### - -Properties { - # ----------------------- Basic properties -------------------------------- - - # The root directories for the module's docs, src and test. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $DocsRootDir = "$PSScriptRoot\docs" - $SrcRootDir = "$PSScriptRoot\src" - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $TestRootDir = "$PSScriptRoot\test" - - # The name of your module should match the basename of the PSD1 file. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $ModuleName = Get-Item $SrcRootDir/*.psd1 | - Where-Object { $null -ne (Test-ModuleManifest -Path $_ -ErrorAction SilentlyContinue) } | - Select-Object -First 1 | Foreach-Object BaseName - - # The $OutDir is where module files and updatable help files are staged for signing, install and publishing. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $OutDir = "$PSScriptRoot\Release" - - # The local installation directory for the install task. Defaults to your home Modules location. - # The test for $profile is for the Plaster AppVeyor build machine since it doesn't define $profile. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $InstallPath = Join-Path (Split-Path $(if ($profile) {$profile} else {$Home}) -Parent) ` - "Modules\$ModuleName\$((Test-ModuleManifest -Path $SrcRootDir\$ModuleName.psd1).Version.ToString())" - - # Default Locale used for help generation, defaults to en-US. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $DefaultLocale = 'en-US' - - # Items in the $Exclude array will not be copied to the $OutDir e.g. $Exclude = @('.gitattributes') - # Typically you wouldn't put any file under the src dir unless the file was going to ship with - # the module. However, if there are such files, add their $SrcRootDir relative paths to the exclude list. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $Exclude = @() - - # ------------------ Script analysis properties --------------------------- - - # Enable/disable use of PSScriptAnalyzer to perform script analysis. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $ScriptAnalysisEnabled = $false - - # When PSScriptAnalyzer is enabled, control which severity level will generate a build failure. - # Valid values are Error, Warning, Information and None. "None" will report errors but will not - # cause a build failure. "Error" will fail the build only on diagnostic records that are of - # severity error. "Warning" will fail the build on Warning and Error diagnostic records. - # "Any" will fail the build on any diagnostic record, regardless of severity. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - [ValidateSet('Error', 'Warning', 'Any', 'None')] - $ScriptAnalysisFailBuildOnSeverityLevel = 'Error' - - # Path to the PSScriptAnalyzer settings file. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $ScriptAnalyzerSettingsPath = "$PSScriptRoot\ScriptAnalyzerSettings.psd1" - - # ------------------- Script signing properties --------------------------- - - # Set to $true if you want to sign your scripts. You will need to have a code-signing certificate. - # You can specify the certificate's subject name below. If not specified, you will be prompted to - # provide either a subject name or path to a PFX file. After this one time prompt, the value will - # saved for future use and you will no longer be prompted. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $ScriptSigningEnabled = $false - - # Specify the Subject Name of the certificate used to sign your scripts. Leave it as $null and the - # first time you build, you will be prompted to enter your code-signing certificate's Subject Name. - # This variable is used only if $SignScripts is set to $true. - # - # This does require the code-signing certificate to be installed to your certificate store. If you - # have a code-signing certificate in a PFX file, install the certificate to your certificate store - # with the command below. You may be prompted for the certificate's password. - # - # Import-PfxCertificate -FilePath .\myCodeSigingCert.pfx -CertStoreLocation Cert:\CurrentUser\My - # - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $CertSubjectName = $null - - # Certificate store path. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $CertPath = "Cert:\" - - # -------------------- File catalog properties ---------------------------- - - # Enable/disable generation of a catalog (.cat) file for the module. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $CatalogGenerationEnabled = $true - - # Select the hash version to use for the catalog file: 1 for SHA1 (compat with Windows 7 and - # Windows Server 2008 R2), 2 for SHA2 to support only newer Windows versions. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $CatalogVersion = 2 - - # ---------------------- Testing properties ------------------------------- - - # Enable/disable Pester code coverage reporting. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $CodeCoverageEnabled = $true - - # CodeCoverageFiles specifies the files to perform code coverage analysis on. This property - # acts as a direct input to the Pester -CodeCoverage parameter, so will support constructions - # like the ones found here: https://github.com/pester/Pester/wiki/Code-Coverage. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $CodeCoverageFiles = "$SrcRootDir\*.ps1", "$SrcRootDir\*.psm1" - - # -------------------- Publishing properties ------------------------------ - - # Your NuGet API key for the PSGallery. Leave it as $null and the first time you publish, - # you will be prompted to enter your API key. The build will store the key encrypted in the - # settings file, so that on subsequent publishes you will no longer be prompted for the API key. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $NuGetApiKey = $null - - # Name of the repository you wish to publish to. If $null is specified the default repo (PowerShellGallery) is used. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $PublishRepository = $null - - # Path to the release notes file. Set to $null if the release notes reside in the manifest file. - # The contents of this file are used during publishing for the ReleaseNotes parameter. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $ReleaseNotesPath = "$PSScriptRoot\ReleaseNotes.md" - - # ----------------------- Misc properties --------------------------------- - - # In addition, PFX certificates are supported in an interactive scenario only, - # as a way to import a certificate into the user personal store for later use. - # This can be provided using the CertPfxPath parameter. PFX passwords will not be stored. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $SettingsPath = "$env:LOCALAPPDATA\Plaster\NewModuleTemplate\SecuredBuildSettings.clixml" - - # Specifies an output file path to send to Invoke-Pester's -OutputFile parameter. - # This is typically used to write out test results so that they can be sent to a CI - # system like AppVeyor. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $TestOutputFile = $null - - # Specifies the test output format to use when the TestOutputFile property is given - # a path. This parameter is passed through to Invoke-Pester's -OutputFormat parameter. - [System.Diagnostics.CodeAnalysis.SuppressMessage('PSUseDeclaredVarsMoreThanAssigments', '')] - $TestOutputFormat = "NUnitXml" -} - -############################################################################### -# Customize these tasks for performing operations before and/or after file staging. -############################################################################### - -# Executes before the StageFiles task. -Task BeforeStageFiles { -} - -# Executes after the StageFiles task. -Task AfterStageFiles { -} - -############################################################################### -# Customize these tasks for performing operations before and/or after Build. -############################################################################### - -# Executes before the BeforeStageFiles phase of the Build task. -Task BeforeBuild { -} - -# Executes after the Build task. -Task AfterBuild { -} - -############################################################################### -# Customize these tasks for performing operations before and/or after BuildHelp. -############################################################################### - -# Executes before the BuildHelp task. -Task BeforeBuildHelp { -} - -# Executes after the BuildHelp task. -Task AfterBuildHelp { -} - -############################################################################### -# Customize these tasks for performing operations before and/or after BuildUpdatableHelp. -############################################################################### - -# Executes before the BuildUpdatableHelp task. -Task BeforeBuildUpdatableHelp { -} - -# Executes after the BuildUpdatableHelp task. -Task AfterBuildUpdatableHelp { -} - -############################################################################### -# Customize these tasks for performing operations before and/or after GenerateFileCatalog. -############################################################################### - -# Executes before the GenerateFileCatalog task. -Task BeforeGenerateFileCatalog { -} - -# Executes after the GenerateFileCatalog task. -Task AfterGenerateFileCatalog { -} - -############################################################################### -# Customize these tasks for performing operations before and/or after Install. -############################################################################### - -# Executes before the Install task. -Task BeforeInstall { -} - -# Executes after the Install task. -Task AfterInstall { -} - -############################################################################### -# Customize these tasks for performing operations before and/or after Publish. -############################################################################### - -# Executes before the Publish task. -Task BeforePublish { -} - -# Executes after the Publish task. -Task AfterPublish { -} diff --git a/docs/en-US/Get-PlasterTemplate.md b/docs/en-US/Get-PlasterTemplate.md index 902fd9a..36a7711 100644 --- a/docs/en-US/Get-PlasterTemplate.md +++ b/docs/en-US/Get-PlasterTemplate.md @@ -1,229 +1,231 @@ ---- -external help file: Plaster-help.xml -Module Name: Plaster -online version: https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Get-PlasterTemplate.md -schema: 2.0.0 ---- - -# Get-PlasterTemplate - -## SYNOPSIS -Retrieves a list of available Plaster templates that can be used with the Invoke-Plaster -cmdlet. - -## SYNTAX - -### Path -``` -Get-PlasterTemplate [[-Path] ] [[-Name] ] [-Tag ] [-Recurse] [] -``` - -### IncludedTemplates -``` -Get-PlasterTemplate [[-Name] ] [-Tag ] [-IncludeInstalledModules] [-ListAvailable] - [] -``` - -## DESCRIPTION -Retrieves a list of available Plaster templates from the specified path or from -the set of templates that are shipped with Plaster. Specifying no arguments will -cause only the built-in Plaster templates to be returned. Using the -IncludeInstalledModules -switch will also search the PSModulePath for PowerShell modules that advertise -Plaster templates that they include. By default, this retrieves the latest version available -for each module. Using the -ListAvailable parameter will return all templates from all module -versions installed on this computer. Using the -Name parameter limits the results based on name. -Using the -Tag parameter limits the results based on the template tags. - - -The objects returned from this cmdlet will provide details about each individual -template that was retrieved. Use the TemplatePath property of a template object as -the input to Invoke-Plaster's -TemplatePath parameter. - -## EXAMPLES - -### Example 1 -``` -PS C:\> $templates = Get-PlasterTemplate - -PS C:\> Invoke-Plaster -TemplatePath $templates[0].TemplatePath -DestinationPath ~\GitHub\NewModule -``` - -This will get the list of built-in Plaster templates. The first template returned is then used to -create a new module at the specifed path. - -### Example 2 -``` -PS C:\> $templates = Get-PlasterTemplate -IncludeInstalledModules - -PS C:\> Invoke-Plaster -TemplatePath $templates[0].TemplatePath -DestinationPath ~\GitHub\NewModule -``` - -This will get a list of Plaster templates, both built-in and included with installed -modules. The first template returned is then used to create a new module at -the specifed path. - -### Example 3 -``` -PS C:\> $templates = Get-PlasterTemplate -Path c:\MyPlasterTemplates -Recurse - -PS C:\> Invoke-Plaster -TemplatePath $templates[0].TemplatePath -DestinationPath ~\GitHub\NewModule -``` - -This will get a list of Plaster templates found recursively under c:\MyPlasterTemplates -The first template returned is then used to create a new module at the specifed path. - -### Example 4 -``` -PS C:\> $template = Get-PlasterTemplate -Name NewPowerShellScriptModule - -PS C:\> Invoke-Plaster -TemplatePath $template.TemplatePath -DestinationPath ~\GitHub\NewModule -``` - -This will get the built-in Plaster template with the name NewPowerShellScriptModule. -It will then use that template to create a new module at the specified path. - -### Example 5 -``` -PS C:\> $templates = Get-PlasterTemplate -IncludeInstalledModules -Name new* - -PS C:\> Invoke-Plaster -TemplatePath $templates[0].TemplatePath -DestinationPath ~\GitHub\NewModule -``` - -This will get a list of Plaster templates, both built-in and included with installed -modules, where the name matches 'new*'. -It will then use the first template found to create a new module at the specified path. - -### Example 6 -``` -PS C:\> $templates = Get-PlasterTemplate -IncludeInstalledModules -tag module* - -PS C:\> $templates[0].InvokePlaster() -``` - -This will get a list of Plaster templates, both built-in and included with installed -modules, where the name matches 'module*'. -It will then use the first template found to create a new module at the specified path -using the InvokePlaster script method that is available on the returned object. - -## PARAMETERS - -### -IncludeInstalledModules -Initiates a search for Plaster templates inside of installed modules. - -```yaml -Type: SwitchParameter -Parameter Sets: IncludedTemplates -Aliases: IncludeModules - -Required: True -Position: 0 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -ListAvailable -If specified, searches for Plaster templates inside of all installed module versions.```yaml -Type: SwitchParameter -Parameter Sets: IncludedTemplates -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Name -Limits the templates returned to those that match the template name. Wildcard characters are permitted. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 1 -Default value: * -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Path -Specifies a path to a folder containing a Plaster template or multiple template folders. -Can also be a path to plasterManifest.xml. - -```yaml -Type: String -Parameter Sets: Path -Aliases: - -Required: False -Position: 0 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Recurse -Indicates that this cmdlet gets the items in the specified locations and in all child items of the locations. - -```yaml -Type: SwitchParameter -Parameter Sets: Path -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Tag -Limits the templates returned to those that match the template tags. Wildcard characters are permitted. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: * -Accept pipeline input: False -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### System.String -The first positional parameter is a filesystem path under which templates might be -found. The -Recurse switch will cause this path to be searched recursively. - -## OUTPUTS - -### System.Object -This output object provides the following properties: - -- Name: The name of the template -- Title: The title of the template -- Author: The author of the template -- Version: The version of the template -- Description: Text describing the template and what it creates -- Tags: A list of tag strings which categorize the template -- TemplatePath: The template's folder path in the filesystem - -This output object provides the following methods: - -- InvokePlaster(): Runs Invoke-Plaster against the template - -## NOTES - -## RELATED LINKS - -[Invoke-Plaster](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Invoke-Plaster.md) +--- +external help file: Plaster-help.xml +Module Name: Plaster +online version: https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Get-PlasterTemplate.md +schema: 2.0.0 +--- + +# Get-PlasterTemplate + +## SYNOPSIS +Retrieves a list of available Plaster templates that can be used with the Invoke-Plaster +cmdlet. + +## SYNTAX + +### Path +``` +Get-PlasterTemplate [[-Path] ] [[-Name] ] [-Tag ] [-Recurse] [] +``` + +### IncludedTemplates +``` +Get-PlasterTemplate [[-Name] ] [-Tag ] [-IncludeInstalledModules] [-ListAvailable] + [] +``` + +## DESCRIPTION +Retrieves a list of available Plaster templates from the specified path or from +the set of templates that are shipped with Plaster. Specifying no arguments will +cause only the built-in Plaster templates to be returned. Using the -IncludeInstalledModules +switch will also search the PSModulePath for PowerShell modules that advertise +Plaster templates that they include. By default, this retrieves the latest version available +for each module. Using the -ListAvailable parameter will return all templates from all module +versions installed on this computer. Using the -Name parameter limits the results based on name. +Using the -Tag parameter limits the results based on the template tags. + + +The objects returned from this cmdlet will provide details about each individual +template that was retrieved. Use the TemplatePath property of a template object as +the input to Invoke-Plaster's -TemplatePath parameter. + +## EXAMPLES + +### Example 1 +``` +PS C:\> $templates = Get-PlasterTemplate + +PS C:\> Invoke-Plaster -TemplatePath $templates[0].TemplatePath -DestinationPath ~\GitHub\NewModule +``` + +This will get the list of built-in Plaster templates. The first template returned is then used to +create a new module at the specifed path. + +### Example 2 +``` +PS C:\> $templates = Get-PlasterTemplate -IncludeInstalledModules + +PS C:\> Invoke-Plaster -TemplatePath $templates[0].TemplatePath -DestinationPath ~\GitHub\NewModule +``` + +This will get a list of Plaster templates, both built-in and included with installed +modules. The first template returned is then used to create a new module at +the specifed path. + +### Example 3 +``` +PS C:\> $templates = Get-PlasterTemplate -Path c:\MyPlasterTemplates -Recurse + +PS C:\> Invoke-Plaster -TemplatePath $templates[0].TemplatePath -DestinationPath ~\GitHub\NewModule +``` + +This will get a list of Plaster templates found recursively under c:\MyPlasterTemplates +The first template returned is then used to create a new module at the specifed path. + +### Example 4 +``` +PS C:\> $template = Get-PlasterTemplate -Name NewPowerShellScriptModule + +PS C:\> Invoke-Plaster -TemplatePath $template.TemplatePath -DestinationPath ~\GitHub\NewModule +``` + +This will get the built-in Plaster template with the name NewPowerShellScriptModule. +It will then use that template to create a new module at the specified path. + +### Example 5 +``` +PS C:\> $templates = Get-PlasterTemplate -IncludeInstalledModules -Name new* + +PS C:\> Invoke-Plaster -TemplatePath $templates[0].TemplatePath -DestinationPath ~\GitHub\NewModule +``` + +This will get a list of Plaster templates, both built-in and included with installed +modules, where the name matches 'new*'. +It will then use the first template found to create a new module at the specified path. + +### Example 6 +``` +PS C:\> $templates = Get-PlasterTemplate -IncludeInstalledModules -tag module* + +PS C:\> $templates[0].InvokePlaster() +``` + +This will get a list of Plaster templates, both built-in and included with installed +modules, where the name matches 'module*'. +It will then use the first template found to create a new module at the specified path +using the InvokePlaster script method that is available on the returned object. + +## PARAMETERS + +### -IncludeInstalledModules +Initiates a search for Plaster templates inside of installed modules. + +```yaml +Type: SwitchParameter +Parameter Sets: IncludedTemplates +Aliases: IncludeModules + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ListAvailable +If specified, searches for Plaster templates inside of all installed module versions. + +```yaml +Type: SwitchParameter +Parameter Sets: IncludedTemplates +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Name +Limits the templates returned to those that match the template name. Wildcard characters are permitted. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: * +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +Specifies a path to a folder containing a Plaster template or multiple template folders. +Can also be a path to plasterManifest.xml. + +```yaml +Type: String +Parameter Sets: Path +Aliases: + +Required: False +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Recurse +Indicates that this cmdlet gets the items in the specified locations and in all child items of the locations. + +```yaml +Type: SwitchParameter +Parameter Sets: Path +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Tag +Limits the templates returned to those that match the template tags. Wildcard characters are permitted. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: * +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String +The first positional parameter is a filesystem path under which templates might be +found. The -Recurse switch will cause this path to be searched recursively. + +## OUTPUTS + +### System.Object +This output object provides the following properties: + +- Name: The name of the template +- Title: The title of the template +- Author: The author of the template +- Version: The version of the template +- Description: Text describing the template and what it creates +- Tags: A list of tag strings which categorize the template +- TemplatePath: The template's folder path in the filesystem + +This output object provides the following methods: + +- InvokePlaster(): Runs Invoke-Plaster against the template + +## NOTES + +## RELATED LINKS + +[Invoke-Plaster](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Invoke-Plaster.md) diff --git a/docs/en-US/Invoke-Plaster.md b/docs/en-US/Invoke-Plaster.md index 7aa8773..94f3ffa 100644 --- a/docs/en-US/Invoke-Plaster.md +++ b/docs/en-US/Invoke-Plaster.md @@ -1,178 +1,178 @@ ---- -external help file: Plaster-help.xml -Module Name: Plaster -online version: https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Invoke-Plaster.md -schema: 2.0.0 ---- - -# Invoke-Plaster - -## SYNOPSIS -Invokes the specified Plaster template which will scaffold out a file or a set of files and directories. - -## SYNTAX - -``` -Invoke-Plaster [-TemplatePath] [-DestinationPath] [-Force] [-NoLogo] [-PassThru] [-WhatIf] - [-Confirm] [] -``` - -## DESCRIPTION -Invokes the specified Plaster template which will scaffold out a file or a -set of files and directories. - -## EXAMPLES - -### -------------------------- EXAMPLE 1 -------------------------- -``` -Invoke-Plaster -TemplatePath . -Destination ~\GitHub\NewModule -``` - -This will invoke the Plaster template in the current directory. -The template will generate any files and -directories in the ~\GitHub\NewModule directory. - -### -------------------------- EXAMPLE 2 -------------------------- -``` -Invoke-Plaster -TemplatePath . -Destination ~\GitHub\NewModule -ModuleName Foo -Version 1.0.0 -``` - -This will invoke the Plaster template in the current directory using dynamic -parameters ModuleName and Version extracted from the parameters section of -the manifest file. The template will generate any files and directories in -the ~\GitHub\NewModule directory. - -Note: The parameters -ModuleName and -Version are dynamically added from the plaster manifest file in the current directory. If you run this command it may fail if the manifest file you are testing with does not contain these parameters. - -## PARAMETERS - -### -Confirm -Prompts you for confirmation before running the cmdlet. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: cf - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -DestinationPath -Specifies the path to directory in which the template will use as a root directory when generating files. -If the directory does not exist, it will be created. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 1 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Force -Specify Force to override user prompts for conflicting handling. -This will override the confirmation -prompt and allow the template to overwrite existing files. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: False -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -NoLogo -Suppresses the display of the Plaster logo. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: False -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -PassThru -Returns an InvokePlasterInfo object with the following fields: - -* TemplatePath -* DestinationPath -* Success -* CreatedFiles -* UpdatedFiles -* MissingModules - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -TemplatePath -Specifies the path to the template directory. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 0 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -WhatIf -Shows what would happen if the cmdlet runs. -The cmdlet is not run. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: wi - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -## OUTPUTS - -## NOTES - -## RELATED LINKS - -[New-PlasterManifest](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/New-PlasterManifest.md) -[Test-PlasterManifest](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Test-PlasterManifest.md) - +--- +external help file: Plaster-help.xml +Module Name: Plaster +online version: https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Invoke-Plaster.md +schema: 2.0.0 +--- + +# Invoke-Plaster + +## SYNOPSIS +Invokes the specified Plaster template which will scaffold out a file or a set of files and directories. + +## SYNTAX + +``` +Invoke-Plaster [-TemplatePath] [-DestinationPath] [-Force] [-NoLogo] [-PassThru] [-WhatIf] + [-Confirm] [] +``` + +## DESCRIPTION +Invokes the specified Plaster template which will scaffold out a file or a +set of files and directories. + +## EXAMPLES + +### EXAMPLE 1 +``` +Invoke-Plaster -TemplatePath . -Destination ~\GitHub\NewModule +``` + +This will invoke the Plaster template in the current directory. +The template will generate any files and +directories in the ~\GitHub\NewModule directory. + +### EXAMPLE 2 +``` +Invoke-Plaster -TemplatePath . -Destination ~\GitHub\NewModule -ModuleName Foo -Version 1.0.0 +``` + +This will invoke the Plaster template in the current directory using dynamic +parameters ModuleName and Version extracted from the parameters section of +the manifest file. The template will generate any files and directories in +the ~\GitHub\NewModule directory. + +Note: The parameters -ModuleName and -Version are dynamically added from the plaster manifest file in the current directory. If you run this command it may fail if the manifest file you are testing with does not contain these parameters. + +## PARAMETERS + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -DestinationPath +Specifies the path to directory in which the template will use as a root directory when generating files. +If the directory does not exist, it will be created. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Force +Specify Force to override user prompts for conflicting handling. +This will override the confirmation +prompt and allow the template to overwrite existing files. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoLogo +Suppresses the display of the Plaster logo. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -PassThru +Returns an InvokePlasterInfo object with the following fields: + +* TemplatePath +* DestinationPath +* Success +* CreatedFiles +* UpdatedFiles +* MissingModules + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TemplatePath +Specifies the path to the template directory. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS + +[New-PlasterManifest](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/New-PlasterManifest.md) +[Test-PlasterManifest](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Test-PlasterManifest.md) + diff --git a/docs/en-US/New-PlasterManifest.md b/docs/en-US/New-PlasterManifest.md index 24e60e7..eb79d22 100644 --- a/docs/en-US/New-PlasterManifest.md +++ b/docs/en-US/New-PlasterManifest.md @@ -1,304 +1,304 @@ ---- -external help file: Plaster-help.xml -Module Name: Plaster -online version: https://github.com/PowerShell/Plaster/blob/master/docs/en-US/New-PlasterManifest.md -schema: 2.0.0 ---- - -# New-PlasterManifest - -## SYNOPSIS -Creates a new Plaster template manifest file. - -## SYNTAX - -``` -New-PlasterManifest [[-Path] ] [-TemplateName] [-TemplateType] [[-Id] ] - [[-TemplateVersion] ] [[-Title] ] [[-Description] ] [[-Tags] ] - [[-Author] ] [-AddContent] [-WhatIf] [-Confirm] [] -``` - -## DESCRIPTION -The New-PlasterManifest command creates a new Plaster manifest file, -populates its values, and saves the manifest file in the specified path. - -Template authors can use this command to create a manifest for their -template. A template manifest is a file named plasterManifest.xml or -plasterManifest_\.xml. The information stored in the manifest -is used to scaffold files and folders. - -The metadata section of the manifest is used to supply information about the -template e.g. a unique id, name, version, title, author and tags. - -The parameters section of the manifest is used to describe choices the -template user can choose from. Those choices are then used to conditionally -create files and folders and modify existing files under the specified -destination path. - -The content section is used to specify what actions the template will perform -under the user's chosen destination directory. This includes copying files to -the destination, copy & expanding template files, modifying files, verifying -required modules are installed and displaying messages to the user. - -See the help topic about_Plaster_CreatingAManifest for more details on -authoring a Plaster manifest file. - -## EXAMPLES - -### -------------------------- EXAMPLE 1 -------------------------- -``` -New-PlasterManifest -TemplateName NewPowerShellItem -TemplateType Item -``` - -Creates a basic plasterManifest.xml file in the current directory. - -### -------------------------- EXAMPLE 2 -------------------------- -``` -New-PlasterManifest -TemplateName NewPowerShellItem -TemplateType Item -TemplateVersion 0.1.0 -Description "Some description." -Tags Module, Publish,Build -``` - -Creates a plasterManifest.xml file in the current directory with the version set to 0.1.0 and with the -Description and Tags elements populated. - -### -------------------------- EXAMPLE 3 -------------------------- -``` -New-PlasterManifest -TemplateName NewPowerShellItem -TemplateType Item -AddContent -``` - -Creates a plasterManifest.xml file in the current directory with the content element filled in with all the -files (except for any plasterManifest files) in and below the specified directory which defaults to the -current directory. - -## PARAMETERS - -### -AddContent -If specified, the contents of the directory the manifest is being created in will be added to the -manifest's content element. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: - -Required: False -Position: Named -Default value: False -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Author -Specifies the author of the template. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 8 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Confirm -Prompts you for confirmation before running the cmdlet. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: cf - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Description -Description of the Plaster template. -This describes what the the template is for. -It is typically used in -an editor like VSCode when displaying additional information about a Plaster template. -A typical title might be "Creates files required for a PowerShell module with optional support for Pester -tests, building with psake and publishing to the PowerShell Gallery." - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 6 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Id -Unique identifier for all versions of this template. -The id is a GUID. -Use the same id for each version -of your template. -This will prevent editor environments from listing multiple, installed versions of your -template. -When you keep your template id the same, the editor will list only the latest version of your -template. - -```yaml -Type: Guid -Parameter Sets: (All) -Aliases: - -Required: False -Position: 3 -Default value: [guid]::NewGuid() -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Path -Specifies the path and file name of the new Plaster manifest. -Enter a path and file name with a .xml -extension, such as $pshome\Modules\MyPlasterTemplate\plasterManifest.xml. -NOTE: Plaster requires the manifest -file be named either plasterManifest.xml OR plasterManifest_\.xml e.g. -plasterManifest_fr-FR.xml. -The default, if no value is provided is to create plasterManifest.xml in the current directory. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 0 -Default value: "$pwd\plasterManifest.xml" -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Tags -Specifies an array of tags for the template. -Users can search for templates based on these tags. - -```yaml -Type: String[] -Parameter Sets: (All) -Aliases: - -Required: False -Position: 7 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -TemplateName -Specifies the name of the template. -A template name is required. -For localized manifests, this value -should not be localized. -The name is limited to the characters: aA-zZ0-9_-. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: True -Position: 1 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -TemplateType -Defines the type of template. Valid values are: Project and Item. This value -is used by editor extensions like the PowerShell extension for Visual Studio -Code to determine if the template expects to create a whole new project in an -empty workspace or if it adds an item to an existing workspace. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: -Accepted values: Item, Project - -Required: True -Position: 2 -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -TemplateVersion -Specifies the version of the template. - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 4 -Default value: 1.0.0 -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -Title -Title of the Plaster template. -This string is typically used in an editor like VSCode when displaying -a list of Plaster templates. -A typical title might be "New DSC Resource" or "New PowerShell Module". - -```yaml -Type: String -Parameter Sets: (All) -Aliases: - -Required: False -Position: 5 -Default value: $Name -Accept pipeline input: False -Accept wildcard characters: False -``` - -### -WhatIf -Shows what would happen if the cmdlet runs. -The cmdlet is not run. - -```yaml -Type: SwitchParameter -Parameter Sets: (All) -Aliases: wi - -Required: False -Position: Named -Default value: None -Accept pipeline input: False -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### None -You cannot pipe input to this cmdlet. - -## OUTPUTS - -### None - -## NOTES - -## RELATED LINKS - -[Invoke-Plaster](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Invoke-Plaster.md) -[Test-PlasterManifest](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Test-PlasterManifest.md) - +--- +external help file: Plaster-help.xml +Module Name: Plaster +online version: https://github.com/PowerShell/Plaster/blob/master/docs/en-US/New-PlasterManifest.md +schema: 2.0.0 +--- + +# New-PlasterManifest + +## SYNOPSIS +Creates a new Plaster template manifest file. + +## SYNTAX + +``` +New-PlasterManifest [[-Path] ] [-TemplateName] [-TemplateType] [[-Id] ] + [[-TemplateVersion] ] [[-Title] ] [[-Description] ] [[-Tags] ] + [[-Author] ] [-AddContent] [-WhatIf] [-Confirm] [] +``` + +## DESCRIPTION +The New-PlasterManifest command creates a new Plaster manifest file, +populates its values, and saves the manifest file in the specified path. + +Template authors can use this command to create a manifest for their +template. A template manifest is a file named plasterManifest.xml or +plasterManifest_\.xml. The information stored in the manifest +is used to scaffold files and folders. + +The metadata section of the manifest is used to supply information about the +template e.g. a unique id, name, version, title, author and tags. + +The parameters section of the manifest is used to describe choices the +template user can choose from. Those choices are then used to conditionally +create files and folders and modify existing files under the specified +destination path. + +The content section is used to specify what actions the template will perform +under the user's chosen destination directory. This includes copying files to +the destination, copy & expanding template files, modifying files, verifying +required modules are installed and displaying messages to the user. + +See the help topic about_Plaster_CreatingAManifest for more details on +authoring a Plaster manifest file. + +## EXAMPLES + +### EXAMPLE 1 +``` +New-PlasterManifest -TemplateName NewPowerShellItem -TemplateType Item +``` + +Creates a basic plasterManifest.xml file in the current directory. + +### EXAMPLE 2 +``` +New-PlasterManifest -TemplateName NewPowerShellItem -TemplateType Item -TemplateVersion 0.1.0 -Description "Some description." -Tags Module, Publish,Build +``` + +Creates a plasterManifest.xml file in the current directory with the version set to 0.1.0 and with the +Description and Tags elements populated. + +### EXAMPLE 3 +``` +New-PlasterManifest -TemplateName NewPowerShellItem -TemplateType Item -AddContent +``` + +Creates a plasterManifest.xml file in the current directory with the content element filled in with all the +files (except for any plasterManifest files) in and below the specified directory which defaults to the +current directory. + +## PARAMETERS + +### -AddContent +If specified, the contents of the directory the manifest is being created in will be added to the +manifest's content element. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Author +Specifies the author of the template. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 8 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Confirm +Prompts you for confirmation before running the cmdlet. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: cf + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Description +Description of the Plaster template. +This describes what the the template is for. +It is typically used in +an editor like VSCode when displaying additional information about a Plaster template. +A typical title might be "Creates files required for a PowerShell module with optional support for Pester +tests, building with psake and publishing to the PowerShell Gallery." + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 6 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Id +Unique identifier for all versions of this template. +The id is a GUID. +Use the same id for each version +of your template. +This will prevent editor environments from listing multiple, installed versions of your +template. +When you keep your template id the same, the editor will list only the latest version of your +template. + +```yaml +Type: Guid +Parameter Sets: (All) +Aliases: + +Required: False +Position: 3 +Default value: [guid]::NewGuid() +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +Specifies the path and file name of the new Plaster manifest. +Enter a path and file name with a .xml +extension, such as $pshome\Modules\MyPlasterTemplate\plasterManifest.xml. +NOTE: Plaster requires the manifest +file be named either plasterManifest.xml OR plasterManifest_\.xml e.g. +plasterManifest_fr-FR.xml. +The default, if no value is provided is to create plasterManifest.xml in the current directory. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 0 +Default value: "$pwd\plasterManifest.xml" +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Tags +Specifies an array of tags for the template. +Users can search for templates based on these tags. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: 7 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TemplateName +Specifies the name of the template. +A template name is required. +For localized manifests, this value +should not be localized. +The name is limited to the characters: aA-zZ0-9_-. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TemplateType +Defines the type of template. Valid values are: Project and Item. This value +is used by editor extensions like the PowerShell extension for Visual Studio +Code to determine if the template expects to create a whole new project in an +empty workspace or if it adds an item to an existing workspace. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: +Accepted values: Item, Project + +Required: True +Position: 2 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -TemplateVersion +Specifies the version of the template. + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 4 +Default value: 1.0.0 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Title +Title of the Plaster template. +This string is typically used in an editor like VSCode when displaying +a list of Plaster templates. +A typical title might be "New DSC Resource" or "New PowerShell Module". + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 5 +Default value: $Name +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WhatIf +Shows what would happen if the cmdlet runs. +The cmdlet is not run. + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: wi + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None +You cannot pipe input to this cmdlet. + +## OUTPUTS + +### None + +## NOTES + +## RELATED LINKS + +[Invoke-Plaster](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Invoke-Plaster.md) +[Test-PlasterManifest](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Test-PlasterManifest.md) + diff --git a/docs/en-US/Test-PlasterManifest.md b/docs/en-US/Test-PlasterManifest.md index 3d8f43d..9fed78c 100644 --- a/docs/en-US/Test-PlasterManifest.md +++ b/docs/en-US/Test-PlasterManifest.md @@ -1,80 +1,80 @@ ---- -external help file: Plaster-help.xml -Module Name: Plaster -online version: https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Test-PlasterManifest.md -schema: 2.0.0 ---- - -# Test-PlasterManifest - -## SYNOPSIS -Verifies that a plaster manifest file is a valid. - -## SYNTAX - -``` -Test-PlasterManifest [[-Path] ] [] -``` - -## DESCRIPTION -Verifies that a plaster manifest file is a valid. -If there are any errors, the details of the errors can be viewed by using the -Verbose parameter. - -## EXAMPLES - -### -------------------------- EXAMPLE 1 -------------------------- -``` -Test-PlasterManifest MyTemplate\plasterManifest.xml -``` - -Verifies that the plasterManifest.xml file in the MyTemplate sub-directory -is valid. - -### -------------------------- EXAMPLE 2 -------------------------- -``` -Test-PlasterManifest plasterManifest.xml -Verbose -``` - -Verifies that the plasterManifest.xml file in the current directory is valid. -If there are any validation errors, using -Verbose will display the details -of those errors. - -## PARAMETERS - -### -Path -Specifies a path to a plasterManifest.xml file. - -```yaml -Type: String[] -Parameter Sets: (All) -Aliases: PSPath - -Required: False -Position: 0 -Default value: "$pwd\plasterManifest.xml" -Accept pipeline input: True (ByPropertyName, ByValue) -Accept wildcard characters: False -``` - -### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). - -## INPUTS - -### System.String -You can pipe the path to a plaster manifest to Test-PlasterManifest. - -## OUTPUTS - -### System.Xml.XmlDocument -Test-PlasterManifest returns a System.Xml.XmlDocument if the manifest is -valid. Otherwise it returns $null. - -## NOTES - -## RELATED LINKS - -[Invoke-Plaster](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Invoke-Plaster.md) -[New-PlasterManifest](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/New-PlasterManifest.md) - +--- +external help file: Plaster-help.xml +Module Name: Plaster +online version: https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Test-PlasterManifest.md +schema: 2.0.0 +--- + +# Test-PlasterManifest + +## SYNOPSIS +Verifies that a plaster manifest file is a valid. + +## SYNTAX + +``` +Test-PlasterManifest [[-Path] ] [] +``` + +## DESCRIPTION +Verifies that a plaster manifest file is a valid. +If there are any errors, the details of the errors can be viewed by using the +Verbose parameter. + +## EXAMPLES + +### EXAMPLE 1 +``` +Test-PlasterManifest MyTemplate\plasterManifest.xml +``` + +Verifies that the plasterManifest.xml file in the MyTemplate sub-directory +is valid. + +### EXAMPLE 2 +``` +Test-PlasterManifest plasterManifest.xml -Verbose +``` + +Verifies that the plasterManifest.xml file in the current directory is valid. +If there are any validation errors, using -Verbose will display the details +of those errors. + +## PARAMETERS + +### -Path +Specifies a path to a plasterManifest.xml file. + +```yaml +Type: String[] +Parameter Sets: (All) +Aliases: PSPath + +Required: False +Position: 0 +Default value: "$pwd\plasterManifest.xml" +Accept pipeline input: True (ByPropertyName, ByValue) +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### System.String +You can pipe the path to a plaster manifest to Test-PlasterManifest. + +## OUTPUTS + +### System.Xml.XmlDocument +Test-PlasterManifest returns a System.Xml.XmlDocument if the manifest is +valid. Otherwise it returns $null. + +## NOTES + +## RELATED LINKS + +[Invoke-Plaster](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/Invoke-Plaster.md) +[New-PlasterManifest](https://github.com/PowerShell/Plaster/blob/master/docs/en-US/New-PlasterManifest.md) + diff --git a/githubactions.yml b/githubactions.yml deleted file mode 100644 index 2e60237..0000000 --- a/githubactions.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Pester -on: - push: - branches: [ master ] -jobs: - test-pwsh: - runs-on: windows-latest - steps: - - uses: actions/checkout@v2 - - name: Run Pester tests - shell: pwsh - run: | - Set-PSRepository psgallery -InstallationPolicy trusted - Install-Module -Name Pester -RequiredVersion 5.2.1 -Confirm:$false -Force - Invoke-Pester -Path "tests" \ No newline at end of file diff --git a/psakeFile.ps1 b/psakeFile.ps1 new file mode 100644 index 0000000..7963aa1 --- /dev/null +++ b/psakeFile.ps1 @@ -0,0 +1,132 @@ +properties { + if ($galleryApiKey) { + $PSBPreference.Publish.PSRepositoryApiKey = $galleryApiKey.GetNetworkCredential().password + } + $PSBPreference.Test.OutputFile = 'Out/testResults.xml' + # Using JUnitXML since that can be picked up by github workflow + $PSBPreference.Test.OutputFormat = 'JUnitXml' +} + +task default -depends test + +task Test -FromModule PowerShellBuild -Version 0.6.1 + +Task Sign -depends StageFiles -requiredVariables CertPath, SettingsPath, ScriptSigningEnabled { + if (!$ScriptSigningEnabled) { + "Script signing is not enabled. Skipping $($psake.context.currentTaskName) task." + return + } + + $validCodeSigningCerts = Get-ChildItem -Path $CertPath -CodeSigningCert -Recurse | Where-Object NotAfter -ge (Get-Date) + if (!$validCodeSigningCerts) { + throw "There are no non-expired code-signing certificates in $CertPath. You can either install " + + "a code-signing certificate into the certificate store or disable script analysis in build.settings.ps1." + } + + $certSubjectNameKey = "CertSubjectName" + $storeCertSubjectName = $true + + # Get the subject name of the code-signing certificate to be used for script signing. + if (!$CertSubjectName -and ($CertSubjectName = GetSetting -Key $certSubjectNameKey -Path $SettingsPath)) { + $storeCertSubjectName = $false + } elseif (!$CertSubjectName) { + "A code-signing certificate has not been specified." + "The following non-expired, code-signing certificates are available in your certificate store:" + $validCodeSigningCerts | Format-List Subject, Issuer, Thumbprint, NotBefore, NotAfter + + $CertSubjectName = Read-Host -Prompt 'Enter the subject name (case-sensitive) of the certificate to use for script signing' + } + + # Find a code-signing certificate that matches the specified subject name. + $certificate = $validCodeSigningCerts | + Where-Object { $_.SubjectName.Name -cmatch [regex]::Escape($CertSubjectName) } | + Sort-Object NotAfter -Descending | Select-Object -First 1 + + if ($certificate) { + $SharedProperties.CodeSigningCertificate = $certificate + + if ($storeCertSubjectName) { + SetSetting -Key $certSubjectNameKey -Value $certificate.SubjectName.Name -Path $SettingsPath + "The new certificate subject name has been stored in ${SettingsPath}." + } else { + "Using stored certificate subject name $CertSubjectName from ${SettingsPath}." + } + + $LineSep + "Using code-signing certificate: $certificate" + $LineSep + + $files = @(Get-ChildItem -Path $ModuleOutDir\* -Recurse -Include *.ps1, *.psm1) + foreach ($file in $files) { + $setAuthSigParams = @{ + FilePath = $file.FullName + Certificate = $certificate + Verbose = $VerbosePreference + } + + $result = Microsoft.PowerShell.Security\Set-AuthenticodeSignature @setAuthSigParams + if ($result.Status -ne 'Valid') { + throw "Failed to sign script: $($file.FullName)." + } + + "Successfully signed script: $($file.Name)" + } + } else { + $expiredCert = Get-ChildItem -Path $CertPath -CodeSigningCert -Recurse | + Where-Object { ($_.SubjectName.Name -cmatch [regex]::Escape($CertSubjectName)) -and + ($_.NotAfter -lt (Get-Date)) } + Sort-Object NotAfter -Descending | Select-Object -First 1 + + if ($expiredCert) { + throw "The code-signing certificate `"$($expiredCert.SubjectName.Name)`" EXPIRED on $($expiredCert.NotAfter)." + } + + throw 'No valid certificate subject name supplied or stored.' + } +} + +Task CoreGenerateFileCatalog -requiredVariables CatalogGenerationEnabled, CatalogVersion, ModuleName, ModuleOutDir, OutDir { + if (!$CatalogGenerationEnabled) { + "FileCatalog generation is not enabled. Skipping $($psake.context.currentTaskName) task." + return + } + + if (!(Get-Command Microsoft.PowerShell.Security\New-FileCatalog -ErrorAction SilentlyContinue)) { + "FileCatalog commands not available on this version of PowerShell. Skipping $($psake.context.currentTaskName) task." + return + } + + $catalogFilePath = "$env:BHBuildOutput\$ModuleName.cat" + + $newFileCatalogParams = @{ + Path = $ModuleOutDir + CatalogFilePath = $catalogFilePath + CatalogVersion = $CatalogVersion + Verbose = $VerbosePreference + } + + Microsoft.PowerShell.Security\New-FileCatalog @newFileCatalogParams > $null + + if ($ScriptSigningEnabled) { + if ($SharedProperties.CodeSigningCertificate) { + $setAuthSigParams = @{ + FilePath = $catalogFilePath + Certificate = $SharedProperties.CodeSigningCertificate + Verbose = $VerbosePreference + } + + $result = Microsoft.PowerShell.Security\Set-AuthenticodeSignature @setAuthSigParams + if ($result.Status -ne 'Valid') { + throw "Failed to sign file catalog: $($catalogFilePath)." + } + + "Successfully signed file catalog: $($catalogFilePath)" + } else { + "No code-signing certificate was found to sign the file catalog." + } + } else { + "Script signing is not enabled. Skipping signing of file catalog." + } + + Move-Item -LiteralPath $newFileCatalogParams.CatalogFilePath -Destination $ModuleOutDir +} diff --git a/test/ModuleManifest.Tests.ps1 b/test/ModuleManifest.Tests.ps1 deleted file mode 100644 index 399a465..0000000 --- a/test/ModuleManifest.Tests.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -$SuppressImportModule = $true -. $PSScriptRoot\Shared.ps1 - -Describe 'Module Manifest Tests' { - It 'Passes Test-ModuleManifest' { - Test-ModuleManifest -Path $ModuleManifestPath - $? | Should -Be $true - } -} diff --git a/test/NewPlasterManifest.Tests.ps1 b/test/NewPlasterManifest.Tests.ps1 deleted file mode 100644 index 61d829f..0000000 --- a/test/NewPlasterManifest.Tests.ps1 +++ /dev/null @@ -1,159 +0,0 @@ -. $PSScriptRoot\Shared.ps1 - -$LatestSchemaVersion = $plasterModule.Invoke({$LatestSupportedSchemaVersion}) - -function CompareManifestContent($expectedManifest, $actualManifestPath) { - # Compare the manifests while accounting for possible newline incompatiblity - $expectedManifest = $expectedManifest -replace "`r`n", "`n" - $actualManifest = (Get-Content $plasterPath -Raw) -replace "`r`n", "`n" - $actualManifest | Should -BeExactly $expectedManifest -} - -Describe 'New-PlasterManifest Command Tests' { - Context 'Generates a valid manifest' { - It 'Works with just Path, TemplateName, TemplateType and Id' { - CleanDir $OutDir - - $expectedManifest = @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - -"@ - $plasterPath = "$OutDir\plasterManifest.xml" - New-PlasterManifest -Path $plasterPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName -TemplateType item - Test-PlasterManifest -Path $plasterPath | Should -Not -BeNullOrEmpty - CompareManifestContent $expectedManifest $plasterPath - } - - It 'Properly encodes XML special chars and entity refs' { - CleanDir $OutDir - - $expectedManifest = @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - This is <cool> & awesome. - - - - - - -"@ - $plasterPath = "$OutDir\plasterManifest.xml" - New-PlasterManifest -Path $plasterPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName ` - -TemplateType project -Description "This is & awesome." - Test-PlasterManifest -Path $plasterPath | Should -Not -BeNullOrEmpty - CompareManifestContent $expectedManifest $plasterPath - } - - It 'Captures tags correctly' { - CleanDir $OutDir - - $expectedManifest = @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - Bag&Tag, Foo, Bar, Baz boy - - - - -"@ - $plasterPath = "$OutDir\plasterManifest.xml" - New-PlasterManifest -Path $plasterPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName ` - -TemplateType item -Tags "Bag&Tag", Foo, Bar, "Baz boy" - Test-PlasterManifest -Path $plasterPath | Should -Not -BeNullOrEmpty - CompareManifestContent $expectedManifest $plasterPath - } - - It 'AddContent parameter works' { - CleanDir $OutDir - - $expectedManifest = @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - - - - - - - - -"@ - - $plasterPath = "$OutDir\plasterManifest.xml" - Copy-Item $PSScriptRoot\Recurse $OutDir -Recurse - New-PlasterManifest -Path $plasterPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName ` - -TemplateType project -AddContent - Test-PlasterManifest -Path $plasterPath | Should -Not -BeNullOrEmpty - CompareManifestContent $expectedManifest $plasterPath - } - } - - Context 'Parameter tests' { - It 'Path resolves ~' { - $plasterPath = "~\plasterManifest.xml" - Remove-Item $plasterPath -ErrorAction SilentlyContinue - if (Test-Path $plasterPath) { - throw "$plasterManifest should have been removed for this test to work correctly." - } - New-PlasterManifest -Path $plasterPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName ` - -TemplateType item - Test-PlasterManifest -Path $plasterPath | Should -Not -BeNullOrEmpty - } - } -} diff --git a/test/Shared.ps1 b/test/Shared.ps1 deleted file mode 100644 index 5027c37..0000000 --- a/test/Shared.ps1 +++ /dev/null @@ -1,37 +0,0 @@ -$ModuleManifestName = 'Plaster.psd1' -$ModuleManifestPath = "$PSScriptRoot\..\src\$ModuleManifestName" -$TemplateDir = "$PSScriptRoot\TemplateRootTemp" -$OutDir = "$PSScriptRoot\Out" -$PlasterManifestPath = "$TemplateDir\plasterManifest.xml" - -if (!$SuppressImportModule) { - # -Scope Global is needed when running tests from inside of psake, otherwise - # the module's functions cannot be found in the Plaster\ namespace - $plasterModule = Import-Module $ModuleManifestPath -Scope Global -PassThru -} - -function CleanDir { - param( - [Parameter(Mandatory)] - [ValidateNotNullOrEmpty()] - [string] - $Path - ) - - $oldDir = Get-Location - - if (!(Test-Path $Path)) { - New-Item $Path -ItemType Directory - } - - Set-Location $Path -ErrorAction Stop - - if (!$Path.Contains($PSScriptRoot)) { - throw "Not deleting dir contents since it isn't under the Tests dir" - } - else { - Remove-Item * -Recurse - } - - Set-Location $oldDir -} diff --git a/test/TestPlasterManifest.Tests.ps1 b/test/TestPlasterManifest.Tests.ps1 deleted file mode 100644 index f5529f2..0000000 --- a/test/TestPlasterManifest.Tests.ps1 +++ /dev/null @@ -1,323 +0,0 @@ -. $PSScriptRoot\Shared.ps1 - -$SchemaVersion = $plasterModule.Invoke({$LatestSupportedSchemaVersion}) - -Describe 'Test-PlasterManifest Command Tests' { - Context 'Verifies plasterVersion correctly' { - It 'Works with the current Plaster version.' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - Test-PlasterManifest -Path $PlasterManifestPath -OutVariable xmldoc | Should -Not -BeNullOrEmpty - $xmldoc.plasterManifest.plasterVersion | Should -Be $plasterModule.Version - } - - It 'Errors on manifest plasterVersion greater than the current Plaster version.' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -BeNullOrEmpty - $TestErr.Exception.Message -match "specifies a plasterVersion of 9999\.0" | Should -Be $true - } - } - - Context 'Verifies manifest schema correctly' { - It 'Errors on manifest major version greater than supported' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -BeNullOrEmpty - $TestErr.Exception.Message -match "requires a newer version of Plaster" | Should -Be $true - } - - It 'Errors on manifest major version equal but minor version greater than supported' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -BeNullOrEmpty - $TestErr.Exception.Message -match "requires a newer version of Plaster" | Should -Be $true - } - - It 'Works on manifest major version equal to latest version' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty - $TestErr | Should -BeNullOrEmpty - } - - It 'Works on manifest major version equal but minor version is less than latest minor version' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - try { - $plasterModule.Invoke({$script:LatestSupportedSchemaVersion = New-Object System.Version $LatestSupportedSchemaVersion.Major,($LatestSupportedSchemaVersion.Minor+1)}) - Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty - $TestErr | Should -BeNullOrEmpty - } - finally { - $plasterModule.Invoke({$script:LatestSupportedSchemaVersion = $SchemaVersion}) - } - } - - It 'Detects invalid default value for choice parameters' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - $verboseRecord = Test-PlasterManifest -Path $PlasterManifestPath -Verbose -ErrorVariable TestErr -ErrorAction SilentlyContinue 4>&1 - $TestErr | Should -Not -BeNullOrEmpty - $verboseRecord | Should -Not -BeNullOrEmpty - $verboseRecord.Message | Should -Match "attribute value 'None'" - $verboseRecord.Message | Should -Match "a zero-based" - } - - It 'Detects invalid default value for multichoice parameters' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - - - - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - $verboseRecord = Test-PlasterManifest -Path $PlasterManifestPath -Verbose -ErrorVariable TestErr -ErrorAction SilentlyContinue 4>&1 - $TestErr | Should -Not -BeNullOrEmpty - $verboseRecord | Should -Not -BeNullOrEmpty - $verboseRecord.Message | Should -Match "attribute value 'Git,psake'" - $verboseRecord.Message | Should -Match "one or more zero-based" - } - - It 'Detects invalid condition attribute value' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - $verboseRecord = Test-PlasterManifest -Path $PlasterManifestPath -Verbose -ErrorVariable TestErr -ErrorAction SilentlyContinue 4>&1 - $TestErr | Should -Not -BeNullOrEmpty - $verboseRecord | Should -Not -BeNullOrEmpty - $verboseRecord.Message | Should -Match "Invalid condition '`"foo`" -eq `"bar'" - } - - It 'Detects invalid content attribute value' { - CleanDir $TemplateDir - - @" - - - - TemplateName - 1a1b0933-78b2-4a3e-bf48-492591e69521 - 1.0.0 - TemplateName - - - - - - - - - -"@ | Out-File $PlasterManifestPath -Encoding utf8 - - $verboseRecord = Test-PlasterManifest -Path $PlasterManifestPath -Verbose -ErrorVariable TestErr -ErrorAction SilentlyContinue 4>&1 - $TestErr | Should -Not -BeNullOrEmpty - $verboseRecord | Should -Not -BeNullOrEmpty - $verboseRecord.Message | Should -Match "Invalid 'source' attribute value 'Recurse\\`"foo.txt'" - } - } -} diff --git a/test/ConditionEval.Tests.ps1 b/tests/ConditionEval.Tests.ps1 similarity index 82% rename from test/ConditionEval.Tests.ps1 rename to tests/ConditionEval.Tests.ps1 index b759868..cb9bea5 100644 --- a/test/ConditionEval.Tests.ps1 +++ b/tests/ConditionEval.Tests.ps1 @@ -1,10 +1,28 @@ -. $PSScriptRoot\Shared.ps1 - +BeforeAll { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop +} Describe 'Condition Attribute Evaluation Tests' { + BeforeEach { + $TemplateDir = "TestDrive:\TemplateRootTemp" + New-Item -ItemType Directory $TemplateDir | Out-Null + $OutDir = "TestDrive:\Out" + New-Item -ItemType Directory $OutDir | Out-Null + $PlasterManifestPath = "$TemplateDir\plasterManifest.xml" + Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse + } + AfterEach { + Remove-Item $PlasterManifestPath -Confirm:$False + Remove-Item $outDir -Recurse -Confirm:$False + Remove-Item $TemplateDir -Recurse -Confirm:$False + } Context 'Runspace FileSystem provider working' { It 'Determines non-existing file is actually not in destination path' { - CleanDir $TemplateDir - CleanDir $OutDir @" @@ -22,16 +40,12 @@ Describe 'Condition Attribute Evaluation Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null # condition should return false (file doesn't exist) which will not copy over the file foo.txt Get-Item $OutDir\foo.txt -ErrorAction SilentlyContinue | Should -BeNullOrEmpty } It 'Determines existing file is in destination path' { - CleanDir $TemplateDir - CleanDir $OutDir @" @@ -49,8 +63,6 @@ Describe 'Condition Attribute Evaluation Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse New-Item $OutDir\bar.txt -ItemType File > $null Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null # condition should return true which will copy over the file foo.txt @@ -60,8 +72,6 @@ Describe 'Condition Attribute Evaluation Tests' { Context 'Runspace commands' { It 'Get-Content command is available' { - CleanDir $TemplateDir - CleanDir $OutDir @" @@ -79,16 +89,12 @@ Describe 'Condition Attribute Evaluation Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null # condition should return true which will copy over the file foo.txt Get-Item $OutDir\foo.txt -ErrorAction SilentlyContinue | Foreach-Object Name | Should -BeExactly foo.txt } It 'Get-Variable command is available' { - CleanDir $TemplateDir - CleanDir $OutDir @" @@ -106,16 +112,12 @@ Describe 'Condition Attribute Evaluation Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null # condition should return true which will copy over the file foo.txt Get-Item $OutDir\foo.txt -ErrorAction SilentlyContinue | Foreach-Object Name | Should -BeExactly foo.txt } It 'Compare-Object command is available' { - CleanDir $TemplateDir - CleanDir $OutDir @" @@ -133,8 +135,6 @@ Describe 'Condition Attribute Evaluation Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null # condition should return true which will copy over the file foo.txt Get-Item $OutDir\foo.txt -ErrorAction SilentlyContinue | Foreach-Object Name | Should -BeExactly foo.txt diff --git a/test/ExpandFileSourceSpec.Tests.ps1 b/tests/ExpandFileSourceSpec.Tests.ps1 similarity index 77% rename from test/ExpandFileSourceSpec.Tests.ps1 rename to tests/ExpandFileSourceSpec.Tests.ps1 index 14447cc..a14d1b5 100644 --- a/test/ExpandFileSourceSpec.Tests.ps1 +++ b/tests/ExpandFileSourceSpec.Tests.ps1 @@ -1,12 +1,30 @@ -. $PSScriptRoot\Shared.ps1 - +BeforeDiscovery { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop +} Describe 'File Directive ExpandFileSource Tests' { + BeforeEach { + $TemplateDir = "TestDrive:\TemplateRootTemp" + New-Item -ItemType Directory $TemplateDir | Out-Null + $OutDir = "TestDrive:\Out" + New-Item -ItemType Directory $OutDir | Out-Null + $PlasterManifestPath = "$TemplateDir\plasterManifest.xml" + Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse + } + AfterEach { + Remove-Item $PlasterManifestPath -Confirm:$False + Remove-Item $outDir -Recurse -Confirm:$False + Remove-Item $TemplateDir -Recurse -Confirm:$False + } Context 'Recurse\** case' { It 'It copies all files, preserving directory structure under the Recurse dir' { - CleanDir $TemplateDir - CleanDir $OutDir -@" + @" @@ -22,9 +40,6 @@ Describe 'File Directive ExpandFileSource Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null $src = Get-ChildItem $PSScriptRoot\Recurse -Recurse -File -Name @@ -33,10 +48,8 @@ Describe 'File Directive ExpandFileSource Tests' { } It 'It copies empty directories' { - CleanDir $TemplateDir - CleanDir $OutDir -@" + @" @@ -52,9 +65,6 @@ Describe 'File Directive ExpandFileSource Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null $src = Get-ChildItem $PSScriptRoot\Recurse -Recurse -Directory -Name @@ -66,10 +76,8 @@ Describe 'File Directive ExpandFileSource Tests' { Context 'Recurse\*.txt case' { It 'It copies only empty.txt, foo.txt under the Recurse dir' { - CleanDir $TemplateDir - CleanDir $OutDir -@" + @" @@ -85,9 +93,6 @@ Describe 'File Directive ExpandFileSource Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null $src = Get-ChildItem $PSScriptRoot\Recurse -Recurse -File -Filter *.txt -Name @@ -99,10 +104,8 @@ Describe 'File Directive ExpandFileSource Tests' { Context 'Recurse\**\*.txt case' { It 'It copies all *.txt files, preserving directory structure under the Recurse dir' { - CleanDir $TemplateDir - CleanDir $OutDir -@" + @" @@ -118,9 +121,6 @@ Describe 'File Directive ExpandFileSource Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null $src = Get-ChildItem $PSScriptRoot\Recurse -Recurse -File -Filter *.txt -Name diff --git a/test/GetPlasterTemplate.Tests.ps1 b/tests/GetPlasterTemplate.Tests.ps1 similarity index 61% rename from test/GetPlasterTemplate.Tests.ps1 rename to tests/GetPlasterTemplate.Tests.ps1 index 9140673..08d329d 100644 --- a/test/GetPlasterTemplate.Tests.ps1 +++ b/tests/GetPlasterTemplate.Tests.ps1 @@ -1,7 +1,16 @@ -. $PSScriptRoot\Shared.ps1 - +BeforeDiscovery { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop +} Describe 'Get-PlasterTemplate' { - $examplesPath = Resolve-Path "$PSScriptRoot/../examples/" + BeforeEach { + $examplesPath = Resolve-Path "$env:BHProjectPath/examples/" + } Context "when given a path" { It "finds the contained template" { @@ -10,17 +19,17 @@ Describe 'Get-PlasterTemplate' { } It "finds templates recursively" { - $templates = Get-PlasterTemplate -Path "$PSScriptRoot/../examples/" -Recurse + $templates = Get-PlasterTemplate -Path $examplesPath -Recurse $templates[0].Title | Should -Be "New DSC Resource Script File" } It "finds templates recursively and by name" { - $template = Get-PlasterTemplate -Path "$PSScriptRoot/../examples/" -Recurse -Name 'NewDscResourceScript*' + $template = Get-PlasterTemplate -Path $examplesPath -Recurse -Name 'NewDscResourceScript*' $template.Name | Should -Be "NewDscResourceScriptFile" } It "finds templates recursively and by tag" { - $template = Get-PlasterTemplate -Path "$PSScriptRoot/../examples/" -Recurse -Tag 'DSC' + $template = Get-PlasterTemplate -Path $examplesPath -Recurse -Tag 'DSC' $template.Name | Should -Be "NewDscResourceScriptFile" } } @@ -44,7 +53,9 @@ Describe 'Get-PlasterTemplate' { It "finds templates included with modules" { $builtInTemplates = Get-PlasterTemplate $oldPSModulePath = $env:PSModulePath; - $env:PSModulePath = "$(Resolve-Path "$PSScriptRoot/../examples")$([System.IO.Path]::PathSeparator)$($env:PSModulePath)"; + # Only use example path, because tester could have many templates + # installed and ordering is Alphbetical. + $env:PSModulePath = $examplesPath; $templates = Get-PlasterTemplate -IncludeInstalledModules $templates.Count -gt $builtInTemplates.Count | Should -Be $true diff --git a/test/InvokePlaster.Tests.ps1 b/tests/InvokePlaster.Tests.ps1 similarity index 67% rename from test/InvokePlaster.Tests.ps1 rename to tests/InvokePlaster.Tests.ps1 index 0698635..608d735 100644 --- a/test/InvokePlaster.Tests.ps1 +++ b/tests/InvokePlaster.Tests.ps1 @@ -1,12 +1,30 @@ -. $PSScriptRoot\Shared.ps1 - +BeforeDiscovery { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop +} Describe 'Invoke-Plaster Tests' { + BeforeEach { + $TemplateDir = "TestDrive:\TemplateRootTemp" + New-Item -ItemType Directory $TemplateDir | Out-Null + $OutDir = "TestDrive:\Out" + New-Item -ItemType Directory $OutDir | Out-Null + $PlasterManifestPath = "$TemplateDir\plasterManifest.xml" + Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse + $DestPath = Join-Path $OutDir Foo + } + AfterEach { + Remove-Item $PlasterManifestPath -Confirm:$False + Remove-Item $outDir -Recurse -Confirm:$False + Remove-Item $TemplateDir -Recurse -Confirm:$False + } Context 'Parameters' { It 'DestinationPath creates directory if it doesn''t exist' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -22,21 +40,13 @@ Describe 'Invoke-Plaster Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - - $DestPath = Join-Path $OutDir Foo - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $DestPath -NoLogo 6> $null Test-Path -LiteralPath $DestPath\foo.txt | Should -Be $true } It 'Does not process conditional parameters that eval to false' { - CleanDir $TemplateDir - CleanDir $OutDir - -@' + @' @@ -55,21 +65,13 @@ Describe 'Invoke-Plaster Tests' { '@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - - $DestPath = Join-Path $OutDir Foo - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $DestPath -NoLogo 6> $null Test-Path -LiteralPath $DestPath\foo.txt | Should -Be $true } It 'PassThru generates object' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -85,28 +87,29 @@ Describe 'Invoke-Plaster Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - - $DestPath = Join-Path $OutDir Foo - $res = Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $DestPath -NoLogo -PassThru 6> $null + # Snagged from Pester documentation + function GetFullPath { + Param( + [string] $Path + ) + $full = $Path.Replace('TestDrive:', (Get-PSDrive TestDrive).Root) + return (Resolve-Path $full).Path + } + $res.Success | Should -Be $true $res.TemplateType | Should -Be 'Project' - $res.TemplatePath -eq $TemplateDir | Should -Be $true - $res.DestinationPath -eq $DestPath | Should -Be $true - @($res.CreatedFiles)[0] | Should -Be "$DestPath\foo.txt" + $res.TemplatePath | Should -Be (GetFullPath -Path $TemplateDir) + $res.DestinationPath | Should -Be (GetFullPath -Path $DestPath) + @($res.CreatedFiles)[0] | Should -Be (GetFullPath -Path "$DestPath\foo.txt") $res.UpdatedFiles.Count | Should -Be 0 $res.MissingModules.Count | Should -Be 0 - @($res.OpenFiles)[0] | Should -Be "$DestPath\foo.txt" + @($res.OpenFiles)[0] | Should -Be (GetFullPath -Path "$DestPath\foo.txt") } It 'Text parameter with default value where condition evaluates to false returns default value' { - CleanDir $TemplateDir - CleanDir $OutDir - -@' + @' @@ -125,11 +128,6 @@ Describe 'Invoke-Plaster Tests' { '@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - - $DestPath = Join-Path $OutDir Foo - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $DestPath -NoLogo 6> $null Test-Path -LiteralPath $DestPath\foo.txt | Should -Be $true diff --git a/tests/ModuleManifest.Tests.ps1 b/tests/ModuleManifest.Tests.ps1 new file mode 100644 index 0000000..b5aa1ea --- /dev/null +++ b/tests/ModuleManifest.Tests.ps1 @@ -0,0 +1,6 @@ +Describe 'Module Manifest Tests' { + It 'Passes Test-ModuleManifest' { + Test-ModuleManifest -Path $env:BHPSModuleManifest + $? | Should -Be $true + } +} diff --git a/tests/NewPlasterManifest.Tests.ps1 b/tests/NewPlasterManifest.Tests.ps1 new file mode 100644 index 0000000..8f4163e --- /dev/null +++ b/tests/NewPlasterManifest.Tests.ps1 @@ -0,0 +1,177 @@ +BeforeDiscovery { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + $module = Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop -PassThru + + $global:LatestSchemaVersion = $module.Invoke( { $LatestSupportedSchemaVersion }) + function global:GetFullPath { + Param( + [string] $Path + ) + return $Path.Replace('TestDrive:', (Get-PSDrive TestDrive).Root) + } + function global:CompareManifestContent($expectedManifest, $actualManifestPath) { + # Compare the manifests while accounting for possible newline incompatiblity + $expectedManifest = $expectedManifest -replace "`r`n", "`n" + $actualManifest = (Get-Content $actualManifestPath -Raw) -replace "`r`n", "`n" + $actualManifest | Should -BeExactly $expectedManifest + } +} +Describe 'New-PlasterManifest Command Tests' { + BeforeEach { + $TemplateDir = "TestDrive:\TemplateRootTemp" + New-Item -ItemType Directory $TemplateDir | Out-Null + $OutDir = "TestDrive:\Out" + New-Item -ItemType Directory $OutDir | Out-Null + $PlasterManifestPath = "$TemplateDir\plasterManifest.xml" + Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse + } + AfterEach { + Remove-Item $PlasterManifestPath -Confirm:$False + Remove-Item $outDir -Recurse -Confirm:$False + Remove-Item $TemplateDir -Recurse -Confirm:$False + } + Context 'Generates a valid manifest' { + It 'Works with just Path, TemplateName, TemplateType and Id' { + $expectedManifest = @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + +"@ + New-PlasterManifest -Path $PlasterManifestPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName -TemplateType item + Test-PlasterManifest -Path $PlasterManifestPath | Should -Not -BeNullOrEmpty + global:CompareManifestContent $expectedManifest $PlasterManifestPath + } + + It 'Properly encodes XML special chars and entity refs' { + $expectedManifest = @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + This is <cool> & awesome. + + + + + + +"@ + New-PlasterManifest -Path $PlasterManifestPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName ` + -TemplateType project -Description "This is & awesome." + Test-PlasterManifest -Path (global:GetFullPath $PlasterManifestPath) | Should -Not -BeNullOrEmpty + global:CompareManifestContent $expectedManifest $PlasterManifestPath + } + + It 'Captures tags correctly' { + $expectedManifest = @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + Bag&Tag, Foo, Bar, Baz boy + + + + +"@ + New-PlasterManifest -Path $PlasterManifestPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName ` + -TemplateType item -Tags "Bag&Tag", Foo, Bar, "Baz boy" + Test-PlasterManifest -Path $PlasterManifestPath | Should -Not -BeNullOrEmpty + global:CompareManifestContent $expectedManifest $PlasterManifestPath + } + + It 'AddContent parameter works' { + $seperator = if ($IsWindows) { "\" } else { "/" } + $expectedManifest = @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + + + + + + + + +"@ -f $seperator + + New-PlasterManifest -Path $PlasterManifestPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName ` + -TemplateType project -AddContent + Test-PlasterManifest -Path $PlasterManifestPath | Should -Not -BeNullOrEmpty + global:CompareManifestContent $expectedManifest $PlasterManifestPath + } + } + <# + Context 'Parameter tests' { + Not sure the actual value of this, since it would be testing PowerShell + understanding of tilde. This is difficult to test in Pester 5, and I'm not + sure what value it's providing - HeyItsGilbert + + It 'Path resolves ~' { + $PlasterManifestPath = "~\plasterManifest.xml" + Remove-Item $PlasterManifestPath -ErrorAction SilentlyContinue + if (Test-Path $PlasterManifestPath) { + throw "$plasterManifest should have been removed for this test to work correctly." + } + New-PlasterManifest -Path $PlasterManifestPath -Id '1a1b0933-78b2-4a3e-bf48-492591e69521' -TemplateName TemplateName ` + -TemplateType item + Test-PlasterManifest -Path $PlasterManifestPath | Should -Not -BeNullOrEmpty + } + } + #> +} diff --git a/test/Recurse/empty.txt b/tests/Out/.gitkeep similarity index 100% rename from test/Recurse/empty.txt rename to tests/Out/.gitkeep diff --git a/test/PlasterManifestValidation.Tests.ps1 b/tests/PlasterManifestValidation.Tests.ps1 similarity index 81% rename from test/PlasterManifestValidation.Tests.ps1 rename to tests/PlasterManifestValidation.Tests.ps1 index 448f0a4..72e466f 100644 --- a/test/PlasterManifestValidation.Tests.ps1 +++ b/tests/PlasterManifestValidation.Tests.ps1 @@ -1,37 +1,52 @@ -. $PSScriptRoot\Shared.ps1 - +BeforeDiscovery { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop +} Describe 'Module Error Handling Tests' { + BeforeEach { + $TemplateDir = "TestDrive:\TemplateRootTemp" + New-Item -ItemType Directory $TemplateDir | Out-Null + $OutDir = "TestDrive:\Out" + New-Item -ItemType Directory $OutDir | Out-Null + $PlasterManifestPath = "$TemplateDir\plasterManifest.xml" + Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse + $DestPath = Join-Path $OutDir Foo + } + AfterEach { + Remove-Item $PlasterManifestPath -Confirm:$False -ErrorAction SilentlyContinue + Remove-Item $outDir -Recurse -Confirm:$False + Remove-Item $TemplateDir -Recurse -Confirm:$False + } Context 'Empty template dir' { It 'Throws on missing plasterManifest.xml' { - CleanDir $TemplateDir - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo } | Should Throw + { Invoke-Plaster -TemplatePath 'foo\plasterManifest.xml' -DestinationPath $OutDir -NoLogo } | Should -Throw } } - - Context 'Invalid Manifest File Tests' { It 'Throws on not well-formed XML manifest file' { - CleanDir $TemplateDir "" | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo *>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo *>$null } | Should -Throw } It 'Throws on missing plasterManifest (root) element' { - CleanDir $TemplateDir -@" + @" "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo *>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo *>$null } | Should -Throw } It 'Throws on missing target namespace on (root) element' { - CleanDir $TemplateDir -@" + @" @@ -46,13 +61,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo *>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo *>$null } | Should -Throw } It 'Throws on missing metadata element' { - CleanDir $TemplateDir -@" + @" @@ -62,13 +76,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } It 'Throws on missing metadata id element' { - CleanDir $TemplateDir -@" + @" @@ -85,13 +98,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } It 'Throws on missing metadata name element' { - CleanDir $TemplateDir -@" + @" @@ -108,13 +120,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } It 'Throws on missing metadata version element' { - CleanDir $TemplateDir -@" + @" @@ -131,13 +142,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } It 'Throws on missing metadata title element' { - CleanDir $TemplateDir -@" + @" @@ -154,13 +164,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } It 'Throws on missing content element' { - CleanDir $TemplateDir -@" + @" @@ -179,16 +188,15 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } } Context 'Not supported schemaVersion' { It 'Throws on schemaVersion greater than latest supported schemaVersion' { - CleanDir $TemplateDir -@" + @" @@ -202,16 +210,15 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null} | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } } Context 'Template cannot write outside of the user-specified DestinationPath' { It 'Throws on modify path that is absolute path' { - CleanDir $TemplateDir -@" + @" @@ -234,13 +241,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null} | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should -Throw } It 'Throws on newModuleManifest destination that is absolute path' { - CleanDir $TemplateDir - -@" + $root = if ($IsWindows) { $env:LOCALAPPDATA } else { '/' } + @" @@ -252,21 +258,20 @@ Describe 'Module Error Handling Tests' { - -"@ | Out-File $PlasterManifestPath -Encoding utf8 +"@ -f $root | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null} | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should -Throw } It 'Throws on templateFile destination that is absolute path' { - CleanDir $TemplateDir -@" + @" @@ -283,13 +288,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null} | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should -Throw } It 'Throws on modify relativePath outside of DestinationPath' { - CleanDir $TemplateDir -@" + @" @@ -312,13 +316,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should -Throw } It 'Throws on newModuleManifest relativePath outside of DestinationPath' { - CleanDir $TemplateDir -@" + @" @@ -338,13 +341,12 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should -Throw } It 'Throws on templateFile relativePath outside of DestinationPath' { - CleanDir $TemplateDir -@" + @" @@ -361,7 +363,7 @@ Describe 'Module Error Handling Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null } | Should -Throw } } } diff --git a/test/Recurse/a/b/baz.txt b/tests/Recurse/a/b/baz.txt similarity index 100% rename from test/Recurse/a/b/baz.txt rename to tests/Recurse/a/b/baz.txt diff --git a/test/Recurse/a/bar.txt b/tests/Recurse/a/bar.txt similarity index 100% rename from test/Recurse/a/bar.txt rename to tests/Recurse/a/bar.txt diff --git a/test/Recurse/a/c/d/gilead.txt b/tests/Recurse/a/c/d/gilead.txt similarity index 100% rename from test/Recurse/a/c/d/gilead.txt rename to tests/Recurse/a/c/d/gilead.txt diff --git a/test/Recurse/a/c/test.ini b/tests/Recurse/a/c/test.ini similarity index 100% rename from test/Recurse/a/c/test.ini rename to tests/Recurse/a/c/test.ini diff --git a/tests/Recurse/empty.txt b/tests/Recurse/empty.txt new file mode 100644 index 0000000..e69de29 diff --git a/test/Recurse/foo.txt b/tests/Recurse/foo.txt similarity index 100% rename from test/Recurse/foo.txt rename to tests/Recurse/foo.txt diff --git a/test/RequireModule.Tests.ps1 b/tests/RequireModule.Tests.ps1 similarity index 89% rename from test/RequireModule.Tests.ps1 rename to tests/RequireModule.Tests.ps1 index b4c5555..8a611e7 100644 --- a/test/RequireModule.Tests.ps1 +++ b/tests/RequireModule.Tests.ps1 @@ -1,12 +1,29 @@ -. $PSScriptRoot\Shared.ps1 - +BeforeDiscovery { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop +} Describe 'RequireModule Directive Tests' { + BeforeEach { + $TemplateDir = "TestDrive:\TemplateRootTemp" + New-Item -ItemType Directory $TemplateDir | Out-Null + $OutDir = "TestDrive:\Out" + New-Item -ItemType Directory $OutDir | Out-Null + $PlasterManifestPath = "$TemplateDir\plasterManifest.xml" + Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse + } + AfterEach { + Remove-Item $PlasterManifestPath -Confirm:$False + Remove-Item $outDir -Recurse -Confirm:$False + Remove-Item $TemplateDir -Recurse -Confirm:$False + } Context 'Finds module' { It 'It finds module with no version number' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -29,10 +46,7 @@ Describe 'RequireModule Directive Tests' { } It 'It finds module based on minimumVersion' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -55,10 +69,7 @@ Describe 'RequireModule Directive Tests' { } It 'It finds module based on maximumVersion' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -81,10 +92,7 @@ Describe 'RequireModule Directive Tests' { } It 'It finds module based on minimumVersion and maximumVersion' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -107,12 +115,10 @@ Describe 'RequireModule Directive Tests' { } It 'It finds module based on requiredVersion' { - $version = (Get-Module -ListAvailable Microsoft.PowerShell.Management).Version.ToString() + # Grab the 0th item since there could be many + $version = (Get-Module -ListAvailable Microsoft.PowerShell.Management)[0].Version.ToString() - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -138,10 +144,7 @@ Describe 'RequireModule Directive Tests' { Context 'Should not find module that doesn not exist or is not the specified version' { It 'Determines non-existing module is missing with no version information' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -164,10 +167,7 @@ Describe 'RequireModule Directive Tests' { } It 'Determines minimum version of module is missing' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -190,10 +190,7 @@ Describe 'RequireModule Directive Tests' { } It 'Determines maximum version of module is missing' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -216,10 +213,7 @@ Describe 'RequireModule Directive Tests' { } It 'Determines required version of module is missing' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -245,10 +239,7 @@ Describe 'RequireModule Directive Tests' { Context 'Test condition attribute' { It 'True condition evaluates requireModule directive' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -271,10 +262,7 @@ Describe 'RequireModule Directive Tests' { } It 'False condition does not evaluate requireModule directive' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -301,12 +289,9 @@ Describe 'RequireModule Directive Tests' { Context 'Test message attribute' { It 'Outputs message when module not found' { - CleanDir $TemplateDir - CleanDir $OutDir - $message = "BUMMER DUDE" -@" + @" @@ -330,12 +315,9 @@ Describe 'RequireModule Directive Tests' { } It 'Does not output message when module is found' { - CleanDir $TemplateDir - CleanDir $OutDir - $message = "BUMMER DUDE" -@" + @" @@ -361,10 +343,7 @@ Describe 'RequireModule Directive Tests' { Context 'Invalid attribute combinations' { It 'It fails on combined requiredVersion with minimumVersion' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -381,14 +360,11 @@ Describe 'RequireModule Directive Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } It 'It fails on combined requiredVersion with maximumVersion' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -405,7 +381,7 @@ Describe 'RequireModule Directive Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should Throw + { Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 3>$null } | Should -Throw } } } diff --git a/ScriptAnalyzerSettings.psd1 b/tests/ScriptAnalyzerSettings.psd1 similarity index 100% rename from ScriptAnalyzerSettings.psd1 rename to tests/ScriptAnalyzerSettings.psd1 diff --git a/test/TemplateFile.Tests.ps1 b/tests/TemplateFile.Tests.ps1 similarity index 61% rename from test/TemplateFile.Tests.ps1 rename to tests/TemplateFile.Tests.ps1 index a16abee..40a77b5 100644 --- a/test/TemplateFile.Tests.ps1 +++ b/tests/TemplateFile.Tests.ps1 @@ -1,12 +1,30 @@ -. $PSScriptRoot\Shared.ps1 +BeforeDiscovery { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop +} Describe 'TemplateFile Directive Tests' { + BeforeEach { + $TemplateDir = "TestDrive:\TemplateRootTemp" + New-Item -ItemType Directory $TemplateDir | Out-Null + $OutDir = "TestDrive:\Out" + New-Item -ItemType Directory $OutDir | Out-Null + $PlasterManifestPath = "$TemplateDir\plasterManifest.xml" + Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse + } + AfterEach { + Remove-Item $PlasterManifestPath -Confirm:$False + Remove-Item $outDir -Recurse -Confirm:$False + Remove-Item $TemplateDir -Recurse -Confirm:$False + } Context 'Invalid template files' { It 'It does not crash on an empty template file' { - CleanDir $TemplateDir - CleanDir $OutDir - -@" + @" @@ -22,19 +40,12 @@ Describe 'TemplateFile Directive Tests' { "@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -NoLogo 6> $null - Get-Item $OutDir\empty.txt | Foreach-Object Length | Should -BeExactly 0 } It 'It does not crash when prompt evaluates to empty' { - CleanDir $TemplateDir - CleanDir $OutDir - -@' + @' @@ -53,11 +64,7 @@ Describe 'TemplateFile Directive Tests' { '@ | Out-File $PlasterManifestPath -Encoding utf8 - - Copy-Item $PSScriptRoot\Recurse $TemplateDir -Recurse - Invoke-Plaster -TemplatePath $TemplateDir -DestinationPath $OutDir -Directory foo -NoLogo 6> $null - Get-Item $OutDir\empty.txt | Foreach-Object Length | Should -BeExactly 0 } } diff --git a/tests/TestPlasterManifest.Tests.ps1 b/tests/TestPlasterManifest.Tests.ps1 new file mode 100644 index 0000000..e39d441 --- /dev/null +++ b/tests/TestPlasterManifest.Tests.ps1 @@ -0,0 +1,322 @@ +BeforeDiscovery { + $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 + $outputModVerManifest = Join-Path -Path $outputModVerDir -ChildPath "$($env:BHProjectName).psd1" + Get-Module $env:BHProjectName | Remove-Module -Force -ErrorAction Ignore + $global:module = Import-Module -Name $outputModVerManifest -Verbose:$false -ErrorAction Stop -PassThru + + $global:SchemaVersion = $global:module.Invoke( { $LatestSupportedSchemaVersion }) + +} +Describe 'Test-PlasterManifest Command Tests' { + BeforeEach { + $TemplateDir = "TestDrive:\TemplateRootTemp" + New-Item -ItemType Directory $TemplateDir | Out-Null + $OutDir = "TestDrive:\Out" + New-Item -ItemType Directory $OutDir | Out-Null + $PlasterManifestPath = "$TemplateDir\plasterManifest.xml" + } + AfterEach { + Remove-Item $PlasterManifestPath -Confirm:$False + Remove-Item $outDir -Recurse -Confirm:$False + Remove-Item $TemplateDir -Recurse -Confirm:$False + } + Context 'Verifies plasterVersion correctly' { + It 'Works with the current Plaster version.' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + Test-PlasterManifest -Path ($PlasterManifestPath -replace 'TestDrive:', (Get-PSDrive TestDrive).Root) -OutVariable xmldoc | Should -Not -BeNullOrEmpty + $xmldoc.plasterManifest.plasterVersion | Should -Be $global:module.Version + } + + It 'Errors on manifest plasterVersion greater than the current Plaster version.' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + Test-PlasterManifest -Path ($PlasterManifestPath -replace 'TestDrive:', (Get-PSDrive TestDrive).Root) -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -BeNullOrEmpty + $TestErr.Exception.Message -match "specifies a plasterVersion of 9999\.0" | Should -Be $true + } + } + + Context 'Verifies manifest schema correctly' { + It 'Errors on manifest major version greater than supported' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -BeNullOrEmpty + $TestErr.Exception.Message -match "requires a newer version of Plaster" | Should -Be $true + } + + It 'Errors on manifest major version equal but minor version greater than supported' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -BeNullOrEmpty + $TestErr.Exception.Message -match "requires a newer version of Plaster" | Should -Be $true + } + + It 'Works on manifest major version equal to latest version' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty + $TestErr | Should -BeNullOrEmpty + } + + It 'Works on manifest major version equal but minor version is less than latest minor version' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + try { + $global:module.Invoke( { $script:LatestSupportedSchemaVersion = New-Object System.Version $LatestSupportedSchemaVersion.Major, ($LatestSupportedSchemaVersion.Minor + 1) }) + Test-PlasterManifest -Path $PlasterManifestPath -ErrorVariable TestErr -ErrorAction SilentlyContinue | Should -Not -BeNullOrEmpty + $TestErr | Should -BeNullOrEmpty + } finally { + $global:module.Invoke( { $script:LatestSupportedSchemaVersion = $global:SchemaVersion }) + } + } + + It 'Detects invalid default value for choice parameters' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + $verboseRecord = Test-PlasterManifest -Path $PlasterManifestPath -Verbose -ErrorVariable TestErr -ErrorAction SilentlyContinue 4>&1 + $TestErr | Should -Not -BeNullOrEmpty + $verboseRecord | Should -Not -BeNullOrEmpty + $verboseRecord.Message | Should -Match "attribute value 'None'" + $verboseRecord.Message | Should -Match "a zero-based" + } + + It 'Detects invalid default value for multichoice parameters' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + + + + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + $verboseRecord = Test-PlasterManifest -Path $PlasterManifestPath -Verbose -ErrorVariable TestErr -ErrorAction SilentlyContinue 4>&1 + $TestErr | Should -Not -BeNullOrEmpty + $verboseRecord | Should -Not -BeNullOrEmpty + $verboseRecord.Message | Should -Match "attribute value 'Git,psake'" + $verboseRecord.Message | Should -Match "one or more zero-based" + } + + It 'Detects invalid condition attribute value' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + $verboseRecord = Test-PlasterManifest -Path $PlasterManifestPath -Verbose -ErrorVariable TestErr -ErrorAction SilentlyContinue 4>&1 + $TestErr | Should -Not -BeNullOrEmpty + $verboseRecord | Should -Not -BeNullOrEmpty + $verboseRecord.Message | Should -Match "Invalid condition '`"foo`" -eq `"bar'" + } + + It 'Detects invalid content attribute value' { + @" + + + + TemplateName + 1a1b0933-78b2-4a3e-bf48-492591e69521 + 1.0.0 + TemplateName + + + + + + + + + +"@ | Out-File $PlasterManifestPath -Encoding utf8 + + $verboseRecord = Test-PlasterManifest -Path $PlasterManifestPath -Verbose -ErrorVariable TestErr -ErrorAction SilentlyContinue 4>&1 + $TestErr | Should -Not -BeNullOrEmpty + $verboseRecord | Should -Not -BeNullOrEmpty + $verboseRecord.Message | Should -Match "Invalid 'source' attribute value 'Recurse\\`"foo.txt'" + } + } +} From b883361e62d13c345ba4a5094aeb35fd18a21da8 Mon Sep 17 00:00:00 2001 From: Gilbert Sanchez Date: Sun, 3 Oct 2021 20:08:17 -0700 Subject: [PATCH 2/2] Update PesterReports.yml --- .github/workflows/PesterReports.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/PesterReports.yml b/.github/workflows/PesterReports.yml index 4eac96c..6108dc7 100644 --- a/.github/workflows/PesterReports.yml +++ b/.github/workflows/PesterReports.yml @@ -39,7 +39,7 @@ jobs: uses: actions/upload-artifact@v2 with: name: Unit Test Results (OS ${{ matrix.os }}) - path: ./tests/out/testResults.xml + path: ./tests/Out/testResults.xml publish-test-results: name: "Publish Unit Tests Results"