diff --git a/Docs/en-US/Format-Chronometer.md b/Docs/en-US/Format-Chronometer.md new file mode 100644 index 0000000..033c8e2 --- /dev/null +++ b/Docs/en-US/Format-Chronometer.md @@ -0,0 +1,126 @@ +--- +external help file: chronometer-help.xml +Module Name: chronometer +online version: +schema: 2.0.0 +--- + +# Format-Chronometer + +## SYNOPSIS + +## SYNTAX + +### Script (Default) +``` +Format-Chronometer [-InputObject ] [-WarningAt ] [-ErrorAt ] [-ShowAll] + [] +``` + +### Line +``` +Format-Chronometer [-Line ] [-WarningAt ] [-ErrorAt ] [-ShowAll] + [] +``` + +## DESCRIPTION +Generates a report from a Chronometer + +## EXAMPLES + +### EXAMPLE 1 +``` +$script = ls C:\workspace\PSGraph\PSGraph -Recurse -Filter *.ps1 +``` + +$resultes = Get-Chronometer -Path $script.fullname -ScriptBlock {Invoke-Pester C:\workspace\PSGraph} +$results | Format-Chronometer -WarnAt 20 -ErrorAt 200 + +## PARAMETERS + +### -ErrorAt +If the average time of a comamand is more than this, the output is red + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 200 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -InputObject +This is a MonitoredScript object from Get-Chronometer + +```yaml +Type: MonitoredScript[] +Parameter Sets: Script +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -Line +This is a ScriptLine object from a MonitoredScript object + +```yaml +Type: ScriptLine[] +Parameter Sets: Line +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -ShowAll +Forces the report to show scripts with no execution time + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: False +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -WarningAt +If the average time of a command is more than this, the output is yellow + +```yaml +Type: Int32 +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: 20 +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Docs/en-US/Get-Chronometer.md b/Docs/en-US/Get-Chronometer.md new file mode 100644 index 0000000..2ccdaf1 --- /dev/null +++ b/Docs/en-US/Get-Chronometer.md @@ -0,0 +1,88 @@ +--- +external help file: chronometer-help.xml +Module Name: chronometer +online version: +schema: 2.0.0 +--- + +# Get-Chronometer + +## SYNOPSIS + +## SYNTAX + +``` +Get-Chronometer [-Path ] [-LineNumber ] [[-ScriptBlock] ] [] +``` + +## DESCRIPTION +Loads a script and then tracks the line by line execution times + +## EXAMPLES + +### EXAMPLE 1 +``` +Get-Chronometer -Path .\example.ps1 -Script { +``` + +.\example.ps1 +} + +## PARAMETERS + +### -LineNumber +Line numbers within the script file to measure + +```yaml +Type: Int32[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Path +Script file to measure execution times on + +```yaml +Type: Object[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +### -ScriptBlock +The script to start the scrupt or execute other commands + +```yaml +Type: ScriptBlock +Parameter Sets: (All) +Aliases: Script, CommandScript + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. +For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +## OUTPUTS + +## NOTES + +## RELATED LINKS diff --git a/Docs/en-US/chronometer.md b/Docs/en-US/chronometer.md new file mode 100644 index 0000000..8d269f2 --- /dev/null +++ b/Docs/en-US/chronometer.md @@ -0,0 +1,19 @@ +--- +Module Name: chronometer +Module Guid: f3719c3c-008a-4b25-b94d-fc9f587f62dd +Download Help Link: {{Please enter FwLink manually}} +Help Version: {{Please enter version of help manually (X.X.X.X) format}} +Locale: en-US +--- + +# chronometer Module +## Description +{{Manually Enter Description Here}} + +## chronometer Cmdlets +### [Format-Chronometer](Format-Chronometer.md) +{{Manually Enter Format-Chronometer Description Here}} + +### [Get-Chronometer](Get-Chronometer.md) +{{Manually Enter Get-Chronometer Description Here}} + diff --git a/Tests/Classes/MonitoredScript.Tests.ps1 b/Tests/Classes/MonitoredScript.Tests.ps1 new file mode 100644 index 0000000..bf1abe1 --- /dev/null +++ b/Tests/Classes/MonitoredScript.Tests.ps1 @@ -0,0 +1,16 @@ +InModuleScope Chronometer { + + Describe "Class: MonitoredScript" -Tag Build { + + It "Creates an object" { + {[MonitoredScript]::New()} | Should Not Throw + } + + It "SetScript()" { + + $monitor = [MonitoredScript]::New() + {$monitor.SetScript("$PSScriptRoot\..\..\scratchfiles\example.ps1")} | Should Not Throw + } + } + +} diff --git a/Tests/Classes/ScriptLine.Tests.ps1 b/Tests/Classes/ScriptLine.Tests.ps1 new file mode 100644 index 0000000..dbe2244 --- /dev/null +++ b/Tests/Classes/ScriptLine.Tests.ps1 @@ -0,0 +1,16 @@ +InModuleScope Chronometer { + Describe "Class: ScriptLine" -Tag Build { + + It "Creates an Object" { + {[ScriptLine]::New()} | Should Not Throw + } + + It "ToString()" { + {[ScriptLine]::New().toString()} | Should Not Throw + } + + It "Creates an Object" { + {[ScriptLine]::New().AddExecutionTime(1)} | Should Not Throw + } + } +} diff --git a/Tests/Classes/ScriptProfiler.Tests.ps1 b/Tests/Classes/ScriptProfiler.Tests.ps1 new file mode 100644 index 0000000..1e499d2 --- /dev/null +++ b/Tests/Classes/ScriptProfiler.Tests.ps1 @@ -0,0 +1,13 @@ +InModuleScope Chronometer { + + Describe "Class: ScriptProfiler" -Tag Build { + + It "Creates an Object" { + {[ScriptProfiler]::New()} | Should Not Throw + } + + It "Start()" { + {[ScriptProfiler]::Start()} | Should Not Throw + } + } +} diff --git a/Tests/Format-Chronometer.Tests.ps1 b/Tests/Format-Chronometer.Tests.ps1 new file mode 100644 index 0000000..d9bc862 --- /dev/null +++ b/Tests/Format-Chronometer.Tests.ps1 @@ -0,0 +1,11 @@ +Describe "Function: Format-Chronometer" -Tag Build { + + It "Does not throw" { + {$null | Format-Chronometer } | Should Not Throw + } + + It "Can process a result object without throwing" { + $results = Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {. "$PSScriptRoot\..\ScratchFiles\example.ps1"} + $results | Format-Chronometer *>&1 | Should Not BeNullOrEmpty + } +} diff --git a/Tests/Get-Chronometer.Tests.ps1 b/Tests/Get-Chronometer.Tests.ps1 new file mode 100644 index 0000000..71d9a54 --- /dev/null +++ b/Tests/Get-Chronometer.Tests.ps1 @@ -0,0 +1,23 @@ +Describe "Function: Get-Chronometer" -Tag Build { + It "Does not throw" { + # Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"} + {Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {"Test"} } | Should Not Throw + } + + It "Executes a script and gives results" { + # Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"} + $results = Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {. "$PSScriptRoot\..\ScratchFiles\example.ps1"} + $results | Should Not BeNullOrEmpty + } + + It "Executes a script with linenumbers and gives results" { + # Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"} + $params = @{ + Path = "$PSScriptRoot\..\ScratchFiles\example.ps1" + Script = {. "$PSScriptRoot\..\ScratchFiles\example.ps1"} + LineNumber = 2,3,5,6 + } + $results = Get-Chronometer @params + $results | Should Not BeNullOrEmpty + } +} diff --git a/Tests/Help.Tests.ps1 b/Tests/Help.Tests.ps1 deleted file mode 100644 index 7a61ead..0000000 --- a/Tests/Help.Tests.ps1 +++ /dev/null @@ -1,30 +0,0 @@ -$projectRoot = Resolve-Path "$PSScriptRoot\.." -$moduleRoot = Split-Path (Resolve-Path "$projectRoot\*\*.psm1") -$moduleName = Split-Path $moduleRoot -Leaf - - -Describe "Help tests for $moduleName" -Tags Build { - - Import-Module (Join-Path $moduleRoot "$moduleName.psm1") -force - - $functions = Get-Command -Module $moduleName - $help = $functions | %{Get-Help $_.name} - foreach($node in $help) - { - Context $node.name { - - it "has a description" { - $node.description | Should Not BeNullOrEmpty - } - it "has an example" { - $node.examples | Should Not BeNullOrEmpty - } - foreach($parameter in $node.parameters.parameter) - { - it "parameter $($parameter.name) has a description" { - $parameter.Description.text | Should Not BeNullOrEmpty - } - } - } - } -} diff --git a/Tests/Project.Tests.ps1 b/Tests/Project.Tests.ps1 deleted file mode 100644 index 0cd47cb..0000000 --- a/Tests/Project.Tests.ps1 +++ /dev/null @@ -1,51 +0,0 @@ -$projectRoot = Resolve-Path "$PSScriptRoot\.." -$moduleRoot = Split-Path (Resolve-Path "$projectRoot\*\*.psd1") -$moduleName = Split-Path $moduleRoot -Leaf - -Describe "General project validation: $moduleName" -Tags Build { - - Context "Valid Powershell" { - $scripts = Get-ChildItem $projectRoot -Include *.ps1,*.psm1,*.psd1 -Recurse | where fullname -notmatch 'classes' - # TestCases are splatted to the script so we need hashtables - $testCase = $scripts | Foreach-Object{@{file=$_}} - - It "Script should be valid powershell" -TestCases $testCase { - param($file) - - $file.fullname | Should Exist - - $contents = Get-Content -Path $file.fullname -ErrorAction Stop - $errors = $null - $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) - $errors.Count | Should Be 0 - } - - It "Classes are valid" { - $classes = Get-ChildItem $projectRoot -Include *.ps1,*.psm1,*.psd1 -Recurse | where fullname -match 'classes' - - # Must be imported togehter incase they depend on each other - $contents = Get-Content -Path $classes.FullName | Out-String - - $errors = $null - $null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) - $errors.Count | Should Be 0 - } - } - - Context "ScriptAnalyzer" { - - $scripts = Get-ChildItem $moduleRoot -Include *.ps1,*.psm1,*.psd1 -Recurse | where fullname -notmatch 'classes' - $testCase = $scripts | Foreach-Object{@{file=$_}} - - it "Script should pass ScriptAnalyzer rules" -TestCases $testCase { - param($file) - - $file.fullname | Should Exist - Invoke-ScriptAnalyzer $file| Should BeNullOrEmpty - } - } - - It "Module '$moduleName' can import cleanly" { - {Import-Module (Join-Path $moduleRoot "$moduleName.psm1") -force } | Should Not Throw - } -} diff --git a/Tests/Unit.Tests.ps1 b/Tests/Unit.Tests.ps1 deleted file mode 100644 index 71f832d..0000000 --- a/Tests/Unit.Tests.ps1 +++ /dev/null @@ -1,83 +0,0 @@ -$projectRoot = Resolve-Path "$PSScriptRoot\.." -$moduleRoot = Split-Path (Resolve-Path "$projectRoot\*\*.psd1") -$moduleName = Split-Path $moduleRoot -Leaf - -Describe "Basic unit tests" -Tags Build { - - Import-Module (Join-Path $moduleRoot "$moduleName.psm1") -force - - Context "Function: Get-Chronometer" { - it "Does not throw" { - # Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"} - {Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {"Test"} } | Should Not Throw - } - - it "Executes a script and gives results" { - # Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"} - $results = Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {. "$PSScriptRoot\..\ScratchFiles\example.ps1"} - $results | Should Not BeNullOrEmpty - } - - it "Executes a script with linenumbers and gives results" { - # Get-Chronometer -Path ScratchFiles\example.ps1 -Script {"Test"} - $params = @{ - Path = "$PSScriptRoot\..\ScratchFiles\example.ps1" - Script = {. "$PSScriptRoot\..\ScratchFiles\example.ps1"} - LineNumber = 2,3,5,6 - } - $results = Get-Chronometer @params - $results | Should Not BeNullOrEmpty - } - } - - Context "Function: Format-Chronometer" { - - it "Does not throw" { - {$null | Format-Chronometer } | Should Not Throw - } - - it "Can process a result object without throwing" { - $results = Get-Chronometer -Path $PSScriptRoot\..\ScratchFiles\example.ps1 -Script {. "$PSScriptRoot\..\ScratchFiles\example.ps1"} - $results | Format-Chronometer *>&1 | Should Not BeNullOrEmpty - } - } - - InModuleScope $moduleName { - Context "Class: ScriptLine" { - - it "Creates an Object" { - {[ScriptLine]::New()} | Should Not Throw - } - it "ToString()" { - {[ScriptLine]::New().toString()} | Should Not Throw - } - it "Creates an Object" { - {[ScriptLine]::New().AddExecutionTime(1)} | Should Not Throw - } - } - - Context "Class: ScriptProfiler" { - - it "Creates an Object" { - {[ScriptProfiler]::New()} | Should Not Throw - } - it "Start()" { - {[ScriptProfiler]::Start()} | Should Not Throw - } - } - - Context "Class: MonitoredScript" { - it "Creates an object" { - {[MonitoredScript]::New()} | Should Not Throw - } - - it "SetScript()" { - pushd $projectRoot - $monitor = [MonitoredScript]::New() - {$monitor.SetScript(".\scratchfiles\example.ps1")} | Should Not Throw - popd - } - } - - } -} \ No newline at end of file