forked from go-python/gopy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_unix_test.go
78 lines (69 loc) · 1.65 KB
/
main_unix_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright 2015 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build !windows
// +build !windows
package main
import (
"fmt"
"log"
"os"
"os/exec"
"strings"
)
func init() {
// ld needs to look into the current directory to load the _go.so library
os.Setenv("LD_LIBRARY_PATH", fmt.Sprintf("%s:.", os.Getenv("LD_LIBRARY_PATH")))
testEnvironment = os.Environ()
var (
py2 = "python2"
py3 = "python3"
// pypy2 = "pypy"
// pypy3 = "pypy3"
)
if os.Getenv("GOPY_TRAVIS_CI") == "1" {
log.Printf("Running in travis CI")
}
var (
disabled []string
missing int
)
for _, be := range []struct {
name string
vm string
module string
mandatory bool
}{
{"py3", py3, "", true},
{"py2", py2, "", true},
} {
args := []string{"-c", ""}
if be.module != "" {
args[1] = "import " + be.module
}
log.Printf("checking testbackend: %q...", be.name)
cmd := exec.Command(be.vm, args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
if err != nil {
log.Printf("disabling testbackend: %q, error: '%s'", be.name, err.Error())
testBackends[be.name] = ""
disabled = append(disabled, be.name)
if be.mandatory {
missing++
}
} else {
log.Printf("enabling testbackend: %q", be.name)
testBackends[be.name] = be.vm
}
}
if len(disabled) > 0 {
log.Printf("The following test backends are not available: %s",
strings.Join(disabled, ", "))
if os.Getenv("GOPY_TRAVIS_CI") == "1" && missing > 0 {
log.Fatalf("Not all backends available in travis CI")
}
}
}