forked from pester/Pester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pester.Tests.ps1
627 lines (483 loc) · 25.4 KB
/
Pester.Tests.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
Set-StrictMode -Version Latest
BeforeAll {
$manifestPath = (Join-Path $PSScriptRoot 'Pester.psd1')
$changeLogPath = (Join-Path $PSScriptRoot 'CHANGELOG.md')
}
# DO NOT CHANGE THIS TAG NAME; IT AFFECTS THE CI BUILD.
Describe -Tags 'VersionChecks' "Pester manifest and changelog" {
BeforeAll {
$script:manifest = $null
$script:tagVersion = $null
$script:tagVersionShort = $null
$script:changelogVersion = $null
$script:changelogVersionShort = $null
$script:tagPrerelease = $null
}
It "has a valid manifest" {
{
$script:manifest = Test-ModuleManifest -Path $manifestPath -ErrorAction Stop -WarningAction SilentlyContinue
} | Should -Not -Throw
}
It "has a valid name in the manifest" {
$script:manifest.Name | Should -Be Pester
}
It "has a valid guid in the manifest" {
$script:manifest.Guid | Should -Be 'a699dea5-2c73-4616-a270-1f7abb777e71'
}
if ((Get-Command -Name git -ErrorAction SilentlyContinue) -and (Get-Item ".git" -ErrorAction Ignore)) {
if ([bool]((git remote -v 2>&1) -match "github.com/Pester/")) {
It "is tagged with a valid version" {
$thisCommit = git log --decorate --oneline HEAD~1..HEAD
if ($thisCommit -match 'tag:\s*(.*?)[,)]') {
$script:tagVersion = $matches[1]
$script:tagVersionShort, $script:tagPrerelease = $script:tagVersion -split "-", 2
}
$script:tagVersion | Should -Not -BeNullOrEmpty
$script:tagVersionShort -as [Version] | Should -Not -BeNullOrEmpty
}
It "has valid release notes in the manifest" {
$script:manifest.PrivateData.PSData.ReleaseNotes | Should -Be "https://github.com/pester/Pester/releases/tag/$script:tagVersion"
}
It "tag and changelog versions are the same" {
foreach ($line in (Get-Content $changeLogPath)) {
if ($line -match "^\s*##\s+(?<Version>.*?)\s") {
$script:changelogVersion = $matches.Version
$script:changelogVersionShort = $script:changelogVersion -replace "-.*$", ''
break
}
}
$script:changelogVersion | Should -Be $script:tagVersion
$script:changelogVersionShort | Should -Be $script:tagVersionShort
}
It "tag and changelog versions are the same" {
$script:changelogVersion | Should -Be $script:tagVersion
}
It "all short versions are the same" {
$script:changelogVersionShort -as [Version] | Should -Be ( $script:manifest.Version -as [Version] )
$script:manifest.Version -as [Version] | Should -Be ( $script:tagVersionShort -as [Version] )
}
}
}
It "has valid pre-release suffix in manifest (empty for stable version)" {
# might be empty or null, as well as the tagPrerelase. we need empty string to eq $null but not to eq any other value
$prereleaseFromManifest = $script:manifest.PrivateData.PSData.Prerelease | where { $_ }
$prereleaseFromManifest | Should -Be $script:tagPrerelease
}
}
if ($PSVersionTable.PSVersion.Major -ge 3) {
Describe 'Clean treatment of the $error variable' {
BeforeAll {
$error.Clear()
}
Context 'A Context' {
It 'Performs a successful test' {
$true | Should -Be $true
}
}
It 'Did not add anything to the $error variable' {
$error.Count | Should -Be 0
}
}
InPesterModuleScope {
Describe 'SafeCommands table' {
BeforeAll {
$path = $ExecutionContext.SessionState.Module.ModuleBase
$filesToCheck = Get-ChildItem -Path $path -Recurse -Include *.ps1, *.psm1 -Exclude *.Tests.ps1
$callsToSafeCommands = @(
foreach ($file in $filesToCheck) {
$tokens = $parseErrors = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref] $tokens, [ref] $parseErrors)
$filter = {
$args[0] -is [System.Management.Automation.Language.CommandAst] -and
$args[0].InvocationOperator -eq [System.Management.Automation.Language.TokenKind]::Ampersand -and
$args[0].CommandElements[0] -is [System.Management.Automation.Language.IndexExpressionAst] -and
$args[0].CommandElements[0].Target -is [System.Management.Automation.Language.VariableExpressionAst] -and
$args[0].CommandElements[0].Target.VariablePath.UserPath -match '^(?:script:)?SafeCommands$'
}
$ast.FindAll($filter, $true)
}
)
$uniqueSafeCommands = $callsToSafeCommands | ForEach-Object { $_.CommandElements[0].Index.Value } | Select-Object -Unique
$missingSafeCommands = $uniqueSafeCommands | Where { -not $script:SafeCommands.ContainsKey($_) }
# These commands are conditionally added to the safeCommands table due to Nano / Core versus PSv2 compatibility; one will always
# be missing, and can be ignored.
# Also add the two possible commands uname and id which would be found on non-Windows platforms
$missingSafeCommands = $missingSafeCommands | Where { @('Get-WmiObject', 'Get-CimInstance', 'uname', 'id') -notcontains $_ }
}
It 'The SafeCommands table contains all commands that are called from the module' {
$missingSafeCommands | Should -Be $null
}
}
}
}
Describe 'Public API' {
It 'all non-deprecated, non-internal public commands use CmdletBinding' {
$r = Get-Command -Module Pester |
? { $_.CommandType -ne 'Alias' } | # Get-Command outputs aliases in PowerShell 2
? { -not $_.CmdletBinding } |
% { $_.Name }
$r | Should -beNullOrEmpty
}
}
Describe 'Style rules' -Tag StyleRules {
BeforeAll {
$pesterRoot = (Get-Module Pester).ModuleBase
$files = @(
Get-ChildItem $pesterRoot\* -Include *.ps1, *.psm1, *.psd1
Get-ChildItem (Join-Path $pesterRoot 'en-US') -Include *.ps1, *.psm1, *.psd1, *.txt -Recurse
Get-ChildItem (Join-Path $pesterRoot 'Functions') -Include *.ps1, *.psm1, *.psd1 -Recurse
Get-ChildItem (Join-Path $pesterRoot 'Dependencies') -Include *.ps1, *.psm1, *.psd1 -Recurse
)
}
It 'Pester source files contain no trailing whitespace' {
$badLines = @(
foreach ($file in $files) {
$lines = [System.IO.File]::ReadAllLines($file.FullName)
$lineCount = $lines.Count
for ($i = 0; $i -lt $lineCount; $i++) {
if ($lines[$i] -match '\s+$') {
'File: {0}, Line: {1}' -f $file.FullName, ($i + 1)
}
}
}
)
if ($badLines.Count -gt 0) {
throw "The following $($badLines.Count) lines contain trailing whitespace: $([System.Environment]::NewLine)$([System.Environment]::NewLine)$($badLines -join "$([System.Environment]::NewLine)")"
}
}
It 'Spaces are used for indentation in all code files, not tabs' {
$badLines = @(
foreach ($file in $files) {
$lines = [System.IO.File]::ReadAllLines($file.FullName)
$lineCount = $lines.Count
for ($i = 0; $i -lt $lineCount; $i++) {
if ($lines[$i] -match '^[ ]*\t|^\t|^\t[ ]*') {
'File: {0}, Line: {1}' -f $file.FullName, ($i + 1)
}
}
}
)
if ($badLines.Count -gt 0) {
throw "The following $($badLines.Count) lines start with a tab character: $([System.Environment]::NewLine)$([System.Environment]::NewLine)$($badLines -join "$([System.Environment]::NewLine)")"
}
}
It 'Pester Source Files all end with a newline' {
$badFiles = @(
foreach ($file in $files) {
$string = [System.IO.File]::ReadAllText($file.FullName)
if ($string.Length -gt 0 -and $string[-1] -ne "`n") {
$file.FullName
}
}
)
if ($badFiles.Count -gt 0) {
throw "The following files do not end with a newline: $([System.Environment]::NewLine)$([System.Environment]::NewLine)$($badFiles -join "$([System.Environment]::NewLine)")"
}
}
}
InPesterModuleScope {
Describe 'Find-File' {
BeforeAll {
New-Item -ItemType File 'TestDrive:\SomeFile.ps1'
New-Item -ItemType File 'TestDrive:\SomeFile.Tests.ps1'
New-Item -ItemType File 'TestDrive:\SomeOtherFile.ps1'
New-Item -ItemType File 'TestDrive:\SomeOtherFile.Tests.ps1'
}
It 'Resolves non-wildcarded file paths regardless of whether the file ends with Tests.ps1' {
$result = @(Find-File 'TestDrive:\SomeOtherFile.ps1' -Extension ".Tests.ps1")
$result.Count | Should -Be 1
$result[0].UnresolvedPath | Should -Be 'TestDrive:\SomeOtherFile.ps1'
}
It 'Finds only *.Tests.ps1 files when the path contains wildcards' {
$result = @(Find-File 'TestDrive:\*.ps1' -Extension ".Tests.ps1")
$result.Count | Should -Be 2
$paths = $result | Select-Object -ExpandProperty FullName
$testDrive = (Get-PSDrive TestDrive).Root
($paths -contains (Join-Path $testDrive "SomeFile.Tests.ps1")) | Should -Be $true
($paths -contains (Join-Path $testDrive "SomeOtherFile.Tests.ps1")) | Should -Be $true
}
It 'Finds only *.Tests.ps1 files when the path refers to a directory and does not contain wildcards' {
$result = @(Find-File 'TestDrive:\' -Extension ".Tests.ps1")
$result.Count | Should -Be 2
$paths = $result | Select-Object -ExpandProperty FullName
$testDrive = (Get-PSDrive TestDrive).Root
($paths -contains (Join-Path $testDrive "SomeFile.Tests.ps1")) | Should -Be $true
($paths -contains (Join-Path $testDrive "SomeOtherFile.Tests.ps1")) | Should -Be $true
}
# It 'Assigns empty array and hashtable to the Arguments and Parameters properties when none are specified by the caller' {
# $result = @(Find-File 'TestDrive:\SomeFile.ps1' -Extension ".Tests.ps1")
# $result.Count | Should -Be 1
# $result[0].UnresolvedPath | Should -Be 'TestDrive:\SomeFile.ps1'
# , $result[0].Arguments | Should -Not -Be $null
# , $result[0].Parameters | Should -Not -Be $null
# $result[0].Arguments.GetType() | Should -Be ([object[]])
# $result[0].Arguments.Count | Should -Be 0
# $result[0].Parameters.GetType() | Should -Be ([hashtable])
# $result[0].Parameters.PSBase.Count | Should -Be 0
# }
# Context 'Passing in Dictionaries instead of Strings' {
# It 'Allows the use of a "p" key instead of "Path"' {
# $result = @(Find-RSpecTestFile @{ p = 'TestDrive:\SomeFile.ps1' })
# $result.Count | Should -Be 1
# $result[0].Path | Should -Be 'TestDrive:\SomeFile.ps1'
# }
# $testArgs = @('I am a string')
# It 'Allows the use of an "Arguments" key in the dictionary' {
# $result = @(Find-RSpecTestFile @{ Path = 'TestDrive:\SomeFile.ps1'; Arguments = $testArgs })
# $result.Count | Should -Be 1
# $result[0].Path | Should -Be 'TestDrive:\SomeFile.ps1'
# $result[0].Arguments.Count | Should -Be 1
# $result[0].Arguments[0] | Should -Be 'I am a string'
# }
# It 'Allows the use of an "args" key in the dictionary' {
# $result = @(Find-RSpecTestFile @{ Path = 'TestDrive:\SomeFile.ps1'; args = $testArgs })
# $result.Count | Should -Be 1
# $result[0].Path | Should -Be 'TestDrive:\SomeFile.ps1'
# $result[0].Arguments.Count | Should -Be 1
# $result[0].Arguments[0] | Should -Be 'I am a string'
# }
# It 'Allows the use of an "a" key in the dictionary' {
# $result = @(Find-RSpecTestFile @{ Path = 'TestDrive:\SomeFile.ps1'; a = $testArgs })
# $result.Count | Should -Be 1
# $result[0].Path | Should -Be 'TestDrive:\SomeFile.ps1'
# $result[0].Arguments.Count | Should -Be 1
# $result[0].Arguments[0] | Should -Be 'I am a string'
# }
# $testParams = @{ MyKey = 'MyValue' }
# It 'Allows the use of a "Parameters" key in the dictionary' {
# $result = @(Find-RSpecTestFile @{ Path = 'TestDrive:\SomeFile.ps1'; Parameters = $testParams })
# $result.Count | Should -Be 1
# $result[0].Path | Should -Be 'TestDrive:\SomeFile.ps1'
# $result[0].Parameters.PSBase.Count | Should -Be 1
# $result[0].Parameters['MyKey'] | Should -Be 'MyValue'
# }
# It 'Allows the use of a "params" key in the dictionary' {
# $result = @(Find-RSpecTestFile @{ Path = 'TestDrive:\SomeFile.ps1'; params = $testParams })
# $result.Count | Should -Be 1
# $result[0].Path | Should -Be 'TestDrive:\SomeFile.ps1'
# $result[0].Parameters.PSBase.Count | Should -Be 1
# $result[0].Parameters['MyKey'] | Should -Be 'MyValue'
# }
# It 'Allows to pass test script string' {
# $result = @(Find-RSpecTestFile @{ Script = "Test script string" })
# $result.Count | Should -Be 1
# $result[0].Script | Should -Be "Test script string"
# $result[0].Path | Should -BeNullOrEmpty
# $result[0].Parameters | Should -BeNullOrEmpty
# $result[0].Arguments | Should -BeNullOrEmpty
# }
# It 'Throws an error if no Path is specified' {
# { Find-RSpecTestFile @{} } | Should -Throw
# }
# It 'Throws an error if a Parameters key is used, but does not contain an IDictionary object' {
# { Find-RSpecTestFile @{ P = 'P'; Params = 'A string' } } | Should -Throw
# }
#}
}
}
Describe 'Assertion operators' {
BeforeAll {
$operators = &(Get-Module Pester) { $script:AssertionOperators }
# enumerate to avoid the collection from being modified
$builtInOperators = $operators.Keys | Foreach-Object { $_ }
}
It 'Allows an operator with an identical name and test to be re-registered' {
function SameNameAndScript {
$true
}
Add-ShouldOperator -Name SameNameAndScript -Test $function:SameNameAndScript
{ Add-ShouldOperator -Name SameNameAndScript -Test $function:SameNameAndScript } | Should -Not -Throw
}
It 'Allows an operator with an identical name, test, and alias to be re-registered' {
function SameNameAndScriptAndAlias {
$true
}
Add-ShouldOperator -Name SameNameAndScriptAndAlias -Test $function:SameNameAndScriptAndAlias -Alias SameAlias
{ Add-ShouldOperator -Name SameNameAndScriptAndAlias -Test $function:SameNameAndScriptAndAlias -Alias SameAlias } | Should -Not -Throw
}
It 'Allows an operator to be registered with multiple aliases' {
function MultipleAlias {
$true
}
Add-ShouldOperator -Name MultipleAlias -Test $Function:MultipleAlias -Alias mult, multiple
{ Add-ShouldOperator -Name MultipleAlias -Test $Function:MultipleAlias -Alias mult, multiple } | Should -Not -Throw
}
It 'Does not allow an operator with a different test to be registered using an existing name' {
function DifferentScriptBlockA {
$true
}
function DifferentScriptBlockB {
$false
}
Add-ShouldOperator -Name DifferentScriptBlock -Test $function:DifferentScriptBlockA
{ Add-ShouldOperator -Name DifferentScriptBlock -Test $function:DifferentScriptBlockB } | Should -Throw
}
It 'Does not allow an operator with a different test to be registered using an existing alias' {
function DifferentAliasA {
$true
}
function DifferentAliasB {
$true
}
Add-ShouldOperator -Name DifferentAliasA -Test $function:DifferentAliasA -Alias DifferentAliasTest
{ Add-ShouldOperator -Name DifferentAliasB -Test $function:DifferentAliasB -Alias DifferentAliasTest } | Should -Throw
}
AfterAll {
$operators = &(Get-Module Pester) { $script:AssertionOperators }
# enumerate to avoid modifying the collection
# list all operators that we added in the tests above
# otherwise we leak them to other tests
# (especially the help tests that will then fail)
$keys = $operators.Keys | Where-Object { $_ -notin $builtInOperators }
$keys | ForEach-Object { $operators.Remove($_) }
}
}
Describe 'Set-StrictMode for all tests files' {
It 'Pester tests files start with explicit declaration of StrictMode set to Latest' {
$files = Get-ChildItem $PSScriptRoot\../tst/ -Include *.Tests.ps1 -Recurse
$UnstrictTests = @(
foreach ($file in $files) {
$lines = [System.IO.File]::ReadAllLines($file.FullName)
$lineCount = $lines.Count
if ($lineCount -lt 3) {
$linesToRead = $lineCount
}
else {
$linestoRead = 3
}
$n = 0
for ($i = 0; $i -lt $linestoRead; $i++) {
if ($lines[$i] -match '^\s*Set-StrictMode\s+-Version\s+Latest') {
$n++
}
}
if ( $n -eq 0 ) {
$file.FullName
}
}
)
if ($UnstrictTests.Count -gt 0) {
throw "The following $($UnstrictTests.Count) tests files doesn't contain strict mode declaration in the first three lines: $([System.Environment]::NewLine)$([System.Environment]::NewLine)$($UnstrictTests -join "$([System.Environment]::NewLine)")"
}
}
}
#Tests mostly based on the blog post http://www.lazywinadmin.com/2016/05/using-pester-to-test-your-comment-based.html
#Author: Francois-Xavier Cat fxcat[at]lazywinadmin[dot]com
# AST is not available in PowerShell < 3
if ($PSVersionTable.PSVersion.Major -gt 2) {
#Tests mostly based on the blog post http://www.lazywinadmin.com/2016/05/using-pester-to-test-your-comment-based.html
#Author: Francois-Xavier Cat fxcat[at]lazywinadmin[dot]com
#Please don't run that section InModuleScope - too much internall functions don't have help
Describe "Module Pester functions help" -Tags "Help" {
[String[]]$AcceptEmptyHelp = @()
[String[]]$AcceptMissedHelpSynopsis = @()
[String[]]$AccepteMissedHelpDescription = @('AfterAll', 'AfterEach', 'BeforeAll', 'BeforeEach')
[String[]]$AcceptMissedHelpParameters = @('Should')
[String[]]$AcceptMissedHelpExamples = @('AfterAll', 'AfterEach', 'AfterEachFeature', 'AfterEachScenario', 'Assert-VerifiableMocks',
'BeforeAll', 'BeforeEach', 'BeforeEachFeature', 'BeforeEachScenario', 'In', 'Should')
[String[]]$FunctionsList = (Get-Command -Module Pester | Where-Object -FilterScript { $_.CommandType -eq 'Function' })
[String[]]$FilteredFunctionList = $($FunctionsList | Where-Object -FilterScript { $AcceptEmptyHelp -notcontains $_ })
ForEach ($Function in $FilteredFunctionList) {
# Retrieve the Help of the function
$FunctionHelp = Get-Help -Name $Function -Full
# Parse the function using AST
$AST = [System.Management.Automation.Language.Parser]::ParseInput((Get-Content function:$Function), [ref]$null, [ref]$null)
Context "The function [$Function] - Help" {
If ($AcceptMissedHelpSynopsis -notcontains $Function) {
$HelpSynopsis = ($FunctionHelp.Synopsis).Trim()
if ( -not [String]::IsNullOrEmpty($HelpSynopsis) ) {
$HelpSynopsisBegin = $HelpSynopsis.SubString(0, $HelpSynopsis.IndexOf('[') + 2)
$HelpSynopsisEnd = $HelpSynopsis.SubString($HelpSynopsis.length - 1, 1 )
}
It "Synopsis for the function is filled up" {
$HelpSynopsis | Should not BeNullOrEmpty
$HelpSynopsisBegin | Should Not Be "$Function [["
$HelpSynopsisEnd | Should Not Be ']'
$HelpSynopsis | Should Not Be $Function
}
}
If ($AccepteMissedHelpDescription -notcontains $Function) {
It "Description for the function is filled up" {
$FunctionDescription = $FunctionHelp.Description
$FunctionDescription | Should not BeNullOrEmpty
}
}
# Get the parameters declared in the Comment Based Help
$RiskMitigationParameters = 'Whatif', 'Confirm'
Try {
$ParametersCount = $(Measure-Object -InputObject $FunctionHelp.parameters.parameter).Count
}
Catch {
$ParametersCount = 0
}
if ( $ParametersCount -gt 0 ) {
$HelpParameters = $FunctionHelp.parameters.parameter | Where-Object name -NotIn $RiskMitigationParameters
}
# Get the parameters declared in the AST PARAM() Block
Try {
[String[]]$ASTParameters = $AST.ParamBlock.Parameters.Name.variablepath.userpath | Sort-Object
}
Catch {
$ASTParameters = $Null
}
If (-not [String]::IsNullOrEmpty($ASTParameters) -and $AcceptMissedHelpParameters -notcontains $Function ) {
$HelpParameters | ForEach-Object {
It "The parameter [$($_.Name)] contains description" {
$ParameterDescription = $_.description
$ParameterDescription | Should not BeNullOrEmpty
}
}
}
# Examples
If ($AcceptMissedHelpExamples -notcontains $Function) {
Try {
$ExamplesCount = $(Measure-Object -InputObject $FunctionHelp.examples.example).Count
}
Catch {
$ExamplesCount = 0
}
it "Example - At least one example exist" {
#$ExamplesCount = $FunctionHelp.examples.example.code.count
$ExamplesCount | Should BeGreaterthan 0
}
If ( $ExamplesCount -gt 0 ) {
# Examples - Remarks (small description that comes with the example)
foreach ($Example in $FunctionHelp.examples.example) {
$StrippedExampleTitle = ($Example.Title).Replace('--------------------------', '')
it "Example - remarks on [$StrippedExampleTitle] are filled up" {
$Example.remarks | Should not BeNullOrEmpty
}
}
}
}
}
}
}
}
InModuleScope -ModuleName Pester {
Describe "Contain-AnyStringLike" {
It 'Given a filter <filter> that does not match any items in collection <collection> it returns $false' -TestCases @(
@{ Filter = "Unit"; Collection = "Integration" }
@{ Filter = "*Unit*"; Collection = "Integration" }
@{ Filter = "*Unit*", "IntegrationTest"; Collection = "Integration" }
@{ Filter = "Unit"; Collection = "Low", "Medium", "High" }
@{ Filter = "*Unit*"; Collection = "Low", "Medium", "High" }
) {
param($Filter, $Collection)
Contain-AnyStringLike -Filter $Filter -Collection $Collection |
Should -BeFalse
}
It 'Given a filter <filter> that matches one or more items in collection <collection> it returns $true' -TestCases @(
@{ Filter = "Unit"; Collection = "Unit" }
@{ Filter = "*Unit*"; Collection = "UnitTest" }
@{ Filter = "UnitTest", "IntegrationTest"; Collection = "UnitTest" }
@{ Filter = "Low"; Collection = "Low", "Medium", "High" }
@{ Filter = "Low", "Medium"; Collection = "Low", "Medium", "High" }
@{ Filter = "l*"; Collection = "Low", "Medium", "High" }
) {
param($Filter, $Collection)
Contain-AnyStringLike -Filter $Filter -Collection $Collection |
Should -BeTrue
}
}
}