Skip to content

Commit cf697b6

Browse files
committed
test: 优化测试用例并跳过废弃函数测试
- 在filesystem.Tests.ps1中使用AsObject参数避免控制台输出 - 在install.Tests.ps1中移除冗余的详细输出测试 - 在help.Tests.ps1中标记废弃函数测试为跳过并添加静默警告
1 parent 36eed2d commit cf697b6

3 files changed

Lines changed: 10 additions & 11 deletions

File tree

psutils/tests/filesystem.Tests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ temp*
2525
}
2626

2727
It "基本功能测试 - 显示目录树" {
28-
# 由于Get-Tree默认输出到控制台,我们测试它不抛出异常
29-
{ Get-Tree -Path $testRoot -MaxDepth 1 } | Should -Not -Throw
28+
# 测试Get-Tree函数不抛出异常,使用AsObject避免控制台输出
29+
{ $null = Get-Tree -Path $testRoot -MaxDepth 1 -AsObject $true } | Should -Not -Throw
3030
}
3131

3232
It "AsObject参数测试 - 返回对象" {

psutils/tests/help.Tests.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,26 +14,26 @@ BeforeAll {
1414
$script:TestModulePath = "$PSScriptRoot\.."
1515
}
1616

17-
Describe "Search-ModuleHelp 函数测试" {
17+
Describe "Search-ModuleHelp 函数测试" -Skip {
1818
Context "基本搜索功能" {
1919
It "应该能够搜索到包含指定关键词的函数" {
2020
# Test deprecated function
21-
$results = Search-ModuleHelp -SearchTerm "install" -ModulePath $script:TestModulePath
21+
$results = Search-ModuleHelp -SearchTerm "install" -ModulePath $script:TestModulePath -WarningAction SilentlyContinue
2222
$results | Should -Not -BeNullOrEmpty
2323
$results.Count | Should -BeGreaterThan 0
2424
}
2525

2626
It "应该能够精确搜索指定的函数名" {
2727
# Test deprecated function
28-
$results = Search-ModuleHelp -FunctionName "Get-OperatingSystem" -ModulePath $script:TestModulePath
28+
$results = Search-ModuleHelp -FunctionName "Get-OperatingSystem" -ModulePath $script:TestModulePath -WarningAction SilentlyContinue
2929
if ($results) {
3030
$results.Name | Should -Be "Get-OperatingSystem"
3131
}
3232
}
3333

3434
It "搜索不存在的函数应该返回空结果" {
3535
# Test deprecated function
36-
$results = Search-ModuleHelp -FunctionName "NonExistentFunction" -ModulePath $script:TestModulePath
36+
$results = Search-ModuleHelp -FunctionName "NonExistentFunction" -ModulePath $script:TestModulePath -WarningAction SilentlyContinue
3737
$results | Should -BeNullOrEmpty
3838
}
3939
}
@@ -42,14 +42,14 @@ Describe "Search-ModuleHelp 函数测试" {
4242
It "无效的模块路径应该产生错误" {
4343
# Test deprecated function
4444
# Test deprecated function
45-
{ Search-ModuleHelp -SearchTerm "test" -ModulePath "C:\NonExistentPath" -ErrorAction Stop } | Should -Throw
45+
{ Search-ModuleHelp -SearchTerm "test" -ModulePath "C:\NonExistentPath" -ErrorAction Stop -WarningAction SilentlyContinue } | Should -Throw
4646
}
4747
}
4848

4949
Context "结果格式验证" {
5050
It "返回的结果应该包含必要的属性" {
5151
# Test deprecated function
52-
$results = Search-ModuleHelp -SearchTerm "Get" -ModulePath $script:TestModulePath
52+
$results = Search-ModuleHelp -SearchTerm "Get" -ModulePath $script:TestModulePath -WarningAction SilentlyContinue
5353
if ($results) {
5454
$result = $results[0]
5555
$result.PSObject.Properties.Name | Should -Contain "Name"

psutils/tests/install.Tests.ps1

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ Describe "Test-ModuleInstalled 函数测试" {
1717

1818
It "应该支持详细输出" {
1919
# 测试详细输出模式
20-
$VerbosePreference = 'Continue'
21-
{ Test-ModuleInstalled -ModuleName "Microsoft.PowerShell.Management" -Verbose } | Should -Not -Throw
22-
$VerbosePreference = 'SilentlyContinue'
20+
# 测试模块安装检查功能,不输出详细信息
21+
{ Test-ModuleInstalled -ModuleName "Microsoft.PowerShell.Management" } | Should -Not -Throw
2322
}
2423

2524
It "应该处理包含特殊字符的模块名" {

0 commit comments

Comments
 (0)