MegaBites-AI/Windows-powershell
0372
1# Copyright (c) Microsoft Corporation.2# Licensed under the MIT License.3Describe "Write-Verbose" -Tags "CI" {4 It "Should be able to call cmdlet without error" {5 { Write-Verbose -Message "test" -ErrorAction SilentlyContinue } | Should -Not -Throw6 }7 8 It "Should not display verbose output by default" {9 $VerbosePreference | Should -Be SilentlyContinue10 11 Write-Verbose -Message "test" | Should -BeNullOrEmpty12 }13 14 It "Should be able to set verbose output to display by changing the `$VerbosePreference automatic variable" {15 $VerbosePreference = "Continue"16 17 Write-Verbose -Message "test" 4>&1 | Should -Not -BeNullOrEmpty18 19 $VerbosePreference = "SilentlyContinue"20 }21 22 It "Should be able to set verbose output to display by using the verbose switch" {23 Write-Verbose -Message "test" -Verbose 4>&1 | Should -BeExactly "test"24 }25 26 It "Should be able to set verbose switch using a colon and boolean" {27 { Write-Verbose -Message "test" -Verbose:$false } | Should -Not -Throw28 29 $(Write-Verbose -Message "test" -Verbose:$true) 4>&1 | Should -BeExactly "test"30 }31 32 It "Should not have added line breaks" {33 $text = "0123456789"34 try {35 while ($text.Length -lt [Console]::WindowWidth) {36 $text += $text37 }38 } catch {39 # Ignore errors if the console doesn't support WindowWidth40 }41 $origVerbosePref = $VerbosePreference42 $VerbosePreference = "continue"43 try {44 $out = Write-Verbose $text 4>&145 $out | Should -BeExactly $text46 }47 finally {48 $VerbosePreference = $origVerbosePref49 }50 }51}52 