<commit_before>package main

import (
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"testing"
)

const name = "rsrc.syso"

func TestIconBuildSucceeds(t *testing.T) {
	dir, err := os.Getwd()
	if err != nil {
		t.Fatal(err)
	}
	dir = filepath.Join(dir, "testdata")

	// Compile icon in testdata/ dir
	os.Stdout.Write([]byte("-- compiling icon...\n"))
	defer os.Remove(filepath.Join(dir, name))
	cmd := exec.Command("go", "run", "../rsrc.go", "-ico", "akavel.ico", "-arch", "amd64", "-o", name)
	cmd.Dir = dir
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err = cmd.Run()
	if err != nil {
		t.Fatal(err)
	}

	defer os.Setenv("GOOS", os.Getenv("GOOS"))
	defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
	os.Setenv("GOOS", "windows")
	os.Setenv("GOARCH", "amd64")

	// Compile sample app in testdata/ dir, trying to link the icon
	// compiled above
	os.Stdout.Write([]byte("-- compiling app...\n"))
	cmd = exec.Command("go", "build")
	cmd.Dir = dir
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err = cmd.Run()
	if err != nil {
		t.Fatal(err)
	}

	// If on Windows, check that the compiled app can exec
	if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
		os.Stdout.Write([]byte("-- running app...\n"))
		cmd = &exec.Cmd{
			Path: "testdata.exe",
			Dir:  dir,
		}
		out, err := cmd.CombinedOutput()
		if err != nil {
			os.Stderr.Write(out)
			os.Stderr.Write([]byte("\n"))
			t.Fatal(err)
		}
		if string(out) != "hello world\n" {
			t.Fatalf("got unexpected output:\n%s", string(out))
		}
	}

	// TODO: test that we can extract icon from compiled app, and that it
	// is our icon
}

func TestManifestBuildSucceeds(t *testing.T) {
	dir, err := os.Getwd()
	if err != nil {
		t.Fatal(err)
	}
	dir = filepath.Join(dir, "testdata")

	// Compile icon in testdata/ dir
	os.Stdout.Write([]byte("-- compiling manifest...\n"))
	defer os.Remove(filepath.Join(dir, name))
	cmd := exec.Command("go", "run", "../rsrc.go", "-manifest", "manifest.xml", "-arch", "amd64", "-o", name)
	cmd.Dir = dir
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err = cmd.Run()
	if err != nil {
		t.Fatal(err)
	}

	defer os.Setenv("GOOS", os.Getenv("GOOS"))
	defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
	os.Setenv("GOOS", "windows")
	os.Setenv("GOARCH", "amd64")

	// Compile sample app in testdata/ dir, trying to link the icon
	// compiled above
	os.Stdout.Write([]byte("-- compiling app...\n"))
	cmd = exec.Command("go", "build")
	cmd.Dir = dir
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err = cmd.Run()
	if err != nil {
		t.Fatal(err)
	}

	// If on Windows, check that the compiled app can exec
	if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
		os.Stdout.Write([]byte("-- running app...\n"))
		cmd = &exec.Cmd{
			Path: "testdata.exe",
			Dir:  dir,
		}
		out, err := cmd.CombinedOutput()
		if err != nil {
			os.Stderr.Write(out)
			os.Stderr.Write([]byte("\n"))
			t.Fatal(err)
		}
		if string(out) != "hello world\n" {
			t.Fatalf("got unexpected output:\n%s", string(out))
		}
	}

	// TODO: test that we can extract manifest from compiled app, and that it
	// is our manifest
}
<commit_msg>test: table-driven, also icon+manifest together<commit_after>package main

import (
	"os"
	"os/exec"
	"path/filepath"
	"runtime"
	"testing"
)

const name = "rsrc.syso"

func TestBuildSucceeds(t *testing.T) {
	tests := []struct {
		comment string
		args    []string
	}{{
		comment: "icon",
		args:    []string{"-ico", "akavel.ico"},
	}, {
		comment: "manifest",
		args:    []string{"-manifest", "manifest.xml"},
	}, {
		comment: "manifest & icon",
		args:    []string{"-manifest", "manifest.xml", "-ico", "akavel.ico"},
	}}
	for _, tt := range tests {
		t.Run(tt.comment, func(t *testing.T) {
			dir, err := os.Getwd()
			if err != nil {
				t.Fatal(err)
			}
			dir = filepath.Join(dir, "testdata")

			// Compile icon/manifest in testdata/ dir
			os.Stdout.Write([]byte("-- compiling resource(s)...\n"))
			defer os.Remove(filepath.Join(dir, name))
			cmd := exec.Command("go", "run", "../rsrc.go", "-arch", "amd64", "-o", name)
			cmd.Args = append(cmd.Args, tt.args...)
			cmd.Dir = dir
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			err = cmd.Run()
			if err != nil {
				t.Fatal(err)
			}

			defer os.Setenv("GOOS", os.Getenv("GOOS"))
			defer os.Setenv("GOARCH", os.Getenv("GOARCH"))
			os.Setenv("GOOS", "windows")
			os.Setenv("GOARCH", "amd64")

			// Compile sample app in testdata/ dir, trying to link the icon
			// compiled above
			os.Stdout.Write([]byte("-- compiling app...\n"))
			cmd = exec.Command("go", "build")
			cmd.Dir = dir
			cmd.Stdout = os.Stdout
			cmd.Stderr = os.Stderr
			err = cmd.Run()
			if err != nil {
				t.Fatal(err)
			}

			// If on Windows, check that the compiled app can exec
			if runtime.GOOS == "windows" && runtime.GOARCH == "amd64" {
				os.Stdout.Write([]byte("-- running app...\n"))
				cmd = &exec.Cmd{
					Path: "testdata.exe",
					Dir:  dir,
				}
				out, err := cmd.CombinedOutput()
				if err != nil {
					os.Stderr.Write(out)
					os.Stderr.Write([]byte("\n"))
					t.Fatal(err)
				}
				if string(out) != "hello world\n" {
					t.Fatalf("got unexpected output:\n%s", string(out))
				}
			}

			// TODO: test that we can extract icon/manifest from compiled app,
			// and that it is our icon/manifest
		})
	}
}

{'fraction_non_alphanumeric': 0.19530658591975775, 'fraction_numerical': 0.0034065102195306586, 'mean_word_length': 2.9826676714393368, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 3}, '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': '563083', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2018, 'n_words': 490}