<commit_before>﻿# Check if PSScriptAnalyzer is already loaded so we don't
# overwrite a test version of Invoke-ScriptAnalyzer by
# accident
if (!(Get-Module PSScriptAnalyzer) -and !$testingLibraryUsage)
{
	Import-Module PSScriptAnalyzer
}

$sa = Get-Command Invoke-ScriptAnalyzer
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
$singularNouns = "PSUseSingularNouns"
$rules = $singularNouns, "PSUseApprovedVerbs"
$avoidRules = "PSAvoid*"
$useRules = "PSUse*"

Describe "Test available parameters" {
    $params = $sa.Parameters
    Context "Path parameter" {
        It "has a Path parameter" {
            $params.ContainsKey("Path") | Should Be $true
        }
        
        It "accepts string" {
            $params["Path"].ParameterType.FullName | Should Be "System.String"
        }
    }

    Context "CustomizedRulePath parameters" {
        It "has a CustomizedRulePath parameter" {
            $params.ContainsKey("CustomizedRulePath") | Should Be $true
        }

        It "accepts string array" {
            $params["CustomizedRulePath"].ParameterType.FullName | Should Be "System.String[]"
        }
    }

    Context "IncludeRule parameters" {
        It "has an IncludeRule parameter" {
            $params.ContainsKey("IncludeRule") | Should Be $true
        }

        It "accepts string array" {
            $params["IncludeRule"].ParameterType.FullName | Should Be "System.String[]"
        }
    }

    Context "Severity parameters" {
        It "has a severity parameters" {
            $params.ContainsKey("Severity") | Should Be $true
        }

        It "accepts string array" {
            $params["Severity"].ParameterType.FullName | Should Be "System.String[]"
        }
    }
}

Describe "Test Path" {
    Context "When given a single file" {
        It "Has the same effect as without Path parameter" {
            $withPath = Invoke-ScriptAnalyzer $directory\TestScript.ps1
            $withoutPath = Invoke-ScriptAnalyzer -Path $directory\TestScript.ps1
            $withPath.Count -eq $withoutPath.Count | Should Be $true
        }

        It "Does not run rules on script with more than 10 parser errors" {
            $moreThanTenErrors = Invoke-ScriptAnalyzer -ErrorAction SilentlyContinue $directory\CSharp.ps1
            $moreThanTenErrors.Count | Should Be 0
        }
    }

    Context "When given a glob" {
    	It "Invokes on all the matching files" {
	   $numFilesResult = (Invoke-ScriptAnalyzer -Path $directory\R*.ps1 | Select-Object -Property ScriptName -Unique).Count
	   $numFilesExpected = Get-ChildItem -Path $directory\R*.ps1
	   #numFilesResult -eq $numFilesExpected | Should Be $true
	}
    }

    Context "When given a FileSystem PSDrive" {
    	It "Recognizes the path" {
	   $freeDrive = 69..90 | %{([char]$_)+":"} | ?{!(Test-Path $_)} | Select-Object -First 1
	   New-PSDrive -Name $freeDrive[0] -PSProvider FileSystem -Root $directory
	   $numFilesExpected = (Get-ChildItem -Path $freeDrive\*.ps1).Count
	   $numFilesResult = (Invoke-ScriptAnalyzer -Path $freeDrive\R*.ps1 | Select-Object -Property ScriptName -Unique).Count
	   #numFilesResult -eq $numFilesExpected | Should Be $true<commit_msg>minor fix: uncommented the test validation statement<commit_after>﻿# Check if PSScriptAnalyzer is already loaded so we don't
# overwrite a test version of Invoke-ScriptAnalyzer by
# accident
if (!(Get-Module PSScriptAnalyzer) -and !$testingLibraryUsage)
{
	Import-Module PSScriptAnalyzer
}

$sa = Get-Command Invoke-ScriptAnalyzer
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
$singularNouns = "PSUseSingularNouns"
$rules = $singularNouns, "PSUseApprovedVerbs"
$avoidRules = "PSAvoid*"
$useRules = "PSUse*"

Describe "Test available parameters" {
    $params = $sa.Parameters
    Context "Path parameter" {
        It "has a Path parameter" {
            $params.ContainsKey("Path") | Should Be $true
        }
        
        It "accepts string" {
            $params["Path"].ParameterType.FullName | Should Be "System.String"
        }
    }

    Context "CustomizedRulePath parameters" {
        It "has a CustomizedRulePath parameter" {
            $params.ContainsKey("CustomizedRulePath") | Should Be $true
        }

        It "accepts string array" {
            $params["CustomizedRulePath"].ParameterType.FullName | Should Be "System.String[]"
        }
    }

    Context "IncludeRule parameters" {
        It "has an IncludeRule parameter" {
            $params.ContainsKey("IncludeRule") | Should Be $true
        }

        It "accepts string array" {
            $params["IncludeRule"].ParameterType.FullName | Should Be "System.String[]"
        }
    }

    Context "Severity parameters" {
        It "has a severity parameters" {
            $params.ContainsKey("Severity") | Should Be $true
        }

        It "accepts string array" {
            $params["Severity"].ParameterType.FullName | Should Be "System.String[]"
        }
    }
}

Describe "Test Path" {
    Context "When given a single file" {
        It "Has the same effect as without Path parameter" {
            $withPath = Invoke-ScriptAnalyzer $directory\TestScript.ps1
            $withoutPath = Invoke-ScriptAnalyzer -Path $directory\TestScript.ps1
            $withPath.Count -eq $withoutPath.Count | Should Be $true
        }

        It "Does not run rules on script with more than 10 parser errors" {
            $moreThanTenErrors = Invoke-ScriptAnalyzer -ErrorAction SilentlyContinue $directory\CSharp.ps1
            $moreThanTenErrors.Count | Should Be 0
        }
    }

    Context "When given a glob" {
    	It "Invokes on all the matching files" {
	   $numFilesResult = (Invoke-ScriptAnalyzer -Path $directory\Rule*.ps1 | Select-Object -Property ScriptName -Unique).Count
	   $numFilesExpected = (Get-ChildItem -Path $directory\Rule*.ps1).Count
	   $numFilesResult | Should be $numFilesExpected
	}
    }

    Context "When given a FileSystem PSDrive" {
    	It "Recognizes the path" {
	   $freeDrive = 69..90 | %{([char]$_)+":"} | ?{!(Test-Path $_)} | Select-Object -First 1
	   New-PSDrive -Name $freeDrive[0] -PSProvider FileSystem -Root $directory
	   $numFilesExpected = (Get-ChildItem -Path $freeDrive\R*.ps1).Count
	   $numFilesResult = (Invoke-ScriptAnalyzer -Path $freeDrive\Rule*.ps1 | Select-Object -Property ScriptName -Unique).Count
	   $numFilesResult | Should Be $numFilesExpected
{'fraction_non_alphanumeric': 0.10799812177179527, 'fraction_numerical': 0.005008608545938331, 'mean_word_length': 2.794536817102138, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2128956', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1835, 'n_words': 503}