Skip to content

Commit 4d86e32

Browse files
authored
Merge pull request #43 from vexx32/dev
v0.39: Objection!
2 parents 14805ef + 9fd79e8 commit 4d86e32

File tree

55 files changed

+1465
-566
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1465
-566
lines changed

Build/Build.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ if ($env:APPVEYOR_REPO_BRANCH -eq 'master' -and -not $env:APPVEYOR_PULL_REQUEST_
77
$Task = 'Deploy'
88
}
99

10-
# Grab nuget bits, install modules, set build variables, start build.
10+
# Grab nuget bits, set build variables, start build.
1111
Get-PackageProvider -Name NuGet -ForceBootstrap > $null
1212

13-
Install-Module Psake, PSDeploy, BuildHelpers -Force -Scope CurrentUser
14-
Install-Module Pester -Force -SkipPublisherCheck -Scope CurrentUser
15-
Import-Module Psake, BuildHelpers
13+
Import-Module -Name Psake, BuildHelpers
1614

1715
Set-BuildEnvironment
1816

Build/Psake.ps1

Lines changed: 66 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,87 +1,115 @@
1-
# PSake makes variables declared here available in other scriptblocks
1+
[CmdletBinding()]
2+
param()
3+
# Psake makes variables declared here available in other scriptblocks
24
# Init some things
35
Properties {
46
# Find the build folder based on build system
57
$ProjectRoot = $env:BHProjectPath
68
if (-not $ProjectRoot) {
7-
$ProjectRoot = Resolve-Path "$PSScriptRoot\.."
9+
$ProjectRoot = Resolve-Path -Path "$PSScriptRoot\.."
810
}
911

10-
$Timestamp = Get-Date -UFormat "%Y%m%d-%H%M%S"
11-
$PSVersion = $PSVersionTable.PSVersion.Major
12-
$TestFile = "TestResults_PS$PSVersion`_$TimeStamp.xml"
13-
$lines = '----------------------------------------------------------------------'
12+
$Timestamp = Get-Date -Format "yyyyMMdd-hhmmss"
13+
$PSVersion = $PSVersionTable.PSVersion
14+
$TestFile = "TestResults_PS${PSVersion}_${TimeStamp}.xml"
15+
$Lines = '-' * 70
1416

15-
$Verbose = @{}
17+
$DeploymentParams = @{
18+
Path = "$ProjectRoot"
19+
Force = $true
20+
Recurse = $false # We keep psdeploy artifacts, avoid deploying those
21+
}
1622
if ($ENV:BHCommitMessage -match "!verbose") {
17-
$Verbose = @{Verbose = $True}
23+
$DeploymentParams.Add('Verbose', $true)
24+
}
25+
26+
$Continue = @{
27+
InformationAction = if ($PSBoundParameters['InformationAction']) {
28+
$PSBoundParameters['InformationAction']
29+
}
30+
else {
31+
'Continue'
32+
}
1833
}
1934
}
2035

21-
Task Default -Depends Test
36+
Task 'Default' -Depends 'Test'
2237

23-
Task Init {
24-
$lines
25-
Set-Location $ProjectRoot
26-
"Build System Details:"
27-
Get-Item ENV:BH*
28-
"`n"
38+
Task 'Init' {
39+
Set-Location -Path $ProjectRoot
40+
Write-Information @Continue @"
41+
$Lines
42+
Build System Details:
43+
"@
44+
Get-Item 'ENV:BH*'
2945
}
3046

31-
Task Test -Depends Init {
32-
$lines
33-
"`n`tSTATUS: Testing with PowerShell $PSVersion"
34-
47+
Task 'Test' -Depends 'Init' {
48+
Write-Information @Continue @"
49+
$Lines
50+
STATUS: Testing with PowerShell $PSVersion
51+
"@
3552
# Testing links on github requires >= tls 1.2
3653
$SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol
3754
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
3855

56+
# Import the module
57+
Import-Module "$ProjectRoot\PSKoans\PSKoans.psd1"
58+
3959
# Gather test results. Store them in a variable and file
40-
$TestResults = Invoke-Pester -Path $ProjectRoot\Tests -PassThru -OutputFormat NUnitXml -OutputFile "$ProjectRoot\$TestFile"
60+
$PesterParams = @{
61+
Path = "$ProjectRoot\Tests"
62+
PassThru = $true
63+
OutputFormat = 'NUnitXml'
64+
OutputFile = "$ProjectRoot\$TestFile"
65+
}
66+
$TestResults = Invoke-Pester @PesterParams
67+
4168
[Net.ServicePointManager]::SecurityProtocol = $SecurityProtocol
4269

43-
# In Appveyor? Upload our tests! #Abstract this into a function?
70+
# In Appveyor? Upload our tests!
4471
If ($ENV:BHBuildSystem -eq 'AppVeyor') {
4572
(New-Object 'System.Net.WebClient').UploadFile(
4673
"https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)",
47-
"$ProjectRoot\$TestFile" )
74+
"$ProjectRoot\$TestFile"
75+
)
4876
}
4977

50-
Remove-Item "$ProjectRoot\$TestFile" -Force -ErrorAction SilentlyContinue
78+
Remove-Item -Path "$ProjectRoot\$TestFile" -Force -ErrorAction SilentlyContinue
79+
5180
# Failed tests?
5281
# Need to tell psake or it will proceed to the deployment. Danger!
5382
if ($TestResults.FailedCount -gt 0) {
54-
Write-Error "Failed '$($TestResults.FailedCount)' tests, build failed"
83+
Write-Error "Failed $($TestResults.FailedCount) tests; build failed!"
5584
}
56-
"`n"
5785
}
5886

59-
Task Build -Depends Test {
60-
$lines
87+
Task 'Build' -Depends 'Test' {
88+
Write-Information @Continue @"
6189
90+
$Lines
91+
"@
6292
# Load the module, read the exported functions, update the psd1 FunctionsToExport
6393
Set-ModuleFunctions
6494

6595
# Bump the module version if we didn't already
66-
Try {
67-
$GalleryVersion = Get-NextPSGalleryVersion -Name $env:BHProjectName -ErrorAction Stop
96+
try {
97+
$GalleryVersion = Get-NextNugetPackageVersion -Name $env:BHProjectName -ErrorAction Stop
6898
$GithubVersion = Get-MetaData -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -ErrorAction Stop
6999
if ($GalleryVersion -ge $GithubVersion) {
70100
Update-Metadata -Path $env:BHPSModuleManifest -PropertyName ModuleVersion -Value $GalleryVersion -ErrorAction stop
71101
}
72102
}
73-
Catch {
74-
"Failed to update version for '$env:BHProjectName': $_.`nContinuing with existing version"
103+
catch {
104+
Write-Information @Continue @"
105+
Failed to update version for '$env:BHProjectName': $_.
106+
Continuing with existing version.
107+
"@
75108
}
76109
}
77110

78111
Task Deploy -Depends Build {
79-
$lines
112+
Write-Information $Lines @Continue
80113

81-
$Params = @{
82-
Path = "$ProjectRoot"
83-
Force = $true
84-
Recurse = $false # We keep psdeploy artifacts, avoid deploying those : )
85-
}
86-
Invoke-PSDeploy @Verbose @Params
114+
Invoke-PSDeploy @DeploymentParams
87115
}

PSKoans/Koans/Advanced Techniques/AboutRedirection.Koans.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Requires -Module PSKoans
2-
[Koan(601)]
2+
[Koan(Position = 601)]
33
param()
44
<#
55
Redirection
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#Requires -Module PSKoans
2+
[Koan(Position = 205)]
3+
param()
4+
<#
5+
Compare-Object
6+
7+
Compare-Object is primarily for comparing collections of objects rather than individual
8+
items, and is usually used to display data comparisons to the user.
9+
#>
10+
Describe 'Compare-Object' {
11+
12+
It 'compares collections of objects' {
13+
$Comparison = @{
14+
ReferenceObject = 'this', 'is', 'the', 'reference'
15+
DifferenceObject = 'these', 'is', 'the', 'difference'
16+
}
17+
$CompareData = Compare-Object @Comparison
18+
$CompareData[0].InputObject | Should -Be '__'
19+
$CompareData[0].SideIndicator | Should -Be '__'
20+
$CompareData[0] | Should -BeOfType __
21+
}
22+
23+
It 'can display items that occur in both sets' {
24+
# By default, items that are the same in both collections are hidden.
25+
$Comparison = @{
26+
ReferenceObject = 'this', 'is', 'the', 'reference'
27+
DifferenceObject = 'these', 'is', 'the', 'difference'
28+
}
29+
$CompareData = Compare-Object @Comparison -IncludeEqual
30+
$CompareData.SideIndicator -contains '==' | Should -BeTrue
31+
$CompareData.Where{$_.InputObject -eq 'the'}.SideIndicator | Should -Be '__'
32+
}
33+
}

PSKoans/Koans/Cmdlets 1/AboutGetHelpAndGetMember.Koans.ps1 renamed to PSKoans/Koans/Cmdlets 1/AboutDiscovery.Koans.ps1

Lines changed: 96 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
11
#Requires -Module PSKoans
2-
[Koan(201)]
2+
[Koan(Position = 201)]
33
param()
44
<#
5-
Get-Help
5+
Help & Discovery
66
7-
Get-Help is a built-in PowerShell cmdlet that is used to retrieve help data for
8-
cmdlets and functions. It contains usage examples, parameter information,
9-
and a significant amount of otherwise difficult to discover tidbits.
7+
PowerShell's help and discovery systems are a key component to its ecosystem. A great
8+
many things can be learned simply by knowing where to look and which few cmdlets to
9+
use in order to find what you're looking for.
1010
11-
Get-Member
12-
13-
Get-Member is another built-in cmdlet that is invaluable in retrieving
14-
information about any object in PowerShell. It can be used to inspect the type
15-
name of an object, as well as all available methods and properties that can be
16-
accessed for that object.
17-
18-
These cmdlets are quintessential discovery tools, and regular use of them will
19-
vastly expedite any unfamiliar task in PowerShell. Combined with well-placed
20-
Google searches, it is possible to learn a significant amount about native
21-
PowerShell cmdlets and functions, and more advanced .NET classes, and methods.
11+
Discovery cmdlets are quintessential learning tools, and regular use of them will
12+
vastly expedite any unfamiliar task in PowerShell. Combined with targeted online
13+
searches, it is straightforward to learn a significant amount about native PowerShell
14+
cmdlets and functions, as well as more advanced .NET classes, and methods.
2215
#>
23-
2416
Describe 'Get-Help' {
17+
<#
18+
Get-Help
2519
20+
Get-Help is a built-in PowerShell cmdlet that is used to retrieve help data for
21+
cmdlets and functions. It contains usage examples, parameter information, and
22+
a significant amount of otherwise difficult to discover tidbits.
23+
#>
2624
Context 'shows help information about cmdlets' {
2725
# Try calling 'Get-Help Get-Help' in a console to see the built in help available
2826
# for the help command.
@@ -55,11 +53,27 @@ Describe 'Get-Help' {
5553
$ParameterInfo.PipelineInput | Should -Be __
5654
}
5755
# Remember: if 'Get-Help Cmdlet-Name' doesn't show you all you need, try -Full. You'll need it.
56+
57+
It 'can search for commands by parameter names' {
58+
$RemoteCommands = Get-Help -Name * -Parameter ComputerName |
59+
Select-Object -ExpandProperty Name
60+
61+
$RemoteCommands.Count | Should -Be __
62+
63+
$RemoteCommands[4] | Should -Be __
64+
}
5865
}
5966
}
6067

6168
Describe 'Get-Member' {
62-
69+
<#
70+
Get-Member
71+
72+
Get-Member is another built-in cmdlet that is invaluable in retrieving
73+
information about any object in PowerShell. It can be used to inspect the type
74+
name of an object, as well as all available methods and properties that can be
75+
accessed for that object.
76+
#>
6377
Context 'Members and methods of objects' {
6478

6579
It 'can help you find useful properties' {
@@ -117,8 +131,8 @@ Describe 'Get-Member' {
117131
Context 'Members of objects returned from cmdlets' {
118132

119133
It 'can help you discover information about unfamiliar objects' {
120-
# Cmdlets also return objects! This cmdlet creates an empty .tmp file in a random location,
121-
# and returns the object representation of this file.
134+
# Cmdlets also return objects! This cmdlet creates an empty .tmp file in a random
135+
# location, and returns the object representing this file.
122136
$TempFile = New-TemporaryFile
123137
Test-Path -Path $TempFile.FullName | Should -BeTrue
124138

@@ -139,4 +153,66 @@ Describe 'Get-Member' {
139153
$MemberData | Should -BeOfType __
140154
}
141155
}
156+
}
157+
158+
Describe 'Get-Command' {
159+
<#
160+
Get-Command
161+
162+
Get-Command is one of the most useful cmdlets for discovery. It allows you to
163+
list all available commands, specify a module to look for available commands in,
164+
and filter based on command name, module name, etc.
165+
166+
As the vast majority of PowerShell commands are packaged with help files, it is
167+
also an invaluable tool in finding possible help topics to look up in the first
168+
place!
169+
170+
When looking for related commands, use of the -Verb and -Noun search options
171+
is often easier than figuring out how many wildcards you need in a -Name search.
172+
#>
173+
BeforeAll {
174+
# Try calling Get-Command in a PowerShell console to see the typical output!
175+
$Commands = Get-Command
176+
}
177+
178+
It 'lists available commands' {
179+
$Commands.Count | Should -Be __
180+
$Commands[7].Name | Should -Be '__'
181+
}
182+
183+
It 'indicates the type of command' {
184+
$CommandTypes = $Commands | Select-Object -ExpandProperty CommandType | Sort-Object -Unique
185+
186+
@('__', '__', 'Cmdlet') | Should -Be $CommandTypes
187+
}
188+
189+
It 'can filter the output by keywords' {
190+
$Command = Get-Command -Name "*-Child*"
191+
$CimCommand = Get-Command -Name '__'
192+
193+
$Command.CommandType | Should -Be 'Cmdlet'
194+
$Command.Name | Should -Be '__'
195+
$CimCommand.Name | Should -Be 'Get-CimClass'
196+
}
197+
198+
It 'can look for commands by verb' {
199+
$GetCommands = Get-Command -Verb 'Get'
200+
$GetCommands.Count | Should -Be __
201+
202+
$GetCommands[4].Name | Should -Be '__'
203+
}
204+
205+
It 'can look for commands by noun' {
206+
$DateCommands = Get-Command -Noun 'Date'
207+
208+
$DateCommands.Count | Should -Be __
209+
$DateCommands[0].Name | Should -Be '__'
210+
}
211+
212+
It 'can look for commands by module' {
213+
$KoanCommands = Get-Command -Module 'PSKoans'
214+
215+
$KoanCommands.Count | Should -Be __
216+
$KoanCommands.Name | Should -Be @('__', '__', '__', '__')
217+
}
142218
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#Requires -Module PSKoans
2+
[Koan(Position = 212)]
3+
param()

0 commit comments

Comments
 (0)