update appveyor.yml to check for bad test tags

add the function to check tags to build.psm1
rename the parser tests so they actually execute
This commit is contained in:
James Truher 2016-07-26 17:41:03 -07:00
parent 05d9fa07a9
commit 5e61213be9
3 changed files with 53 additions and 0 deletions

View file

@ -22,6 +22,12 @@ install:
build_script:
- ps: |
$ErrorActionPreference = 'Stop'
# check to be sure our test tags are correct
$result = Get-PesterTag
if ( $result.Result -ne "Pass" ) {
$result.Warnings
throw "Tags must be CI, Feature, Scenario, or Slow"
}
Start-PSBuild -Publish
Start-PSBuild -FullCLR

View file

@ -465,6 +465,53 @@ function Get-PSOutput {
}
function Get-PesterTag {
param ( [Parameter(Position=0)][string]$testbase = "$PSScriptRoot/test/powershell" )
$alltags = @{}
$warnings = @()
get-childitem -Recurse $testbase -File |?{$_.name -match "tests.ps1"}| %{
$fullname = $_.fullname
$tok = $err = $null
$ast = [System.Management.Automation.Language.Parser]::ParseFile($FullName, [ref]$tok,[ref]$err)
$des = $ast.FindAll({$args[0] -is "System.Management.Automation.Language.CommandAst" -and $args[0].CommandElements[0].Value -eq "Describe"},$true)
foreach( $describe in $des) {
$elements = $describe.CommandElements
$lineno = $elements[0].Extent.StartLineNumber
$foundTag = $false
for ( $i = 0; $i -lt $elements.Count; $i++) {
if ( $elements[$i].extent.text -match "^-t" ) {
$vAst = $elements[$i+1]
if ( $vAst.FindAll({$args[0] -is "System.Management.Automation.Language.VariableExpressionAst"},$true) ) {
$warnings += "TAGS must be static strings, error in ${fullname}, line $lineno"
}
$values = $vAst.FindAll({$args[0] -is "System.Management.Automation.Language.StringConstantExpressionAst"},$true).Value
$values | %{
if ( $_ -notmatch "CI|FEATURE|SCENARIO|SLOW" ) {
$warnings += "${fullname} includes improper tag '$_', line '$lineno'"
}
$alltags[$_]++
}
$foundTag = $true
}
}
if ( ! $foundTag ) {
$warnings += "${fullname} does not include -Tag in Describe, line '$lineno'"
}
}
}
if ( $Warnings.Count -gt 0 ) {
$alltags['Result'] = "Fail"
}
else {
$alltags['Result'] = "Pass"
}
$alltags['Warnings'] = $warnings
$o = [pscustomobject]$alltags
$o.psobject.TypeNames.Add("DescribeTagsInUse")
$o
}
function Start-PSPester {
[CmdletBinding()]param(
[string]$OutputFormat = "NUnitXml",