File tree 13 files changed +90
-17
lines changed
Count-and-Length/PSCustomObject
Number-of-returned-objects
v5-LiteralPath-Recurse-ignores-Include
13 files changed +90
-17
lines changed Original file line number Diff line number Diff line change 1
1
2
- if ($PSVersionTable.PSVersion.Major -le 2 ) {return task v2}
2
+ $Version = $PSVersionTable.PSVersion
3
+ if ($Version.Major -le 2 ) {return task v2}
3
4
4
5
task Test-1 .normal.vs.custom {
5
6
($r = ./ Test-1 .normal.vs.custom.ps1)
6
7
equals $r.Count 2
7
8
equals $r [0 ] ' normal.Count: 1'
8
- equals $r [1 ] ' custom.Count: '
9
+ if ($Version -ge ([version ]' 6.0.9999' )) {
10
+ equals $r [1 ] ' custom.Count: 1'
11
+ }
12
+ else {
13
+ equals $r [1 ] ' custom.Count: '
14
+ }
9
15
}
10
16
11
17
task Test-2 .Select-Object {
@@ -14,5 +20,10 @@ task Test-2.Select-Object {
14
20
equals $r [0 ] ' Get-Some 2 : 2'
15
21
equals $r [1 ] ' Get-Some 1 : 1'
16
22
equals $r [2 ] ' Get-Some 2 | Select-Object : 2'
17
- equals $r [3 ] ' Get-Some 1 | Select-Object : '
23
+ if ($Version -ge ([version ]' 6.0.9999' )) {
24
+ equals $r [3 ] ' Get-Some 1 | Select-Object : 1'
25
+ }
26
+ else {
27
+ equals $r [3 ] ' Get-Some 1 | Select-Object : '
28
+ }
18
29
}
Original file line number Diff line number Diff line change 1
1
2
2
### PSCustomObject does not have surrogate Count and Length
3
3
4
+ ** Fixed in v6.1.0**
5
+
4
6
See help * about_Properties* :
5
7
6
8
Beginning in Windows PowerShell 3.0, Windows PowerShell tries
Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ Set-StrictMode -Off
13
13
# "normal" objects have surrogate Count
14
14
" normal.Count: $ ( $normal.Count ) "
15
15
16
+ # v6.1.0 -- fixed
16
17
# "custom" objects do not have surrogate Count
17
18
# $custom.Count is either $null or error in the strict mode
18
19
" custom.Count: $ ( $custom.Count ) "
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ Set-StrictMode -Off
15
15
" Get-Some 2 : $ ( (Get-Some 2 ).Count) "
16
16
" Get-Some 1 : $ ( (Get-Some 1 ).Count) "
17
17
18
+ # v6.1.0 -- fixed, gets expected 1
18
19
# get Count 2 (expected) and $null/error (may be unexpected)
19
20
" Get-Some 2 | Select-Object : $ ( (Get-Some 2 | Select-Object Name).Count) "
20
21
" Get-Some 1 | Select-Object : $ ( (Get-Some 1 | Select-Object Name).Count) "
Original file line number Diff line number Diff line change 1
1
2
2
$v2 = $PSVersionTable.PSVersion.Major -eq 2
3
+ $v610 = $PSVersionTable.PSVersion -gt ([version ]' 6.0.9999' )
3
4
4
5
task test1.no.results {
5
6
($r = .\test1.no.results.ps1)
@@ -44,7 +45,12 @@ task test4.one.object.Count {
44
45
task test5.PSCustomObject {
45
46
($r = ./ test5.PSCustomObject.ps1)
46
47
equals $r.Count 3
47
- if ($v2 ) {
48
+ if ($v610 ) {
49
+ equals $r [0 ] 1
50
+ equals $r [1 ] $false
51
+ equals $r [2 ] PSCustomObject
52
+ }
53
+ elseif ($v2 ) {
48
54
equals $r [0 ] 2
49
55
equals $r [1 ] $false
50
56
equals $r [2 ] Hashtable
Original file line number Diff line number Diff line change @@ -39,9 +39,9 @@ cannot be used safely. See [Count-and-Length/Strict-Mode](../Count-and-Length/St
39
39
Secondly, if the only returned object has native ` Count ` or ` Length ` then the
40
40
native value has nothing to do with 1, the number of returned objects.
41
41
42
- Thirdly, the ` PSCustomObject ` is an exception to this rule. A collection of
43
- these objects will have a correct count, but a single object will return
44
- ` $null ` for ` Count ` .
42
+ Thirdly ( ** Fixed in v6.1.0 ** ) , the ` PSCustomObject ` is an exception to this
43
+ rule. A collection of these objects will have a correct count, but a single
44
+ object will return ` $null ` for ` Count ` .
45
45
46
46
``` powershell
47
47
$object = [PSCustomObject]@{Name='Joe'; Age=42}
Original file line number Diff line number Diff line change 1
1
2
- $Version = $PSVersionTable.PSVersion.Major
3
- if ($Version -ge 3 ) {
4
- Set-StrictMode - Off
2
+ $Version = $PSVersionTable.PSVersion
3
+ if ($Version -ge ([version ]' 3.0.0' ) -and $Version -lt ([version ]' 6.0.9999' )) {
4
+ Set-StrictMode - Off
5
+ }
6
+ else {
7
+ Set-StrictMode - Version Latest
5
8
}
6
9
7
10
$object = [PSCustomObject ]@ {Name = ' Joe' ; Age = 42 }
@@ -10,6 +13,9 @@ $object = [PSCustomObject]@{Name='Joe'; Age=42}
10
13
# v3+:
11
14
# - $null, $true, PSCustomObject
12
15
# - error in strict mode (v5)
16
+ # v6.1.0
17
+ # - 1, $false, PSCustomObject
18
+ # - no error in strict mode
13
19
14
20
$object.Count
15
21
$null -eq $object.Count
Original file line number Diff line number Diff line change 1
1
2
+ ### PowerShell v6.1.0-preview.1
3
+
4
+ - [ Count-and-Length\PSCustomObject] ( Basic\Count-and-Length\PSCustomObject )
5
+ -- Fixed
6
+ - [ Number-of-returned-objects] ( Basic\Number-of-returned-objects )
7
+ -- Fixed for ` PSCustomObject ` , same as above
8
+ - [ Get-ChildItem\Directory-with-backticks] ( Cmdlets\Get-ChildItem\Directory-with-backticks )
9
+ -- ` Get-ChildItem ` does not fail in the empty directory but still fails in not empty
10
+ - [ v5-LiteralPath-Recurse-ignores-Include] ( Cmdlets\Get-ChildItem\v5-LiteralPath-Recurse-ignores-Include )
11
+ - Fixed the v5 regression
12
+
2
13
### PowerShell v6-RC Core
3
14
4
15
- [ Strict-mode-ErrorRecord-formatting] ( Basic\Strict-mode-ErrorRecord-formatting )
Original file line number Diff line number Diff line change 1
1
2
+ $v610 = $PSVersionTable.PSVersion -ge ([version ]' 6.0.9999' )
3
+
2
4
task Test-1 {
3
5
($r = .\Test-1.ps1 )
4
- equals $r.FullyQualifiedErrorId ' PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand'
6
+ if ($v610 ) {
7
+ equals $r.Count 2
8
+ equals $r [0 ] ' v6.1.0 worked'
9
+ equals $r [1 ].FullyQualifiedErrorId ' ItemNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand'
10
+ }
11
+ else {
12
+ equals $r.FullyQualifiedErrorId ' PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand'
13
+ }
5
14
}
Original file line number Diff line number Diff line change 1
1
2
2
$ErrorActionPreference = ' Stop'
3
- Set-Location - LiteralPath ( Split-Path $MyInvocation .MyCommand.Path )
3
+ $v610 = $PSVersionTable .PSVersion -ge ([ version ] ' 6.0.9999 ' )
4
4
5
- # make directory with backticks and cd to it
5
+ # make directory with backticks, cd to it
6
+ $root = Split-Path $MyInvocation.MyCommand.Path
7
+ Set-Location - LiteralPath $root
6
8
$null = mkdir ' ``test``'
7
9
Set-Location - LiteralPath ' ``test``'
8
10
11
+ # try Get-ChildItem * in the directory with backticks
9
12
try {
10
- # it fails "Cannot find path '...\`test`'
13
+ # v2-v6.0.2 - fails "Cannot find path '...\`test`'
11
14
Get-ChildItem *
15
+
16
+ # v6.1.0 - does not fail in the empty directory, but see next
17
+ ' v6.1.0 worked'
12
18
}
13
19
catch {
14
20
$_
15
21
}
16
22
23
+ # v6.1.0
24
+ if ($v610 ) {
25
+ # make a file
26
+ [System.IO.File ]::WriteAllText((Join-Path $root ' ``test``/z.txt' ), ' text' )
27
+
28
+ # try Get-ChildItem * again in the directory with a file
29
+ try {
30
+ # fails "Could not find item ...\`test`\z.txt"
31
+ Get-ChildItem *
32
+ }
33
+ catch {
34
+ $_
35
+ }
36
+ }
37
+
17
38
# remove test directory
18
39
Set-Location ..
19
- Remove-Item - LiteralPath ' ``test``'
40
+ Remove-Item - LiteralPath ' ``test``' - Force - Recurse
Original file line number Diff line number Diff line change 1
1
2
2
$Version = $PSVersionTable.PSVersion.Major
3
+ $v610 = $PSVersionTable.PSVersion -ge ([version ]' 6.0.9999' )
3
4
4
5
task Test-1 .Path {
5
6
$r = .\Test-1 .Path.ps1
@@ -11,7 +12,7 @@ task Test-2.Path {
11
12
$r = .\Test-2 .LiteralPath.ps1
12
13
($r = @ ($r | Group-Object Extension - NoElement))
13
14
14
- if ($Version -ge 5 -or $Version -eq 2 ) {
15
+ if ($Version -eq 2 -or ( $Version -ge 5 -and ! $v610 ) ) {
15
16
# unexpected
16
17
assert ($r.Count -ge 2 )
17
18
}
Original file line number Diff line number Diff line change 1
1
2
- ### v5 and v2: Get-ChildItem -LiteralPath -Recurse ignores -Include
2
+ ### Get-ChildItem -LiteralPath -Recurse ignores -Include
3
+
4
+ (Affected versions: v2, v5 - v6.0.2, ** Fixed in v6.1.0** )
3
5
4
6
This command (see [ Test-1.Path.ps1] ( Test-1.Path.ps1 ) )
5
7
Original file line number Diff line number Diff line change 1
1
2
2
# This command with LiteralPath in v5 and v2 gets all items instead of expected *.exe
3
+ # v6.1.0 -- fixed
4
+
3
5
Get-ChildItem - LiteralPath $PSHOME - Include * .exe - Recurse
You can’t perform that action at this time.
0 commit comments