PsWrite.Tests.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
<# .SYNOPSIS TEST TDD RDS .DESCRIPTION Unblock-File .EXAMPLE While ($true) {$test = Invoke-Pester -CodeCoverage .\RDS.Tests.ps1 -PassThru; $test.FailedCount; start-sleep -s 15} .EXAMPLE https://github.com/pester/Pester/wiki/Should Be BeExactly BeGreaterThan BeGreaterOrEqual BeIn BeLessThan BeLessOrEqual BeLike BeLikeExactly BeOfType BeTrue BeFalse HaveCount Contain Exist FileContentMatch FileContentMatchExactly FileContentMatchMultiline Match MatchExactly Throw BeNullOrEmpty .NOTES Alopez 2017 Em@il : alban.lopez@gmail.com require https://github.com/pester/Pester https://github.com/pester/Pester/wiki/Should Get-ChildItem C:\Users\alopez\Documents\WindowsPowerShell\Modules\Pester\ -Recurse | Unblock-File #> $psd1 = $MyInvocation.MyCommand.Source -replace ('\.Tests\.ps1', '.psd1') $psd1 | Import-Module -Force #Get-ChildItem $("$($MyInvocation.MyCommand.Path)\RDS.Tests.ps1" -replace('\.Tests\.ps1', '*.psm1')) | %{Import-Module $_.FullName -Force} function global:Write-LogStep {} function global:Write-Color {} Describe "Module - Testing Manifest File (.psd1)" { Context "Manifest" { It "Test-ModuleManifest $psd1" { {Test-ModuleManifest $psd1 -ea Stop} | Should -not -Throw } $Manifest = Test-ModuleManifest $psd1 -ea 0 It "Manifest Version" { $Manifest.Version -ge [version]'0.0.0.1' | Should -BeTrue } It "Manifest commands" { $Manifest.ExportedCommands.count | Should -not -BeNullOrEmpty } } } Describe "Write-* real test" { # $global:JENKINS = $false Context "Console Mode" { $psd1 | Import-Module -Force function Global:Write-Host($Object) { $Object } #Mock Write-Host {$true} It "Write-Host" { write-host 'test' | Should -Be 'test' } It "Write-color" { ( write-color 0,1,2,3,4,5,6 -fore red,cyan) -join('') | Should -Be '0123456' } It "Write-logstep ok" { (write-logstep '0,1,2,3','4,5' ok ) -join('') | Should -Match "\[ OK \] .*" } It "Write-logstep error" { (write-logstep '0,1,2,3','4,5',6 error ) -join('') | Should -Match "\[ Error! \] .*" } It "Write-logstep Other" { (write-logstep '0,1,2,3','4,5',6 Other -LogTrace .\fake.txt ) -join('') | Should -Match "\[ Other\? \] .*" } It "Write-logstep info" { (write-logstep '0,1,2,3','4,5',6 info -LogTrace vdiv03 ) -join('') | Should -Match "\[ Info \] .*" } It "Write-logstep long warn" { (write-logstep 'Try with long title for cut it ','Try with long message for cut it' -prefixe '%caller% L.%line%' warn ) -join('') | Should -Match "\[ Warn \] .*" } It "Write-Object" { (write-Object @{x='0,1,2,3'} -fore red ) -join('') | Should -Match "`"x`": `"0,1,2,3`"" } It "Write-Center" { (write-Center 'center' -fore black ) -join('') | Should -Match " *center *" } It "Write-ProgressBarreColor" { (Write-ProgressBarreColor 50 -Width 20 -block 'X' -empty '-') -join('') | should -be '[XXXXXXXXX---------] 50,0%' } } $global:JENKINS = $true $psd1 | Import-Module -Force Context "Jenkins Mode" { function Global:Write-HostOriginal($Object) { $Object } It "Write-color" { ( write-color @('Green ','DarkGreen ','Black ','Red ','DarkRed ','Yellow ','DarkYellow ','Blue ','DarkBlue ','Magenta ','DarkMagenta ','Cyan ','DarkCyan ','White ','Gray ','DarkGray') ` -ForeGroundColor Red,DarkRed,Yellow,DarkYellow,Blue,DarkBlue,Magenta,DarkMagenta,Cyan,DarkCyan,White,Gray,DarkGray ` -BackGroundColor Green,DarkGreen,Black,Red,DarkRed,Yellow,DarkYellow,Blue,DarkBlue,Magenta,DarkMagenta,Cyan,DarkCyan,White,Gray,DarkGray ) -join('') | Should -Be '[91;102mGreen [0m[31;42mDarkGreen [0m[93mBlack [0m[33;101mRed [0m[94;41mDarkRed [0m[34;103mYellow [0m[95;43mDarkYellow [0m[35;104mBlue [0m[96;44mDarkBlue [0m[36;105mMagenta [0m[97;45mDarkMagenta [0m[37;106mCyan [0m[90;46mDarkCyan [0m[91;107mWhite [0m[31;47mGray [0m[93;100mDarkGray[0m' } } }# > $global:JENKINS = $false $psd1 | Import-Module -Force function Global:Write-Host($Object) { $Object } Describe "Man" { Context "CodeFuntion" { It "Build-Readme.md" { {Build-Readme.md '*.psm1' -MarkDownFileName 'README.md'} | Should -Not -Throw } } } $metaData = New-Object System.Management.Automation.CommandMetaData (Get-Command 'Microsoft.PowerShell.Utility\Write-Host') Invoke-Expression "function Global:Write-Host { $([System.Management.Automation.ProxyCommand]::create($metaData)) }" $psd1 | Import-Module -Force |