<commit_before>﻿param (
	[ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'Fails', 'All')]
	[string]
	$Show = "None",
	
	[ValidateSet('Everything', 'Functions', 'General')]
	[string]
	$Run = "Everything",
	
	[string]
	$Filter = "*.Tests.ps1"
)

Write-Host "Starting Tests" -ForegroundColor Green

Write-Host "Importing Module" -ForegroundColor Cyan

Remove-Module PSModuleDevelopment -ErrorAction Ignore
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psd1"
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psm1" -Force

$totalFailed = 0
$totalRun = 0

$testresults = @()

if ($Run -match "Everything|General")
{
	Write-PSFMessage -Level Important -Message "Modules imported, proceeding with general tests"
	foreach ($file in (Get-ChildItem "$PSScriptRoot\general" -Filter $Filter))
	{
		Write-PSFMessage -Level Significant -Message "  Executing <c='em'>$($file.Name)</c>"
		$TestOuputFile = Join-Path "$PSScriptRoot\..\..\TestResults" "TEST-$($file.BaseName).xml"
		$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru -OutputFile $TestOuputFile -OutputFormat NUnitXml
		foreach ($result in $results)
		{
			$totalRun += $result.TotalCount
			$totalFailed += $result.FailedCount
			$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
				$name = $_.Name
				$testresults += [pscustomobject]@{
					Describe   = $_.Describe
					Context    = $_.Context
					Name	   = "It $name"
					Result	   = $_.Result
					Message    = $_.FailureMessage
				}
			}
		}
	}
}

if ($Run -match "Everything|Functions")
{
	Write-PSFMessage -Level Important -Message "Proceeding with individual tests"
	foreach ($file in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -File -Filter $Filter))
	{
		Write-PSFMessage -Level Significant -Message "  Executing $($file.Name)"
		$results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
		foreach ($result in $results)
		{
			$totalRun += $result.TotalCount
			$totalFailed += $result.FailedCount
			$result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
				$name = $_.Name
				$testresults += [pscustomobject]@{
					Describe    = $_.Describe
					Context	    = $_.Context
					Name	    = "It $name"
					Result	    = $_.Result
					Message	    = $_.FailureMessage
				}
			}
		}
	}
}

$testresults | Sort-Object Describe, Context, Name, Result, Message | Format-List

if ($totalFailed -eq 0) { Write-PSFMessage -Level Critical -Message "All <c='em'>$totalRun</c> tests executed without a single failure!" }
else { Write-PSFMessage -Level Critical -Message "<c='em'>$totalFailed tests</c> out of <c='sub'>$totalRun</c> tests failed!" }

if ($totalFailed -gt 0)
{
	throw "$totalFailed / $totalRun tests failed!"
}
<commit_msg>Added Output to NUnitXML and send them into TestResults folder<commit_after>﻿param (
    [ValidateSet('None', 'Default', 'Passed', 'Failed', 'Pending', 'Skipped', 'Inconclusive', 'Describe', 'Context', 'Summary', 'Header', 'Fails', 'All')]
    [string]
    $Show = "None",

    [ValidateSet('Everything', 'Functions', 'General')]
    [string]
    $Run = "Everything",

    [string]
    $Filter = "*.Tests.ps1"
)

Write-Host "Starting Tests" -ForegroundColor Green

Write-Host "Importing Module" -ForegroundColor Cyan

Remove-Module PSModuleDevelopment -ErrorAction Ignore
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psd1"
Import-Module "$PSScriptRoot\..\PSModuleDevelopment.psm1" -Force

$totalFailed = 0
$totalRun = 0

$testresults = @()

if ($Run -match "Everything|General") {
    Write-PSFMessage -Level Important -Message "Modules imported, proceeding with general tests"
    foreach ($file in (Get-ChildItem "$PSScriptRoot\general" -Filter $Filter)) {
        Write-PSFMessage -Level Significant -Message "  Executing <c='em'>$($file.Name)</c>"
        $TestOuputFile = Join-Path "$PSScriptRoot\..\..\TestResults" "TEST-$($file.BaseName).xml"
        $results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru -OutputFile $TestOuputFile -OutputFormat NUnitXml
        foreach ($result in $results) {
            $totalRun += $result.TotalCount
            $totalFailed += $result.FailedCount
            $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
                $name = $_.Name
                $testresults += [pscustomobject]@{
                    Describe = $_.Describe
                    Context  = $_.Context
                    Name     = "It $name"
                    Result   = $_.Result
                    Message  = $_.FailureMessage
                }
            }
        }
    }
}

if ($Run -match "Everything|Functions") {
    Write-PSFMessage -Level Important -Message "Proceeding with individual tests"
    foreach ($file in (Get-ChildItem "$PSScriptRoot\functions" -Recurse -File -Filter $Filter)) {
        Write-PSFMessage -Level Significant -Message "  Executing $($file.Name)"
        $results = Invoke-Pester -Script $file.FullName -Show $Show -PassThru
        foreach ($result in $results) {
            $totalRun += $result.TotalCount
            $totalFailed += $result.FailedCount
            $result.TestResult | Where-Object { -not $_.Passed } | ForEach-Object {
                $name = $_.Name
                $testresults += [pscustomobject]@{
                    Describe = $_.Describe
                    Context  = $_.Context
                    Name     = "<NAME>"
                    Result   = $_.Result
                    Message  = $_.FailureMessage
                }
            }
        }
    }
}

$testresults | Sort-Object Describe, Context, Name, Result, Message | Format-List

if ($totalFailed -eq 0) { Write-PSFMessage -Level Critical -Message "All <c='em'>$totalRun</c> tests executed without a single failure!" }
else { Write-PSFMessage -Level Critical -Message "<c='em'>$totalFailed tests</c> out of <c='sub'>$totalRun</c> tests failed!" }

if ($totalFailed -gt 0) {
    throw "$totalFailed / $totalRun tests failed!"
}

{'fraction_non_alphanumeric': 0.14351928488660817, 'fraction_numerical': 0.002317497103128621, 'mean_word_length': 2.895551257253385, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '231068', 'n_tokens_mistral': 1993, 'n_tokens_neox': 1829, 'n_words': 462}