mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Redirecting to a variable should be possible (#20381)
* add tests * fix formatting issues * Make redirection to variable an experimental feature. Update test to check for experimental feature status. Set-Variable will still have the -append parameter, but if used when the experimental feature is disabled, a parameter binding error will result. * Check to be sure provider is not null. * update to use different FullyQualifiedErrorId * use Experimental attribute for append parameter rather than runtime check. * Revert "update to use different FullyQualifiedErrorId" This reverts commit 8b34af1ac19ecdb821b34534e446ab129830c92f. * Update src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs Co-authored-by: Ilya <darpa@yandex.ru> * Move remediation steps into resource. Update Set-Variable -Append to be correct when -name and -value are used. Add tests for the new behavior in Set-Variable. * Change expected error for contrained language mode and redirection. * Update src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs Co-authored-by: Ilya <darpa@yandex.ru> * Support redirection of native app. Add tests to validate. * testexe needs proper case to run on linux. * Address codefactor issues 01. * Update src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs Co-authored-by: Steve Lee <slee@microsoft.com> * Update src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs Co-authored-by: Steve Lee <slee@microsoft.com> * Update src/System.Management.Automation/engine/runtime/Operations/MiscOps.cs Co-authored-by: Steve Lee <slee@microsoft.com> --------- Co-authored-by: Ilya <darpa@yandex.ru> Co-authored-by: Steve Lee <slee@microsoft.com>
This commit is contained in:
co-authored by
Ilya
Steve Lee
parent
7108ae0027
commit
167a492415
+1
-1
@@ -460,7 +460,7 @@ try
|
||||
$rs.Open()
|
||||
$pl = $rs.CreatePipeline('"Hello" > c:\temp\foo.txt')
|
||||
|
||||
$e = { $pl.Invoke() } | Should -Throw -ErrorId "CmdletInvocationException"
|
||||
$e = { $pl.Invoke() } | Should -Throw -ErrorId "DriveNotFoundException"
|
||||
|
||||
$rs.Dispose()
|
||||
}
|
||||
|
||||
@@ -241,4 +241,47 @@ Describe "Set-Variable" -Tags "CI" {
|
||||
{ Set-Variable globalVar -Value 1 -Scope local -Force } | Should -Not -Throw
|
||||
}
|
||||
}
|
||||
|
||||
Context "Set-Variable -Append tests" {
|
||||
BeforeAll {
|
||||
if (! (Get-ExperimentalFeature PSRedirectToVariable).Enabled) {
|
||||
$skipTest = $true
|
||||
}
|
||||
|
||||
$testCases = @{ value = 2; Count = 2 },
|
||||
@{ value = @(2,3,4); Count = 2},
|
||||
@{ value = "abc",(Get-Process -Id $PID) ; count = 2}
|
||||
}
|
||||
|
||||
It "Can append values <value> to a variable" -testCases $testCases {
|
||||
param ($value, $count)
|
||||
|
||||
if ($skipTest) {
|
||||
Set-ItResult -skip -because "Experimental Feature PSRedirectToVariable not enabled"
|
||||
return
|
||||
}
|
||||
|
||||
$variableName = "testVar"
|
||||
Set-Variable -Name $variableName -Value 1
|
||||
Set-Variable -Name $variableName -Value $value -Append
|
||||
|
||||
$observedValues = Get-Variable $variableName -Value
|
||||
|
||||
$observedValues.Count | Should -Be $count
|
||||
$observedValues[0] | Should -Be 1
|
||||
|
||||
$observedValues[1] | Should -Be $value
|
||||
}
|
||||
|
||||
It "Can use set-variable via streaming and append values" {
|
||||
if ($skipTest) {
|
||||
Set-ItResult -skip -because "Experimental Feature PSRedirectToVariable not enabled"
|
||||
return
|
||||
}
|
||||
|
||||
$testVar = 1
|
||||
4..6 | Set-Variable -Name testVar -Append
|
||||
$testVar | Should -Be @(1,4,5,6)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user