Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ namespace PowershellTestConfigNamespace

It "Validate Register-PSSessionConfiguration with ApplicationBase, AssemblyName and ConfigurationTypeName parameter" -Pending {

$null = Register-PSSessionConfiguration -Name $TestSessionConfigName -ApplicationBase $script:TestAssemblyDir -AssemblyName $LocalTestAssemblyName -ConfigurationTypeName "PowershellTestConfigNamespace.PowershellTestConfig" -force
$null = Register-PSSessionConfiguration -Name $TestSessionConfigName -ApplicationBase $script:TestAssemblyDir -AssemblyName $LocalTestAssemblyName -ConfigurationTypeName "PowershellTestConfigNamespace.PowershellTestConfig" -Force

ValidateRemoteEndpoint -TestSessionConfigName $TestSessionConfigName -ScriptToExecute $null -ExpectedOutput $true -ExpectedError $null
}
Expand Down Expand Up @@ -566,7 +566,7 @@ namespace PowershellTestConfigNamespace

It "Validate Set-PSSessionConfiguration with ApplicationBase, AssemblyName and ConfigurationTypeName parameter" -Pending {

$null = Set-PSSessionConfiguration -Name $TestSessionConfigName -ApplicationBase $script:TestAssemblyDir -AssemblyName $LocalTestAssemblyName -ConfigurationTypeName "PowershellTestConfigNamespace.PowershellTestConfig" -force
$null = Set-PSSessionConfiguration -Name $TestSessionConfigName -ApplicationBase $script:TestAssemblyDir -AssemblyName $LocalTestAssemblyName -ConfigurationTypeName "PowershellTestConfigNamespace.PowershellTestConfig" -Force

ValidateRemoteEndpoint -TestSessionConfigName $TestSessionConfigName -ScriptToExecute $null -ExpectedOutput $true -ExpectedError $null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Describe "Basic FileSystem Provider Tests" -Tags "CI" {
$topPath = Join-Path $TestDrive $longDir
$longDirPath = Join-Path $topPath $longSubDir
$longFilePath = Join-Path $longDirPath $fileName
$null = New-Item -itemtype file -path $longFilePath -force
$null = New-Item -ItemType file -Path $longFilePath -Force

$longFilePath | Should -Exist

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ Describe "Remove-Item" -Tags "CI" {
$streamfile = Join-Path -Path $testpath -ChildPath $fileName
$streamdir = Join-Path -Path $testpath -ChildPath $dirName

$null = New-Item -Path $streamfile -ItemType "File" -force
$null = New-Item -Path $streamfile -ItemType "File" -Force
Add-Content -Path $streamfile -Value $fileContent
Add-Content -Path $streamfile -Stream $streamName -Value $streamContent
$null = New-Item -Path $streamdir -ItemType "Directory" -Force
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ Describe "Get-Alias DRT Unit Tests" -Tags "CI" {

It "Get-Alias DisplayName should always show AliasName -> ResolvedCommand for all aliases" {
Set-Alias -Name Test-MyAlias -Value Get-Command -Force
Set-Alias -Name tma -Value Test-MyAlias -force
Set-Alias -Name tma -Value Test-MyAlias -Force
$aliases = Get-Alias Test-MyAlias, tma
$aliases | ForEach-Object {
$_.DisplayName | Should -Be "$($_.Name) -> Get-Command"
Expand Down
2 changes: 1 addition & 1 deletion test/powershell/engine/Basic/Encoding.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ Describe "File encoding tests" -Tag CI {
)
}
BeforeEach {
Remove-Item TESTDRIVE:/* -force -ErrorAction Ignore
Remove-Item TESTDRIVE:/* -Force -ErrorAction Ignore
}
It "'<command> has a warning when '-Encoding utf7' is used" -TestCases $testCases {
param ($command, $script)
Expand Down
56 changes: 56 additions & 0 deletions test/powershell/engine/Basic/ParameterCapitalization.Tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

# Guardrail for parameter casing in PowerShell tests (see #26614).
# Parameters are case-insensitive at runtime, but source style prefers PascalCase
# (e.g. -Force, -ErrorAction) for readability and consistency with docs/examples.

Describe "Parameter capitalization in PowerShell test scripts" -Tags @("CI") {
BeforeAll {
# test/powershell/engine/Basic -> repo root is four levels up
$repoRoot = (Resolve-Path (Join-Path $PSScriptRoot "../../../..")).Path
$scanRoot = Join-Path $repoRoot "test/powershell"

# High-frequency switches that should appear PascalCase in source.
# Intentional lowercase uses (binding case-insensitivity tests, stream fixtures)
# are allowlisted by relative path below.
# Negative lookbehind allows start-of-line as well as whitespace/pipe.
$parameterPattern = '(?<![\w-])-(force|erroraction|warningaction|verbose|debug|whatif|confirm)(?=[\s:\|]|$)'

$allowlistRelativePaths = @(
"test/powershell/Language/Scripting/CommonParameters.Tests.ps1"
"test/powershell/Language/Parser/BNotOperator.Tests.ps1"
"test/powershell/Language/Parser/RedirectionOperator.Tests.ps1"
)
}

It "Flags fully-lowercase common parameters (e.g. -force / -erroraction)" {
$files = Get-ChildItem -Path $scanRoot -Recurse -Include *.ps1, *.psm1 -File -ErrorAction Stop

$violations = [System.Collections.Generic.List[string]]::new()
foreach ($file in $files) {
$rel = $file.FullName.Substring($repoRoot.Length).TrimStart('\', '/').Replace('\', '/')
if ($allowlistRelativePaths -contains $rel) {
continue
}

# Avoid automatic $matches variable
$stringHits = Select-String -Path $file.FullName -Pattern $parameterPattern -CaseSensitive -AllMatches
foreach ($hit in $stringHits) {
$trim = $hit.Line.TrimStart()
# Comments that only discuss the switch are fine.
if ($trim.StartsWith('#')) {
continue
}
$violations.Add(("{0}:{1}: {2}" -f $rel, $hit.LineNumber, $hit.Line.Trim()))
}
}

if ($violations.Count -gt 0) {
$header = "Found $($violations.Count) lowercase common-parameter(s). Prefer PascalCase (e.g. -Force, -ErrorAction). See PowerShell/PowerShell#26614."
throw ($header + [Environment]::NewLine + ($violations -join [Environment]::NewLine))
}

$violations.Count | Should -Be 0
}
}