microsoft / Requirements

PowerShell framework for declaratively defining and idempotently imposing system configurations
MIT License
159 stars 26 forks source link

Format-Checklist cosmetic error in the test output #17

Closed omiossec closed 5 years ago

omiossec commented 5 years ago

While working on some examples with Requirements I have noticed that output for the test state in on the same line

11:46:46 [   ] Create a folder for the app11:46:46 [   ] Create the json config File
$WebConfigRequirements = @(
    @{
        name = "AppFolder"
        describe = "Create a folder for the app" 
        test = {
            test-path -Path $AppPath
        }
        set = {
            new-item -path $AppPath -ItemType Directory
        }
    },
    @{
        name = "configfile"
        describe = "Create the json config File"
        test = {
            test-path -Path "$($AppPath)config.json"
        }
        set = {
            new-item -Path "$($AppPath)config.json"
        }
    }
)
$WebConfigRequirements | Invoke-Requirement | Format-Checklist

I will make some investigation on it

chriskuech commented 5 years ago

What terminal app/host do you use? Also what powershell version?

omiossec commented 5 years ago

I use PowerShell core 6.2.1 on Windows

Here's the script I use to reproduce

$ErrorActionPreference = "Stop"
Import-Module Requirements

$AppPath = "c:\work\dotnetbot1\"

$WebConfigRequirements = @(
    @{
        name = "AppFolder"
        describe = "Create a folder for the app" 
        test = {
            test-path -Path $AppPath
        }
        set = {
            new-item -path $AppPath -ItemType Directory
        }
    },
    @{
        name = "configfile"
        describe = "Create the json config File"
        test = {
            test-path -Path "$($AppPath)config.json"
        }
        set = {
            new-item -Path "$($AppPath)config.json"
        }
    }

)

$WebConfigRequirements | Invoke-Requirement | Format-Checklist

image

As you can see the first time it works but for the second time no newline

it's the same with Windows PowerShell 5.1 on Windows 10

image

If you had a requirement

@{
        name = "configfile-yaml"
        describe = "Create the yaml config File"
        test = {
            test-path -Path "$($AppPath)config.yaml"
        }
        set = {
            new-item -Path "$($AppPath)config.yaml"
        }
    }

it's worst image

I use the version 2.2.2 of the module

chriskuech commented 5 years ago

My top guess right now is that Format-Checklist has a bug where it only writes the green checkmark line if it Sets, so the Test text is never overwritten with a terminating newline.

I can look into this tonight.

chriskuech commented 5 years ago

So I confirmed my hypothesis, but I also identified more scenarios that are unaccounted for in the current implementation. I will have to determine all the problematic scenarios and probably rewrite much of Format-Checklist.

chriskuech commented 5 years ago

Had a breakthrough and ended up only needing to add one more event handler. This should be resolved now.