-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shift dynamic positional parameters, fix #217
- Loading branch information
1 parent
f8502cc
commit b359090
Showing
6 changed files
with
74 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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 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 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
48 changes: 48 additions & 0 deletions
48
Tests/Issues/152-positional-script-parameters/152.test.ps1
This file contains 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,48 @@ | ||
|
||
# Issue #152 (1). Also test the bootstrapping scenario. | ||
# This used to fail on the second call of z.ps1. | ||
task DoNotMakeScriptParametersNamed { | ||
# self-invoking build script | ||
Set-Content z.ps1 { | ||
param( | ||
[Parameter()]$Tasks | ||
) | ||
if (!$MyInvocation.ScriptName.EndsWith('Invoke-Build.ps1')) { | ||
return Invoke-Build $Tasks $MyInvocation.MyCommand.Path @PSBoundParameters | ||
} | ||
task Test {} | ||
} | ||
|
||
# invoke the script twice with the task name | ||
./z.ps1 Test | ||
./z.ps1 Test | ||
|
||
remove z.ps1 | ||
} | ||
|
||
<# | ||
Issue #152 (2). Test positional parameters. | ||
Potential problem: | ||
- `Task` and `P1` both have position 0. | ||
- `File` and `P2` both have position 1. | ||
UPDATE: yes, it is a problem, see #217 | ||
Fortunate current behaviour: | ||
PowerShell somehow does what we expect, shift positions of P1, P2, P3. | ||
This may change in the future, so let at least cover this by test. | ||
Workarounds for the future: | ||
- Use `[CmdletBinding(PositionalBinding=$false)]` (PowerShell v3+) to enforce named parameters. | ||
- Set parameter positions explicitly starting with 2 (0, 1 are consumed by Task, File). | ||
UPDATE: This is used by #217 (shift +2) | ||
#> | ||
task PositionalParameters { | ||
Set-Content z.build.ps1 { | ||
param($P1, $P2, $P3) | ||
task Parameters {"$P1|$P2|$P3"} | ||
} | ||
|
||
# invoke the script with 5 positional parameters | ||
($r = Invoke-Build Parameters z.build.ps1 v1 v2 v3) | ||
assert ($r -contains 'v1|v2|v3') | ||
|
||
remove z.build.ps1 | ||
} |
10 changes: 10 additions & 0 deletions
10
Tests/Issues/217-bad-error-on-unknown-parameter/217.build.ps1
This file contains 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,10 @@ | ||
<# https://github.com/nightroman/Invoke-Build/issues/217 | ||
#152 fixed one issue but added another, cryptic errors. | ||
#217 shifts script parameters positions (+2) avoiding conflicts with IB Task and File. | ||
#> | ||
|
||
param( | ||
$MyParam1 #! this parameter position 0 conflicts with IB Task | ||
) | ||
|
||
task . |
This file contains 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,9 @@ | ||
|
||
task UnknownParameter { | ||
try { | ||
throw Invoke-Build -bar | ||
} | ||
catch { | ||
equals "$_" "A parameter cannot be found that matches parameter name 'bar'." | ||
} | ||
} |