-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add -StrictMode to Invoke-Command to allow specifying strict mode when invoking command locally
#16545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
daxian-dbw
merged 31 commits into
PowerShell:master
from
Thomas-Yu:StrictMode-for-Invoke-Command
Jan 12, 2022
Merged
Add -StrictMode to Invoke-Command to allow specifying strict mode when invoking command locally
#16545
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
58d9846
Invoke-Command with StrictModeVersion parameter, Invoke-Command tests…
Thomas-Yu 521836b
Syntax Fixes
Thomas-Yu f3d1e55
Unit Test Naming Changes
Thomas-Yu 03952d1
Updated to support piped input
Thomas-Yu 5f54b27
Changes made
Thomas-Yu d951b40
Updated tests
Thomas-Yu ea03341
Dotnet files removed
Thomas-Yu c23e680
Implemented experimental feature
Thomas-Yu d4020bc
Added experimental attribute for parameter
Thomas-Yu ca5f673
Syntax
Thomas-Yu 6d919fa
Merge
Thomas-Yu 39b929b
Adjusted test file
Thomas-Yu d2d3e51
Got rid of unnecessary error check in strictmodeversion parameter
Thomas-Yu aca32fc
Adjusted InternalCommands.cs file to have ValidateVersion class as in…
Thomas-Yu 0f1fb60
Strictmodeoff added, new test
Thomas-Yu 30693b5
Syntax
Thomas-Yu 1d9bc83
Syntax
Thomas-Yu 543253e
Changes
Thomas-Yu 5173f10
Slight fix
Thomas-Yu 4eff4c9
small fix
Thomas-Yu 94f4a3a
Parameter fixes
Thomas-Yu 0ac2c69
Change didnt get saved for last push
Thomas-Yu 5af61ac
Added psstrictmodeassignment
Thomas-Yu 0af0d9a
-StrictMode off works
Thomas-Yu 36842db
variable name change
Thomas-Yu d353c9d
Changed field
Thomas-Yu 792a425
.
Thomas-Yu 7d7e665
Revert internalcommands.cs changes
Thomas-Yu ef9086b
syntax
Thomas-Yu ca47c60
accepts off
Thomas-Yu 1edfaed
syntax
Thomas-Yu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
test/powershell/Modules/Microsoft.PowerShell.Core/Invoke-Command.Tests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Copyright (c) Microsoft Corporation. | ||
| # Licensed under the MIT License. | ||
|
|
||
| Describe "Invoke-Command" -Tags "CI" { | ||
| Context "StrictMode tests" { | ||
| BeforeAll { | ||
| $skipTest = !($EnabledExperimentalFeatures -contains "PSStrictModeAssignment"); | ||
| If (Test-Path Variable:InvokeCommand__Test) { | ||
| Remove-Item Variable:InvokeCommand__Test | ||
| } | ||
| } | ||
|
|
||
| It "Setting -StrictMode parameter with uninitialized variable throws error" -skip:$skipTest { | ||
| { Invoke-Command -StrictMode 3.0 {$InvokeCommand__Test} } | Should -Throw -ErrorId 'VariableIsUndefined' | ||
| } | ||
|
|
||
| It "Setting -StrictMode parameter with initialized variable does not throw error" -skip:$skipTest { | ||
| $InvokeCommand__Test = 'Something' | ||
| Invoke-Command -StrictMode 3.0 {$InvokeCommand__Test} | Should -Be 'Something' | ||
| Remove-Item Variable:InvokeCommand__Test | ||
| } | ||
|
|
||
| It "-StrictMode parameter sets StrictMode back to original state after process completes" -skip:$skipTest { | ||
| { Invoke-Command -StrictMode 3.0 {$InvokeCommand__Test} } | Should -Throw -ErrorId 'VariableIsUndefined' | ||
| { Invoke-Command {$InvokeCommand__Test} } | Should -Not -Throw | ||
| } | ||
|
|
||
| It "-StrictMode parameter works on piped input" -skip:$skipTest { | ||
| "There" | Invoke-Command -ScriptBlock { "Hello $input" } -StrictMode 3.0 | Should -Be 'Hello There' | ||
| { "There" | Invoke-Command -ScriptBlock { "Hello $InvokeCommand__Test" } -StrictMode 3.0 } | Should -Throw -ErrorId 'VariableIsUndefined' | ||
| } | ||
|
|
||
| It "-StrictMode latest works" -skip:$skipTest { | ||
| { Invoke-Command -StrictMode latest {$InvokeCommand__Test} } | Should -Throw -ErrorId 'VariableIsUndefined' | ||
| } | ||
|
|
||
| It "-StrictMode off works" -skip:$skipTest { | ||
| { Invoke-Command -StrictMode off {$InvokeCommand__Test} } | Should -Not -Throw | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Thomas-Yu , @daxian-dbw For the record, I don't think it was necessary to split the attribute/conversion classes into two separate implementations. Soon,
Set-StrictModewill also take theoffvalue for strict mode version, which means merging these two classes back together. In the mean time, there was no harm in having one set of attribute/conversion implementations. Now whenSet-StrictModeis updated to also supportoffthis work will have to be refactored yet again.@Thomas-Yu Please create an Issue in PowerShell repo that adds
offto theSet-StrictMode -Versionparameter. The committee would like to see it work the same as forInvoke-Commandhere for consistency, although it is not necessary to include the changes in this PR.