1// Copyright 2018 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// This file contains testing utilities copied from $GOROOT/src/internal/testenv/testenv.go.
6
7package gccgoimporter
8
9import (
10	"runtime"
11	"strings"
12	"testing"
13)
14
15// HasGoBuild reports whether the current system can build programs with ``go build''
16// and then run them with os.StartProcess or exec.Command.
17func HasGoBuild() bool {
18	switch runtime.GOOS {
19	case "android", "nacl":
20		return false
21	case "darwin":
22		if strings.HasPrefix(runtime.GOARCH, "arm") {
23			return false
24		}
25	}
26	return true
27}
28
29// MustHaveGoBuild checks that the current system can build programs with ``go build''
30// and then run them with os.StartProcess or exec.Command.
31// If not, MustHaveGoBuild calls t.Skip with an explanation.
32func MustHaveGoBuild(t *testing.T) {
33	if !HasGoBuild() {
34		t.Skipf("skipping test: 'go build' not available on %s/%s", runtime.GOOS, runtime.GOARCH)
35	}
36}
37
38var testenv = struct {
39	HasGoBuild      func() bool
40	MustHaveGoBuild func(*testing.T)
41}{
42	HasGoBuild:      HasGoBuild,
43	MustHaveGoBuild: MustHaveGoBuild,
44}
45