<commit_before>// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package shared_test

import (
	"bufio"
	"bytes"
	"debug/elf"
	"encoding/binary"
	"flag"
	"fmt"
	"go/build"
	"io"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"runtime"
	"sort"
	"strconv"
	"strings"
	"testing"
	"time"
)

var gopathInstallDir, gorootInstallDir string

// This is the smallest set of packages we can link into a shared
// library (runtime/cgo is built implicitly).
var minpkgs = []string{"runtime", "sync/atomic"}
var soname = "libruntime,sync-atomic.so"

var testX = flag.Bool("testx", false, "if true, pass -x to 'go' subcommands invoked by the test")
var testWork = flag.Bool("testwork", false, "if true, log and do not delete the temporary working directory")

// run runs a command and calls t.Errorf if it fails.
func run(t *testing.T, msg string, args ...string) {
	runWithEnv(t, msg, nil, args...)
}

// runWithEnv runs a command under the given environment and calls t.Errorf if it fails.
func runWithEnv(t *testing.T, msg string, env []string, args ...string) {
	c := exec.Command(args[0], args[1:]...)
	if len(env) != 0 {
		c.Env = append(os.Environ(), env...)
	}
	if output, err := c.CombinedOutput(); err != nil {
		t.Errorf("executing %s (%s) failed %s:\n%s", strings.Join(args, " "), msg, err, output)
	}
}

// goCmd invokes the go tool with the installsuffix set up by TestMain. It calls
// t.Fatalf if the command fails.
func goCmd(t *testing.T, args ...string) string {
	newargs := []string{args[0]}
	if *testX {
		newargs = append(newargs, "-x")
	}
	newargs = append(newargs, args[1:]...)
	c := exec.Command("go", newargs...)
	stderr := new(strings.Builder)
	c.Stderr = stderr

	if testing.Verbose() && t == nil {
		fmt.Fprintf(os.Stderr, "+ go %s\n", strings.Join(args, " "))<commit_msg>misc/cgo/testshared: pass -x flag only to commands supporting it<commit_after>// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package shared_test

import (
	"bufio"
	"bytes"
	"debug/elf"
	"encoding/binary"
	"flag"
	"fmt"
	"go/build"
	"io"
	"log"
	"os"
	"os/exec"
	"path/filepath"
	"regexp"
	"runtime"
	"sort"
	"strconv"
	"strings"
	"testing"
	"time"
)

var gopathInstallDir, gorootInstallDir string

// This is the smallest set of packages we can link into a shared
// library (runtime/cgo is built implicitly).
var minpkgs = []string{"runtime", "sync/atomic"}
var soname = "libruntime,sync-atomic.so"

var testX = flag.Bool("testx", false, "if true, pass -x to 'go' subcommands invoked by the test")
var testWork = flag.Bool("testwork", false, "if true, log and do not delete the temporary working directory")

// run runs a command and calls t.Errorf if it fails.
func run(t *testing.T, msg string, args ...string) {
	runWithEnv(t, msg, nil, args...)
}

// runWithEnv runs a command under the given environment and calls t.Errorf if it fails.
func runWithEnv(t *testing.T, msg string, env []string, args ...string) {
	c := exec.Command(args[0], args[1:]...)
	if len(env) != 0 {
		c.Env = append(os.Environ(), env...)
	}
	if output, err := c.CombinedOutput(); err != nil {
		t.Errorf("executing %s (%s) failed %s:\n%s", strings.Join(args, " "), msg, err, output)
	}
}

// goCmd invokes the go tool with the installsuffix set up by TestMain. It calls
// t.Fatalf if the command fails.
func goCmd(t *testing.T, args ...string) string {
	newargs := []string{args[0]}
	if *testX && args[0] != "env" {
		newargs = append(newargs, "-x")
	}
	newargs = append(newargs, args[1:]...)
	c := exec.Command("go", newargs...)
	stderr := new(strings.Builder)
	c.Stderr = stderr

	if testing.Verbose() && t == nil {
		fmt.Fprintf(os.Stderr, "+ go %s\n", strings.Join(args, " "))
{'fraction_non_alphanumeric': 0.15888573639411915, 'fraction_numerical': 0.004900696414753675, 'mean_word_length': 3.694915254237288, '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': '3849010', 'n_tokens_mistral': 1403, 'n_tokens_neox': 1371, 'n_words': 464}