-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ps1
More file actions
82 lines (68 loc) · 2.33 KB
/
test.ps1
File metadata and controls
82 lines (68 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<#
.SYNOPSIS
Run tests
.DESCRIPTION
Run the unit test of the actual module
.NOTES
Using TestingHelper this script will search for a Test module and run the tests
This script will be referenced from launch.json to run the tests on VSCode
.LINK
https://raw.githubusercontent.com/rulasg/StagingModule/main/test.ps1
.EXAMPLE
> ./test.ps1
#>
[CmdletBinding()]
param (
[Parameter()][switch]$ShowTestErrors
)
function Set-TestName{
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Scope='Function')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseShouldProcessForStateChangingFunctions', '', Scope='Function')]
[Alias("st")]
param (
[Parameter(Position=0,ValueFromPipeline)][string]$TestName
)
process{
$global:TestName = $TestName
}
}
function Clear-TestName{
[CmdletBinding()]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSAvoidGlobalVars', '', Scope='Function')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseDeclaredVarsMoreThanAssignments', '', Scope='Function')]
[Alias("ct")]
param (
)
$global:TestName = $null
}
function Import-TestingHelper{
[CmdletBinding()]
param (
[Parameter()][string]$Version,
[Parameter()][switch]$AllowPrerelease,
[Parameter()][switch]$PassThru
)
if ($Version) {
$V = $Version.Split('-')
$semVer = $V[0]
$AllowPrerelease = ($AllowPrerelease -or ($null -ne $V[1]))
}
$module = Import-Module TestingHelper -PassThru -ErrorAction SilentlyContinue -RequiredVersion:$semVer
if ($null -eq $module) {
$installed = Install-Module -Name TestingHelper -Force -AllowPrerelease:$AllowPrerelease -passThru -RequiredVersion:$Version
$module = Import-Module -Name $installed.Name -RequiredVersion ($installed.Version.Split('-')[0]) -Force -PassThru
}
if ($PassThru) {
$module
}
}
Import-TestingHelper -AllowPrerelease -Version "3.0.9-preview"
# Run test by PSD1 file
# Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors
# Test-ModulelocalPSD1 -ShowTestErrors:$ShowTestErrors -TestName StagingModuleTest_*
if($TestName){
Invoke-TestingHelper -TestName $TestName -ShowTestErrors:$ShowTestErrors
} else {
Invoke-TestingHelper -ShowTestErrors:$ShowTestErrors
}