<commit_before>﻿$here = Split-Path -Parent $MyInvocation.MyCommand.Path
. $here/Test-Common.ps1

Describe "Start-Process" {
    $pingCommand = (Get-Command -CommandType Application ping)[0].Definition
    $pingDirectory = Split-Path $pingCommand -Parent
    $tempFile = "$(GetTempDir)/PSTest"
    $assetsFile = $here + "/assets/SortTest.txt"
    $windows = IsWindows
    if ($windows)
    {
        $pingParamNoStop = "localhost -t"
        $pingParamStop = "localhost -n 2"
    }
    else
    {
        $pingParamNoStop = "localhost"
        $pingParamStop = "localhost -c 2"
    }

    It "Should process arguments without error" {
        $process = Start-Process ping -ArgumentList $pingParamNoStop -PassThru

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"

        Stop-Process -Id $process.Id
    }

    It "Should work correctly when used with full path name" {
        $process = Start-Process $pingCommand -ArgumentList $pingParamNoStop -PassThru

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"

        Stop-Process -Id $process.Id
    }

    It "Should invoke correct path when used with FilePath argument" {
        $process = Start-Process -FilePath $pingCommand -ArgumentList $pingParamNoStop -PassThru

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"

        Stop-Process -Id $process.Id
    }

    It "Should wait for command completion if used with Wait argument" {
        $process = Start-Process ping -ArgumentList $pingParamStop -Wait -PassThru
        ( Get-Process -Id $process.Id -ErrorAction SilentlyContinue ) | Should BeNullOrEmpty
    }

    It "Should work correctly with WorkingDirectory argument" {
        $process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParamNoStop -PassThru

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"

        Stop-Process -Id $process.Id
    }

    It "Should should handle stderr redirection without error" {
        $process = Start-Process ping -ArgumentList $pingParamStop -PassThru -RedirectStandardError $tempFile

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"
    }

    It "Should should handle stdout redirection without error" {
        $process = Start-Process ping -ArgumentList $pingParamStop -Wait -RedirectStandardOutput $tempFile
        $dirEntry = dir $tempFile
	$dirEntry.Length | Should BeGreaterThan 0<commit_msg>Don't launch any infinite processes<commit_after>﻿$here = Split-Path -Parent $MyInvocation.MyCommand.Path
. $here/Test-Common.ps1

Describe "Start-Process" {
    $pingCommand = (Get-Command -CommandType Application ping)[0].Definition
    $pingDirectory = Split-Path $pingCommand -Parent
    $tempFile = "$(GetTempDir)/PSTest"
    $assetsFile = $here + "/assets/SortTest.txt"
    $windows = IsWindows
    if ($windows)
    {
        $pingParam = "localhost -n 4"
    }
    else
    {
        $pingParam = "localhost -c 4"
    }

    It "Should process arguments without error" {
        $process = Start-Process ping -ArgumentList $pingParam -PassThru

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"
    }

    It "Should work correctly when used with full path name" {
        $process = Start-Process $pingCommand -ArgumentList $pingParam -PassThru

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"
    }

    It "Should invoke correct path when used with FilePath argument" {
        $process = Start-Process -FilePath $pingCommand -ArgumentList $pingParam -PassThru

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"
    }

    It "Should wait for command completion if used with Wait argument" {
        $process = Start-Process ping -ArgumentList $pingParam -Wait -PassThru
    }

    It "Should work correctly with WorkingDirectory argument" {
        $process = Start-Process ping -WorkingDirectory $pingDirectory -ArgumentList $pingParam -PassThru

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"
    }

    It "Should should handle stderr redirection without error" {
        $process = Start-Process ping -ArgumentList $pingParam -PassThru -RedirectStandardError $tempFile

        $process.Length      | Should Be 1
        $process.Id          | Should BeGreaterThan 1
        $process.ProcessName | Should Be "ping"
    }

    It "Should should handle stdout redirection without error" {
        $process = Start-Process ping -ArgumentList $pingParam -Wait -RedirectStandardOutput $tempFile
        $dirEntry = dir $tempFile
	$dirEntry.Length | Should BeGreaterThan 0
{'fraction_non_alphanumeric': 0.08595229079893979, 'fraction_numerical': 0.005679666792881484, 'mean_word_length': 2.477946017116524, 'pattern_counts': {'":': 0, '<': 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': '1998273', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1423, 'n_words': 449}