removed exit from Format-Checklist (#43)

* removed exit from Format-Checklist

* xplat fix for Initialize-Repo
bugfix-exports
Chris Kuech 2019-09-23 18:03:23 -07:00 committed by GitHub
parent 28e05d161f
commit bd59f83a8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 211 additions and 210 deletions

View File

@ -1,6 +1,6 @@
$preCommitHook = @"
#/bin/bash
#!/bin/bash
pwsh ./test/Checkpoint-Output.ps1
git add ./test/integration
@ -9,4 +9,6 @@ git add ./test/integration
$preCommitHookPath = "$PSScriptRoot/.git/hooks/pre-commit"
$preCommitHook > $preCommitHookPath
chmod u+x $preCommitHookPath
if (-not $IsWindows) {
chmod u+x $preCommitHookPath
}

View File

@ -8,83 +8,82 @@ $ErrorActionPreference = "Stop"
."$PSScriptRoot\types.ps1"
function writePending($timestamp, $description) {
$symbol = " "
$color = "Yellow"
$message = "$timestamp [ $symbol ] $description"
Write-Host $message -ForegroundColor $color -NoNewline
$symbol = " "
$color = "Yellow"
$message = "$timestamp [ $symbol ] $description"
Write-Host $message -ForegroundColor $color -NoNewline
}
function writeSuccess($timestamp, $description, $clearString) {
$symbol = [char]8730
$color = "Green"
$message = "$timestamp [ $symbol ] $description"
Write-Host "`r$clearString" -NoNewline
Write-Host "`r$message" -ForegroundColor $color
$symbol = [char]8730
$color = "Green"
$message = "$timestamp [ $symbol ] $description"
Write-Host "`r$clearString" -NoNewline
Write-Host "`r$message" -ForegroundColor $color
}
function writeFail($timestamp, $description, $clearString) {
$symbol = "X"
$color = "Red"
$message = "$timestamp [ $symbol ] $description"
Write-Host "`r$clearString" -NoNewline
Write-Host "`n$message`n" -ForegroundColor $color
exit -1
$symbol = "X"
$color = "Red"
$message = "$timestamp [ $symbol ] $description"
Write-Host "`r$clearString" -NoNewline
Write-Host "`n$message`n" -ForegroundColor $color
}
$fsm = @{
"Test Test Start $false" = {
writePending @args
@{
"Test Test Stop $true" = {
writeSuccess @args
$fsm
}
"Test Test Stop $false" = {
writeFail @args
}
}
}
"Set Set Start *" = {
writePending @args
@{
"Set Set Stop *" = {
writeSuccess @args
$fsm
}
}
}
"TestSet Test Start $false" = {
writePending @args
@{
"TestSet Test Stop $true" = {
writeSuccess @args
$fsm
}
"TestSet Test Stop $false" = {
"Test Test Start $false" = {
writePending @args
@{
"TestSet Set Start *" = {
@{
"TestSet Set Stop *" = {
@{
"TestSet Validate Start $false" = {
@{
"TestSet Validate Stop $true" = {
writeSuccess @args
$fsm
}
"TestSet Validate Stop $false" = {
writeFail @args
}
}
}
}
}
"Test Test Stop $true" = {
writeSuccess @args
$fsm
}
"Test Test Stop $false" = {
writeFail @args
}
}
}
"Set Set Start *" = {
writePending @args
@{
"Set Set Stop *" = {
writeSuccess @args
$fsm
}
}
}
"TestSet Test Start $false" = {
writePending @args
@{
"TestSet Test Stop $true" = {
writeSuccess @args
$fsm
}
"TestSet Test Stop $false" = {
@{
"TestSet Set Start *" = {
@{
"TestSet Set Stop *" = {
@{
"TestSet Validate Start $false" = {
@{
"TestSet Validate Stop $true" = {
writeSuccess @args
$fsm
}
"TestSet Validate Stop $false" = {
writeFail @args
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
<#
@ -94,46 +93,46 @@ $fsm = @{
Uses Write-Host
#>
function Format-Checklist {
[CmdletBinding()]
Param(
# Logged Requirement lifecycle events
[Parameter(Mandatory, ValueFromPipeline)]
[Alias("Event")]
[RequirementEvent[]]$RequirementEvent
)
[CmdletBinding()]
Param(
# Logged Requirement lifecycle events
[Parameter(Mandatory, ValueFromPipeline)]
[Alias("Event")]
[RequirementEvent[]]$RequirementEvent
)
begin {
$previousRequirement = $null
$nextFsm = $fsm
}
begin {
$previousRequirement = $null
$nextFsm = $fsm
}
process {
$requirement = $_.Requirement
process {
$requirement = $_.Requirement
# build state vector
$requirementType = ("Test", "Set" | ? { $requirement.$_ }) -join ""
$method = $_.Method
$lifecycleState = $_.State
$successResult = if ($method -eq "Set") { "*" } else { [bool]$_.Result }
$stateVector = "$requirementType $method $lifecycleState $successResult"
# build state vector
$requirementType = ("Test", "Set" | ? { $requirement.$_ }) -join ""
$method = $_.Method
$lifecycleState = $_.State
$successResult = if ($method -eq "Set") { "*" } else { [bool]$_.Result }
$stateVector = "$requirementType $method $lifecycleState $successResult"
# build transition arguments
$timestamp = Get-Date -Date $_.Date -Format "hh:mm:ss"
$description = $requirement.Describe
$clearString = ' ' * "??:??:?? [ ? ] $($previousRequirement.Describe)".Length
$transitionArgs = @($timestamp, $description, $clearString)
# build transition arguments
$timestamp = Get-Date -Date $_.Date -Format "hh:mm:ss"
$description = $requirement.Describe
$clearString = ' ' * "??:??:?? [ ? ] $($previousRequirement.Describe)".Length
$transitionArgs = @($timestamp, $description, $clearString)
# transition FSM
if (-not $nextFsm[$stateVector]) {
throw @"
# transition FSM
if (-not $nextFsm[$stateVector]) {
throw @"
Format-Checklist has reached an unexpected state '$stateVector'.
If you are piping the output of Invoke-Requirement directly to this
cmdlet, then this is probably a bug in Format-Checklist.
"@
}
$nextFsm = &$nextFsm[$stateVector] @transitionArgs
$previousRequirement = $requirement
}
$nextFsm = &$nextFsm[$stateVector] @transitionArgs
$previousRequirement = $requirement
}
}
<#
@ -143,79 +142,79 @@ cmdlet, then this is probably a bug in Format-Checklist.
Uses Write-Host
#>
function Format-CallStack {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
[CmdletBinding()]
Param(
# Logged Requirement lifecycle events
[Parameter(Mandatory, ValueFromPipeline)]
[Alias("Event")]
[RequirementEvent[]]$RequirementEvent
)
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSAvoidUsingWriteHost", "")]
[CmdletBinding()]
Param(
# Logged Requirement lifecycle events
[Parameter(Mandatory, ValueFromPipeline)]
[Alias("Event")]
[RequirementEvent[]]$RequirementEvent
)
begin {
$context = [Stack[string]]::new()
}
process {
$timestamp = Get-Date -Date $_.Date -Format 'hh:mm:ss'
$name = $_.Requirement.Name
$description = $_.Requirement.Describe
$method, $state, $result = $_.Method, $_.State, $_.Result
switch ($method) {
"Test" {
switch ($state) {
"Start" {
$context.Push($name)
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] BEGIN TEST $description"
}
"Stop" {
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] END TEST => $result"
$context.Pop() | Out-Null
}
}
}
"Set" {
switch ($state) {
"Start" {
$context.Push($name)
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] BEGIN SET $description"
}
"Stop" {
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] END SET"
$context.Pop() | Out-Null
}
}
}
"Validate" {
switch ($state) {
"Start" {
$context.Push($name)
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] BEGIN TEST $description"
}
"Stop" {
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] END TEST => $result"
$context.Pop() | Out-Null
}
}
}
begin {
$context = [Stack[string]]::new()
}
process {
$timestamp = Get-Date -Date $_.Date -Format 'hh:mm:ss'
$name = $_.Requirement.Name
$description = $_.Requirement.Describe
$method, $state, $result = $_.Method, $_.State, $_.Result
switch ($method) {
"Test" {
switch ($state) {
"Start" {
$context.Push($name)
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] BEGIN TEST $description"
}
"Stop" {
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] END TEST => $result"
$context.Pop() | Out-Null
}
}
}
"Set" {
switch ($state) {
"Start" {
$context.Push($name)
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] BEGIN SET $description"
}
"Stop" {
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] END SET"
$context.Pop() | Out-Null
}
}
}
"Validate" {
switch ($state) {
"Start" {
$context.Push($name)
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] BEGIN TEST $description"
}
"Stop" {
$callstack = $context.ToArray()
[array]::Reverse($callstack)
$serialized = $callstack -join ">"
Write-Host "$timestamp [$serialized] END TEST => $result"
$context.Pop() | Out-Null
}
}
}
}
}
}
}

View File

@ -1,2 +1,2 @@
10:27:29 [MyName] BEGIN SET MyDescribe
10:27:29 [MyName] END SET
05:22:35 [MyName] BEGIN SET MyDescribe
05:22:35 [MyName] END SET

View File

@ -1,2 +1,2 @@
10:27:29 [MyName] BEGIN TEST MyDescribe
10:27:29 [MyName] END TEST => True
05:22:34 [MyName] BEGIN TEST MyDescribe
05:22:34 [MyName] END TEST => True

View File

@ -1,6 +1,6 @@
10:27:29 [MyName] BEGIN TEST MyDescribe
10:27:29 [MyName] END TEST => False
10:27:29 [MyName] BEGIN SET MyDescribe
10:27:29 [MyName] END SET
10:27:29 [MyName] BEGIN TEST MyDescribe
10:27:29 [MyName] END TEST => True
05:22:35 [MyName] BEGIN TEST MyDescribe
05:22:35 [MyName] END TEST => False
05:22:35 [MyName] BEGIN SET MyDescribe
05:22:35 [MyName] END SET
05:22:35 [MyName] BEGIN TEST MyDescribe
05:22:35 [MyName] END TEST => True

View File

@ -1,3 +1,3 @@
10:27:29 [ ] MyDescribe
10:27:29 [ √ ] MyDescribe
05:22:35 [ ] MyDescribe
05:22:35 [ √ ] MyDescribe

View File

@ -1,3 +1,3 @@
10:27:29 [ ] MyDescribe
10:27:29 [ √ ] MyDescribe
05:22:34 [ ] MyDescribe
05:22:34 [ √ ] MyDescribe

View File

@ -1,3 +1,3 @@
10:27:29 [ ] MyDescribe
10:27:29 [ √ ] MyDescribe
05:22:35 [ ] MyDescribe
05:22:35 [ √ ] MyDescribe

View File

@ -1,6 +1,6 @@
Date Method State Result Requirement
---- ------ ----- ------ -----------
9/21/19 10:27:29 AM Set Start MyName
9/21/19 10:27:29 AM Set Stop True MyName
Date Method State Result Requirement
---- ------ ----- ------ -----------
9/23/2019 5:22:35 PM Set Start MyName
9/23/2019 5:22:35 PM Set Stop True MyName

View File

@ -1,6 +1,6 @@
Date Method State Result Requirement
---- ------ ----- ------ -----------
9/21/19 10:27:29 AM Test Start MyName
9/21/19 10:27:29 AM Test Stop True MyName
Date Method State Result Requirement
---- ------ ----- ------ -----------
9/23/2019 5:22:34 PM Test Start MyName
9/23/2019 5:22:34 PM Test Stop True MyName

View File

@ -1,10 +1,10 @@
Date Method State Result Requirement
---- ------ ----- ------ -----------
9/21/19 10:27:29 AM Test Start MyName
9/21/19 10:27:29 AM Test Stop False MyName
9/21/19 10:27:29 AM Set Start MyName
9/21/19 10:27:29 AM Set Stop True MyName
9/21/19 10:27:29 AM Validate Start MyName
9/21/19 10:27:29 AM Validate Stop True MyName
Date Method State Result Requirement
---- ------ ----- ------ -----------
9/23/2019 5:22:35 PM Test Start MyName
9/23/2019 5:22:35 PM Test Stop False MyName
9/23/2019 5:22:35 PM Set Start MyName
9/23/2019 5:22:35 PM Set Stop True MyName
9/23/2019 5:22:35 PM Validate Start MyName
9/23/2019 5:22:35 PM Validate Stop True MyName