<commit_before>package integration

import (
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"testing"
	"time"
)

func TestIsKilledFalseWithNonKilledProcess(t *testing.T) {
	// TODO Windows: Port this test
	if runtime.GOOS == "windows" {
		t.Skip("Needs porting to Windows")
	}

	lsCmd := exec.Command("ls")
	lsCmd.Start()
	// Wait for it to finish
	err := lsCmd.Wait()
	if IsKilled(err) {
		t.Fatalf("Expected the ls command to not be killed, was.")
	}
}

func TestIsKilledTrueWithKilledProcess(t *testing.T) {
	// TODO Windows: Using golang 1.5.3, this seems to hit
	// a bug in go where Process.Kill() causes a panic.
	// Needs further investigation @jhowardmsft
	if runtime.GOOS == "windows" {
		t.SkipNow()
	}
	longCmd := exec.Command("top")
	// Start a command
	longCmd.Start()
	// Capture the error when *dying*
	done := make(chan error, 1)
	go func() {
		done <- longCmd.Wait()
	}()
	// Then kill it
	longCmd.Process.Kill()
	// Get the error
	err := <-done
	if !IsKilled(err) {
		t.Fatalf("Expected the command to be killed, was not.")
	}
}

func TestRunCommandWithOutput(t *testing.T) {
	var (
		echoHelloWorldCmd *exec.Cmd
		expected          string
	)
	if runtime.GOOS != "windows" {
		echoHelloWorldCmd = exec.Command("echo", "hello", "world")
		expected = "hello world\n"
	} else {
		echoHelloWorldCmd = exec.Command("cmd", "/s", "/c", "echo", "hello", "world")
		expected = "hello world\r\n"
	}

	out, exitCode, err := RunCommandWithOutput(echoHelloWorldCmd)
	if out != expected || exitCode != 0 || err != nil {
		t.Fatalf("Expected command to output %s, got %s, %v with exitCode %v", expected, out, err, exitCode)<commit_msg>pkg/integration: Port tests to Windows<commit_after>package integration

import (
	"io"
	"io/ioutil"
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"strconv"
	"strings"
	"testing"
	"time"
)

func TestIsKilledFalseWithNonKilledProcess(t *testing.T) {
	var lsCmd *exec.Cmd
	if runtime.GOOS != "windows" {
		lsCmd = exec.Command("ls")
	} else {
		lsCmd = exec.Command("cmd", "/c", "dir")
	}

	err := lsCmd.Run()
	if IsKilled(err) {
		t.Fatalf("Expected the ls command to not be killed, was.")
	}
}

func TestIsKilledTrueWithKilledProcess(t *testing.T) {
	var longCmd *exec.Cmd
	if runtime.GOOS != "windows" {
		longCmd = exec.Command("top")
	} else {
		longCmd = exec.Command("powershell", "while ($true) { sleep 1 }")
	}

	// Start a command
	err := longCmd.Start()
	if err != nil {
		t.Fatal(err)
	}
	// Capture the error when *dying*
	done := make(chan error, 1)
	go func() {
		done <- longCmd.Wait()
	}()
	// Then kill it
	longCmd.Process.Kill()
	// Get the error
	err = <-done
	if !IsKilled(err) {
		t.Fatalf("Expected the command to be killed, was not.")
	}
}

func TestRunCommandWithOutput(t *testing.T) {
	var (
		echoHelloWorldCmd *exec.Cmd
		expected          string
	)
	if runtime.GOOS != "windows" {
		echoHelloWorldCmd = exec.Command("echo", "hello", "world")
		expected = "hello world\n"
	} else {
		echoHelloWorldCmd = exec.Command("cmd", "/s", "/c", "echo", "hello", "world")
		expected = "hello world\r\n"
	}

	out, exitCode, err := RunCommandWithOutput(echoHelloWorldCmd)
	if out != expected || exitCode != 0 || err != nil {
		t.Fatalf("Expected command to output %s, got %s, %v with exitCode %v", expected, out, err, exitCode)
{'fraction_non_alphanumeric': 0.15903614457831325, 'fraction_numerical': 0.0024096385542168677, 'mean_word_length': 3.6512605042016806, 'pattern_counts': {'":': 0, '<': 7, '<?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': '5423576', 'n_tokens_mistral': 1280, 'n_tokens_neox': 1231, 'n_words': 330}