From bfacd7eadc2e8c98b68ef476bd1f9e6747511490 Mon Sep 17 00:00:00 2001 From: Adam Bertram Date: Sun, 12 Feb 2017 14:04:58 -0600 Subject: [PATCH] Updates to community script --- Tests/Community.Tests.ps1 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Tests/Community.Tests.ps1 b/Tests/Community.Tests.ps1 index 58368e1..e9aa3fd 100644 --- a/Tests/Community.Tests.ps1 +++ b/Tests/Community.Tests.ps1 @@ -44,10 +44,15 @@ $defaultModules = (Get-Module -Name 'Microsoft.PowerShell.*','Pester').Name if ($scripts = Get-ChildItem -Path $FolderPath -Recurse -Filter '*.ps*' | Sort-Object Name) { $scripts | foreach({ $script = $_.FullName - $ast = [System.Management.Automation.Language.Parser]::ParseFile($script,[ref]$null,[ref]$null) $commandRefs = $ast.FindAll({$args[0] -is [System.Management.Automation.Language.CommandAst]},$true) - $script:commandRefNames += @($commandRefs).foreach({ [string]$_.CommandElements[0] }) | Select-Object -Unique + if ($testRefs = (Select-String -path $script -Pattern "mock [`"|'](.*)[`"|']").Matches) { + $commandRefsInTest = $testRefs | foreach { + $_.Groups[1].Value + } + } + + $script:commandRefNames += (@($commandRefs).foreach({ [string]$_.CommandElements[0] }) | Select-Object -Unique) + $commandRefsInTest $script:commandDeclarationNames += $ast.FindAll({ $args[0] -is [System.Management.Automation.Language.FunctionDefinitionAst] }, $true) | Select-Object -ExpandProperty Name describe "[$($script)] Test" { @@ -71,7 +76,8 @@ if ($scripts = Get-ChildItem -Path $FolderPath -Recurse -Filter '*.ps*' | Sort-O } } ) - $privateCommandNames = $commandRefNames | Select-Object -Property $properties | Where { + + $privateCommandNames = $script:commandRefNames | Select-Object -Property $properties | Where { $_.Command -notin $defaultCommandNames -and $_.Command -notin $commandDeclarationNames -and $_.Command -match '^\w' -and