1

大家好,我写了一个示例脚本来查找给定的字符串是否为回文,如下所示

function Palindrome1([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
$sut = (Split-Path -Leaf $MyInvocation.MyCommand.Path) -replace '\.Tests\.', '.'
. "$here\$sut"

Describe "Palindrome1" {
    It "does something useful" {
        Palindrome1 "radar" | Should Be $true
    }
}

下面是调用脚本

$modulePath = "D:\Pester-master\Pester.psm1"
$SourceDir = "E:\Pester"
Import-Module $modulePath -ErrorAction Inquire
$outputFile = Join-Path $SourceDir "TEST-pester.xml"

$result = Invoke-Pester -Path $SourceDir -CodeCoverage "$SourceDir\*.ps1" -PassThru -OutputFile $outputFile

$result

我没有得到预期的结果,有人可以告诉我哪里做错了吗

4

1 回答 1

1

这个说法:

[string] $ReversString

是一个导致空字符串的值表达式。Palindrome1每次运行时,该函数都会输出该空字符串。将其更改为:

[string] $ReversString = ''
于 2016-08-15T12:33:53.510 回答