Enabled and fixed formatters unit tests (#12)
`formatters.tests.ps1` file name had a type and was not being picked up by Pester. As such, formatter bugs were not being caught. This PR fixes the typo thus enabling the unit tests. It also fixes the bugs in `Format-Callstack` that were exposed from enabling the unit tests.format-callstack-doc-img
parent
f94c7b7865
commit
929f6a4310
|
@ -1,124 +1,124 @@
|
|||
@{
|
||||
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'src\module.psm1'
|
||||
# Script module or binary module file associated with this manifest.
|
||||
RootModule = 'src\module.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '2.2'
|
||||
# Version number of this module.
|
||||
ModuleVersion = '2.2.1'
|
||||
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
# Supported PSEditions
|
||||
# CompatiblePSEditions = @()
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'c14a3682-ef9f-40ed-9521-ef74b433a755'
|
||||
# ID used to uniquely identify this module
|
||||
GUID = 'c14a3682-ef9f-40ed-9521-ef74b433a755'
|
||||
|
||||
# Author of this module
|
||||
Author = 'Chris Kuech'
|
||||
# Author of this module
|
||||
Author = 'Chris Kuech'
|
||||
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
# Company or vendor of this module
|
||||
CompanyName = 'Microsoft Corporation'
|
||||
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2018 Microsoft Corporation. All rights reserved.'
|
||||
# Copyright statement for this module
|
||||
Copyright = '(c) 2018 Microsoft Corporation. All rights reserved.'
|
||||
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'PowerShell framework for declaratively defining and idempotently imposing system configurations'
|
||||
# Description of the functionality provided by this module
|
||||
Description = 'PowerShell framework for declaratively defining and idempotently imposing system configurations'
|
||||
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
# PowerShellVersion = ''
|
||||
# Minimum version of the Windows PowerShell engine required by this module
|
||||
# PowerShellVersion = ''
|
||||
|
||||
# Name of the Windows PowerShell host required by this module
|
||||
# PowerShellHostName = ''
|
||||
# Name of the Windows PowerShell host required by this module
|
||||
# PowerShellHostName = ''
|
||||
|
||||
# Minimum version of the Windows PowerShell host required by this module
|
||||
# PowerShellHostVersion = ''
|
||||
# Minimum version of the Windows PowerShell host required by this module
|
||||
# PowerShellHostVersion = ''
|
||||
|
||||
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# DotNetFrameworkVersion = ''
|
||||
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# DotNetFrameworkVersion = ''
|
||||
|
||||
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# CLRVersion = ''
|
||||
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
|
||||
# CLRVersion = ''
|
||||
|
||||
# Processor architecture (None, X86, Amd64) required by this module
|
||||
# ProcessorArchitecture = ''
|
||||
# Processor architecture (None, X86, Amd64) required by this module
|
||||
# ProcessorArchitecture = ''
|
||||
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
# RequiredModules = @()
|
||||
# Modules that must be imported into the global environment prior to importing this module
|
||||
# RequiredModules = @()
|
||||
|
||||
# Assemblies that must be loaded prior to importing this module
|
||||
# RequiredAssemblies = @()
|
||||
# Assemblies that must be loaded prior to importing this module
|
||||
# RequiredAssemblies = @()
|
||||
|
||||
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||
ScriptsToProcess = @(
|
||||
'src\types.ps1'
|
||||
)
|
||||
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
|
||||
ScriptsToProcess = @(
|
||||
'src\types.ps1'
|
||||
)
|
||||
|
||||
# Type files (.ps1xml) to be loaded when importing this module
|
||||
# TypesToProcess = @()
|
||||
# Type files (.ps1xml) to be loaded when importing this module
|
||||
# TypesToProcess = @()
|
||||
|
||||
# Format files (.ps1xml) to be loaded when importing this module
|
||||
# FormatsToProcess = @()
|
||||
# Format files (.ps1xml) to be loaded when importing this module
|
||||
# FormatsToProcess = @()
|
||||
|
||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||
# NestedModules = @()
|
||||
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
|
||||
# NestedModules = @()
|
||||
|
||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||
FunctionsToExport = @(
|
||||
'Format-CallStack',
|
||||
'Format-Checklist',
|
||||
'Invoke-Requirement',
|
||||
'New-Requirement',
|
||||
'Set-Requirement',
|
||||
'Test-Requirement'
|
||||
)
|
||||
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
|
||||
FunctionsToExport = @(
|
||||
'Format-CallStack',
|
||||
'Format-Checklist',
|
||||
'Invoke-Requirement',
|
||||
'New-Requirement',
|
||||
'Set-Requirement',
|
||||
'Test-Requirement'
|
||||
)
|
||||
|
||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||
CmdletsToExport = @()
|
||||
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
|
||||
CmdletsToExport = @()
|
||||
|
||||
# Variables to export from this module
|
||||
VariablesToExport = '*'
|
||||
# Variables to export from this module
|
||||
VariablesToExport = '*'
|
||||
|
||||
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
|
||||
AliasesToExport = @()
|
||||
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
|
||||
AliasesToExport = @()
|
||||
|
||||
# DSC resources to export from this module
|
||||
# DscResourcesToExport = @()
|
||||
# DSC resources to export from this module
|
||||
# DscResourcesToExport = @()
|
||||
|
||||
# List of all modules packaged with this module
|
||||
# ModuleList = @()
|
||||
# List of all modules packaged with this module
|
||||
# ModuleList = @()
|
||||
|
||||
# List of all files packaged with this module
|
||||
# FileList = @()
|
||||
# List of all files packaged with this module
|
||||
# FileList = @()
|
||||
|
||||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||
PrivateData = @{
|
||||
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
|
||||
PrivateData = @{
|
||||
|
||||
PSData = @{
|
||||
PSData = @{
|
||||
|
||||
# Tags applied to this module. These help with module discovery in online galleries.
|
||||
# Tags = @()
|
||||
# Tags applied to this module. These help with module discovery in online galleries.
|
||||
# Tags = @()
|
||||
|
||||
# A URL to the license for this module.
|
||||
LicenseUri = 'https://github.com/Microsoft/Requirements/blob/master/LICENSE'
|
||||
# A URL to the license for this module.
|
||||
LicenseUri = 'https://github.com/Microsoft/Requirements/blob/master/LICENSE'
|
||||
|
||||
# A URL to the main website for this project.
|
||||
ProjectUri = 'https://github.com/Microsoft/Requirements'
|
||||
# A URL to the main website for this project.
|
||||
ProjectUri = 'https://github.com/Microsoft/Requirements'
|
||||
|
||||
# A URL to an icon representing this module.
|
||||
# IconUri = ''
|
||||
# A URL to an icon representing this module.
|
||||
# IconUri = ''
|
||||
|
||||
# ReleaseNotes of this module
|
||||
# ReleaseNotes = ''
|
||||
# ReleaseNotes of this module
|
||||
# ReleaseNotes = ''
|
||||
|
||||
} # End of PSData hashtable
|
||||
} # End of PSData hashtable
|
||||
|
||||
} # End of PrivateData hashtable
|
||||
} # End of PrivateData hashtable
|
||||
|
||||
# HelpInfo URI of this module
|
||||
# HelpInfoURI = ''
|
||||
# HelpInfo URI of this module
|
||||
# HelpInfoURI = ''
|
||||
|
||||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||
# DefaultCommandPrefix = ''
|
||||
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
|
||||
# DefaultCommandPrefix = ''
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -89,6 +89,7 @@ function Format-CallStack {
|
|||
}
|
||||
|
||||
process {
|
||||
$timestamp = Get-Date -Date $_.Date -Format 'hh:mm:ss'
|
||||
$name = $_.Requirement.Name
|
||||
$description = $_.Requirement.Describe
|
||||
$method, $state, $result = $_.Method, $_.State, $_.Result
|
||||
|
@ -100,13 +101,13 @@ function Format-CallStack {
|
|||
$callstack = $context.ToArray()
|
||||
[array]::Reverse($callstack)
|
||||
$serialized = $callstack -join ">"
|
||||
Write-Host "$($_.Date) [$serialized] BEGIN TEST $description"
|
||||
Write-Host "$timestamp [$serialized] BEGIN TEST $description"
|
||||
}
|
||||
"Stop" {
|
||||
$callstack = $context.ToArray()
|
||||
[array]::Reverse($callstack)
|
||||
$serialized = $callstack -join ">"
|
||||
Write-Host "$($_.Date) [$serialized] END TEST => $result"
|
||||
Write-Host "$timestamp [$serialized] END TEST => $result"
|
||||
$context.Pop() | Out-Null
|
||||
}
|
||||
}
|
||||
|
@ -118,13 +119,13 @@ function Format-CallStack {
|
|||
$callstack = $context.ToArray()
|
||||
[array]::Reverse($callstack)
|
||||
$serialized = $callstack -join ">"
|
||||
Write-Host "$($_.Date) [$serialized] BEGIN SET $description"
|
||||
Write-Host "$timestamp [$serialized] BEGIN SET $description"
|
||||
}
|
||||
"Stop" {
|
||||
$callstack = $context.ToArray()
|
||||
[array]::Reverse($callstack)
|
||||
$serialized = $callstack -join ">"
|
||||
Write-Host "$($_.Date) [$serialized] END SET"
|
||||
Write-Host "$timestamp [$serialized] END SET"
|
||||
$context.Pop() | Out-Null
|
||||
}
|
||||
}
|
||||
|
@ -136,13 +137,13 @@ function Format-CallStack {
|
|||
$callstack = $context.ToArray()
|
||||
[array]::Reverse($callstack)
|
||||
$serialized = $callstack -join ">"
|
||||
Write-Host "$($_.Date) [$serialized] BEGIN TEST $description"
|
||||
Write-Host "$timestamp [$serialized] BEGIN TEST $description"
|
||||
}
|
||||
"Stop" {
|
||||
$callstack = $context.ToArray()
|
||||
[array]::Reverse($callstack)
|
||||
$serialized = $callstack -join ">"
|
||||
Write-Host "$($_.Date) [$serialized] END TEST => $result"
|
||||
Write-Host "$timestamp [$serialized] END TEST => $result"
|
||||
$context.Pop() | Out-Null
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,78 +0,0 @@
|
|||
|
||||
."$PSScriptRoot\formatters.ps1"
|
||||
|
||||
function invoke($Requirement) {
|
||||
[RequirementEvent]@{
|
||||
Requirement = $Requirement
|
||||
Method = "Test"
|
||||
State = "Start"
|
||||
}
|
||||
[RequirementEvent]@{
|
||||
Requirement = $Requirement
|
||||
Method = "Test"
|
||||
State = "Stop"
|
||||
Result = $false
|
||||
}
|
||||
[RequirementEvent]@{
|
||||
Requirement = $Requirement
|
||||
Method = "Set"
|
||||
State = "Start"
|
||||
}
|
||||
[RequirementEvent]@{
|
||||
Requirement = $Requirement
|
||||
Method = "Set"
|
||||
State = "Stop"
|
||||
Result = $null
|
||||
}
|
||||
[RequirementEvent]@{
|
||||
Requirement = $Requirement
|
||||
Method = "Validate"
|
||||
State = "Start"
|
||||
}
|
||||
[RequirementEvent]@{
|
||||
Requirement = $Requirement
|
||||
Method = "Validate"
|
||||
State = "Stop"
|
||||
Result = $true
|
||||
}
|
||||
}
|
||||
|
||||
Describe "formatters" {
|
||||
Mock Get-Date { return "00:00:00" }
|
||||
$script:InDesiredState = 0
|
||||
$requirement = @{
|
||||
Name = "simple-requirement"
|
||||
Describe = "Simple Requirement"
|
||||
Test = { $script:InDesiredState++ }
|
||||
Set = { }
|
||||
}
|
||||
$events = invoke $requirement
|
||||
$tempContainer = if ($env:TEMP) { $env:TEMP } else { $env:TMPDIR }
|
||||
Context "Format-Table" {
|
||||
$output = $events | Format-Table | Out-String
|
||||
It "Should print a non-empty string" {
|
||||
$output.Trim().Length | Should -BeGreaterThan 10
|
||||
}
|
||||
}
|
||||
Context "Format-Checklist" {
|
||||
$path = "$tempContainer\$(New-Guid).txt"
|
||||
$events | Format-Checklist *> $path
|
||||
$output = Get-Content $path -Raw
|
||||
Remove-Item $path
|
||||
It "Should format each line as a checklist" {
|
||||
$output | Should -Match "^\d\d:\d\d:\d\d \[ . \] Simple Requirement"
|
||||
}
|
||||
}
|
||||
Context "Format-Callstack" {
|
||||
$path = "$tempContainer\$(New-Guid).txt"
|
||||
$events | Format-CallStack *> $path
|
||||
$output = Get-Content $path -Raw
|
||||
Remove-Item $path
|
||||
It "Should format each line as a callstack" {
|
||||
$output | % { $_ | Should -Match "^\d\d:\d\d:\d\d \[.+\] .+" }
|
||||
}
|
||||
It "Should print 6 lines" {
|
||||
$output.Count | Should -Be 6
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
|
||||
."$PSScriptRoot\formatters.ps1"
|
||||
|
||||
function invoke($Requirement) {
|
||||
[RequirementEvent]::new($Requirement, "Test", "Start")
|
||||
[RequirementEvent]::new($Requirement, "Test", "Stop", $false)
|
||||
[RequirementEvent]::new($Requirement, "Set", "Start")
|
||||
[RequirementEvent]::new($Requirement, "Set", "Stop", $null)
|
||||
[RequirementEvent]::new($Requirement, "Validate", "Start")
|
||||
[RequirementEvent]::new($Requirement, "Validate", "Stop", $true)
|
||||
}
|
||||
|
||||
Describe "formatters" {
|
||||
Mock Get-Date { return "00:00:00" }
|
||||
$script:InDesiredState = 0
|
||||
$requirement = @{
|
||||
Name = "simple-requirement"
|
||||
Describe = "Simple Requirement"
|
||||
Test = { $script:InDesiredState++ }
|
||||
Set = { }
|
||||
}
|
||||
$events = invoke $requirement
|
||||
$tempContainer = if ($env:TEMP) { $env:TEMP } else { $env:TMPDIR }
|
||||
Context "Format-Table" {
|
||||
$output = $events | Format-Table | Out-String
|
||||
It "Should print a non-empty string" {
|
||||
$output.Trim().Length | Should -BeGreaterThan 10
|
||||
}
|
||||
}
|
||||
Context "Format-Checklist" {
|
||||
$path = "$tempContainer\$(New-Guid).txt"
|
||||
$events | Format-Checklist *> $path
|
||||
$output = Get-Content $path -Raw
|
||||
Remove-Item $path
|
||||
It "Should format each line as a checklist" {
|
||||
$output | Should -Match "^\d\d:\d\d:\d\d \[ . \] Simple Requirement"
|
||||
}
|
||||
}
|
||||
Context "Format-Callstack" {
|
||||
$path = "$tempContainer\$(New-Guid).txt"
|
||||
$events | Format-CallStack *> $path
|
||||
$output = Get-Content $path
|
||||
Remove-Item $path
|
||||
It "Should format each line as a callstack" {
|
||||
$output | % { $_ | Should -Match "^\d\d:\d\d:\d\d \[.+\] .+" }
|
||||
}
|
||||
It "Should print 6 lines" {
|
||||
$output.Count | Should -Be 6
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue