gpt4 book ai didi

powershell - Pester PowerShell测试提示多次输入

转载 作者:行者123 更新时间:2023-12-03 01:11:27 26 4
gpt4 key购买 nike

function Palindrome1
{
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string] $param
)

[string] $ReversString
$StringLength = @()

$StringLength = $param.Length

while ($StringLength -ge 0)
{
$ReversString = $ReversString + $param[$StringLength]
$StringLength--
}

if ($ReversString -eq $param)
{
return $true
}
else
{
return $false
}
}

我的 .tests.ps1
$here = Split-Path -Parent $MyInvocation.MyCommand.Path
. "$here\Palindrome1.ps1"

Describe -Tags "Example" "Palindrome1" {
It "does something useful" {
Palindrome1 | Should Be $true
}
}

Enter image description here

最佳答案

标记参数Mandatory时,必须为其提供输入值-否则将提示您输入一个值。

Get-Help about_Parameters :

 PARAMETER ATTRIBUTE TABLE [...]    Parameter Required?     This setting indicates whether the parameter is mandatory, that     is, whether all commands that use this cmdlet must include this     parameter. When the value is "True" and the parameter is missing     from the command, Windows PowerShell prompts you for a value for     the parameter.

Change your test to:

Describe -Tags "Example" "Palindrome1" {
It "does something useful" {
Palindrome1 -param "value goes here" | Should Be $true
}
}

关于powershell - Pester PowerShell测试提示多次输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38955495/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com