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