Skip to content

Commit a452d4b

Browse files
committed
v6.1.0-preview.1
- Count-and-Length/PSCustomObject - Basic/Number-of-returned-objects - Get-ChildItem/Directory-with-backticks, /v5-LiteralPath-Recurse-ignores-Include
1 parent 7b593f9 commit a452d4b

File tree

13 files changed

+90
-17
lines changed

13 files changed

+90
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11

2-
if ($PSVersionTable.PSVersion.Major -le 2) {return task v2}
2+
$Version = $PSVersionTable.PSVersion
3+
if ($Version.Major -le 2) {return task v2}
34

45
task Test-1.normal.vs.custom {
56
($r = ./Test-1.normal.vs.custom.ps1)
67
equals $r.Count 2
78
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+
}
915
}
1016

1117
task Test-2.Select-Object {
@@ -14,5 +20,10 @@ task Test-2.Select-Object {
1420
equals $r[0] 'Get-Some 2 : 2'
1521
equals $r[1] 'Get-Some 1 : 1'
1622
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+
}
1829
}

Basic/Count-and-Length/PSCustomObject/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
### PSCustomObject does not have surrogate Count and Length
33

4+
**Fixed in v6.1.0**
5+
46
See help *about_Properties*:
57

68
Beginning in Windows PowerShell 3.0, Windows PowerShell tries

Basic/Count-and-Length/PSCustomObject/Test-1.normal.vs.custom.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Set-StrictMode -Off
1313
# "normal" objects have surrogate Count
1414
"normal.Count: $($normal.Count)"
1515

16+
# v6.1.0 -- fixed
1617
# "custom" objects do not have surrogate Count
1718
# $custom.Count is either $null or error in the strict mode
1819
"custom.Count: $($custom.Count)"

Basic/Count-and-Length/PSCustomObject/Test-2.Select-Object.ps1

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Set-StrictMode -Off
1515
"Get-Some 2 : $((Get-Some 2).Count)"
1616
"Get-Some 1 : $((Get-Some 1).Count)"
1717

18+
# v6.1.0 -- fixed, gets expected 1
1819
# get Count 2 (expected) and $null/error (may be unexpected)
1920
"Get-Some 2 | Select-Object : $((Get-Some 2 | Select-Object Name).Count)"
2021
"Get-Some 1 | Select-Object : $((Get-Some 1 | Select-Object Name).Count)"

Basic/Number-of-returned-objects/.test.ps1

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
$v2 = $PSVersionTable.PSVersion.Major -eq 2
3+
$v610 = $PSVersionTable.PSVersion -gt ([version]'6.0.9999')
34

45
task test1.no.results {
56
($r = .\test1.no.results.ps1)
@@ -44,7 +45,12 @@ task test4.one.object.Count {
4445
task test5.PSCustomObject {
4546
($r = ./test5.PSCustomObject.ps1)
4647
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) {
4854
equals $r[0] 2
4955
equals $r[1] $false
5056
equals $r[2] Hashtable

Basic/Number-of-returned-objects/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ cannot be used safely. See [Count-and-Length/Strict-Mode](../Count-and-Length/St
3939
Secondly, if the only returned object has native `Count` or `Length` then the
4040
native value has nothing to do with 1, the number of returned objects.
4141

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`.
4545

4646
```powershell
4747
$object = [PSCustomObject]@{Name='Joe'; Age=42}

Basic/Number-of-returned-objects/test5.PSCustomObject.ps1

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11

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
58
}
69

710
$object = [PSCustomObject]@{Name='Joe'; Age=42}
@@ -10,6 +13,9 @@ $object = [PSCustomObject]@{Name='Joe'; Age=42}
1013
# v3+:
1114
# - $null, $true, PSCustomObject
1215
# - error in strict mode (v5)
16+
# v6.1.0
17+
# - 1, $false, PSCustomObject
18+
# - no error in strict mode
1319

1420
$object.Count
1521
$null -eq $object.Count

CHANGES.md

+11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,15 @@
11

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+
213
### PowerShell v6-RC Core
314

415
- [Strict-mode-ErrorRecord-formatting](Basic\Strict-mode-ErrorRecord-formatting)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11

2+
$v610 = $PSVersionTable.PSVersion -ge ([version]'6.0.9999')
3+
24
task Test-1 {
35
($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+
}
514
}
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,40 @@
11

22
$ErrorActionPreference = 'Stop'
3-
Set-Location -LiteralPath (Split-Path $MyInvocation.MyCommand.Path)
3+
$v610 = $PSVersionTable.PSVersion -ge ([version]'6.0.9999')
44

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
68
$null = mkdir '``test``'
79
Set-Location -LiteralPath '``test``'
810

11+
# try Get-ChildItem * in the directory with backticks
912
try {
10-
# it fails "Cannot find path '...\`test`'
13+
# v2-v6.0.2 - fails "Cannot find path '...\`test`'
1114
Get-ChildItem *
15+
16+
# v6.1.0 - does not fail in the empty directory, but see next
17+
'v6.1.0 worked'
1218
}
1319
catch {
1420
$_
1521
}
1622

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+
1738
# remove test directory
1839
Set-Location ..
19-
Remove-Item -LiteralPath '``test``'
40+
Remove-Item -LiteralPath '``test``' -Force -Recurse

Cmdlets/Get-ChildItem/v5-LiteralPath-Recurse-ignores-Include/.test.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
$Version = $PSVersionTable.PSVersion.Major
3+
$v610 = $PSVersionTable.PSVersion -ge ([version]'6.0.9999')
34

45
task Test-1.Path {
56
$r = .\Test-1.Path.ps1
@@ -11,7 +12,7 @@ task Test-2.Path {
1112
$r = .\Test-2.LiteralPath.ps1
1213
($r = @($r | Group-Object Extension -NoElement))
1314

14-
if ($Version -ge 5 -or $Version -eq 2) {
15+
if ($Version -eq 2 -or ($Version -ge 5 -and !$v610)) {
1516
# unexpected
1617
assert ($r.Count -ge 2)
1718
}

Cmdlets/Get-ChildItem/v5-LiteralPath-Recurse-ignores-Include/README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11

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**)
35

46
This command (see [Test-1.Path.ps1](Test-1.Path.ps1))
57

Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11

22
# This command with LiteralPath in v5 and v2 gets all items instead of expected *.exe
3+
# v6.1.0 -- fixed
4+
35
Get-ChildItem -LiteralPath $PSHOME -Include *.exe -Recurse

0 commit comments

Comments
 (0)