Esempio n. 1
0
func setupZone() {
	// consult $TZ to find the time zone to use.
	// no $TZ means use the system default /etc/localtime.
	// $TZ="" means use UTC.
	// $TZ="foo" means use /usr/share/zoneinfo/foo.
	// Many systems use /usr/share/zoneinfo, Solaris 2 has
	// /usr/share/lib/zoneinfo, IRIX 6 has /usr/lib/locale/TZ.
	zoneDirs := []string{"/usr/share/zoneinfo/",
		"/usr/share/lib/zoneinfo/",
		"/usr/lib/locale/TZ/"}

	tz, err := os.Getenverror("TZ")
	switch {
	case err == os.ENOENV:
		zones, _ = readinfofile("/etc/localtime")
	case len(tz) > 0:
		for _, zoneDir := range zoneDirs {
			var ok bool
			if zones, ok = readinfofile(zoneDir + tz); ok {
				break
			}
		}
	case len(tz) == 0:
		// do nothing: use UTC
	}
}
Esempio n. 2
0
func init() {
	var getenvErr os.Error
	EXTJSROOT, getenvErr = os.Getenverror("EXTJSROOT")
	if getenvErr != nil {
		panic(getenvErr)
	}
}
Esempio n. 3
0
func (mdb *mysqlDB) RunTest(t *testing.T, fn func(params)) {
	if !mdb.Running() {
		t.Logf("skipping test; no MySQL running on localhost:3306")
		return
	}
	user := os.Getenv("GOSQLTEST_MYSQL_USER")
	if user == "" {
		user = "******"
	}
	pass, err := os.Getenverror("GOSQLTEST_MYSQL_PASS")
	if err != nil {
		pass = "******"
	}
	dbName := "gosqltest"
	db, err := sql.Open("mymysql", fmt.Sprintf("%s/%s/%s", dbName, user, pass))
	if err != nil {
		t.Fatalf("error connecting: %v", err)
	}

	params := params{mysql, t, db}

	// Drop all tables in the test database.
	rows, err := db.Query("SHOW TABLES")
	if err != nil {
		t.Fatalf("failed to enumerate tables: %v", err)
	}
	for rows.Next() {
		var table string
		if rows.Scan(&table) == nil {
			params.mustExec("DROP TABLE " + table)
		}
	}

	fn(params)
}
Esempio n. 4
0
File: env.go Progetto: 8l/go-learn
func main() {
	ga, e0 := os.Getenverror("GOARCH")
	if e0 != nil {
		print("$GOARCH: ", e0.String(), "\n")
		os.Exit(1)
	}
	if ga != "amd64" && ga != "386" && ga != "arm" {
		print("$GOARCH=", ga, "\n")
		os.Exit(1)
	}
	xxx, e1 := os.Getenverror("DOES_NOT_EXIST")
	if e1 != os.ENOENV {
		print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.String(), "\n")
		os.Exit(1)
	}
}
Esempio n. 5
0
func main() {
	ga, e0 := os.Getenverror("GOARCH")
	if e0 != nil {
		print("$GOARCH: ", e0.Error(), "\n")
		os.Exit(1)
	}
	if ga != runtime.GOARCH {
		print("$GOARCH=", ga, "!= runtime.GOARCH=", runtime.GOARCH, "\n")
		os.Exit(1)
	}
	xxx, e1 := os.Getenverror("DOES_NOT_EXIST")
	if e1 != os.ENOENV {
		print("$DOES_NOT_EXIST=", xxx, "; err = ", e1.Error(), "\n")
		os.Exit(1)
	}
}
Esempio n. 6
0
//  The $GOROOT environment variable.
func GetGoroot() string {
	goroot, err := os.Getenverror("GOROOT")
	if err != nil {
		panic("goroot")
	}
	return goroot
}
Esempio n. 7
0
func setupZone() {
	t, err := os.Getenverror("timezone")
	if err != nil {
		// do nothing: use UTC
		return
	}
	zones = parseZones(t)
}
Esempio n. 8
0
func chdir(args []string) error {
	if len(args) > 0 {
		return os.Chdir(args[0])
	}

	home, err := os.Getenverror("HOME")
	if err != nil {
		return fmt.Errorf("HOME not set")
	}

	return os.Chdir(home)
}
Esempio n. 9
0
func setupZone() {
	// consult $TZ to find the time zone to use.
	// no $TZ means use the system default /etc/localtime.
	// $TZ="" means use UTC.
	// $TZ="foo" means use /usr/share/zoneinfo/foo.

	tz, err := os.Getenverror("TZ")
	switch {
	case err == os.ENOENV:
		zones, _ = readinfofile("/etc/localtime")
	case len(tz) > 0:
		zones, _ = readinfofile(zoneDir + tz)
	case len(tz) == 0:
		// do nothing: use UTC
	}
}
Esempio n. 10
0
// envv returns an environment for build/bench execution
func (b *Builder) envv() []string {
	if runtime.GOOS == "windows" {
		return b.envvWindows()
	}
	e := []string{
		"GOOS=" + b.goos,
		"GOARCH=" + b.goarch,
		"GOROOT_FINAL=/usr/local/go",
	}
	for _, k := range extraEnv {
		s, err := os.Getenverror(k)
		if err == nil {
			e = append(e, k+"="+s)
		}
	}
	return e
}
Esempio n. 11
0
func TestJsb2(t *testing.T) {
	t.Log("Testing the Jsb2 parser")
	extjsRoot, getenvErr := os.Getenverror("EXTJSROOT")
	if getenvErr != nil {
		panic(getenvErr)
	}
	contents, readErr := ioutil.ReadFile(extjsRoot + "/ext.jsb2")
	if readErr != nil {
		panic(readErr)
	}
	p := NewParser(contents)
	deps, err := p.ExtAllPkgDeps()
	if err != nil {
		t.Fatal(err)
	}
	t.Log(deps)
	expectedLen := 25
	if deps.Len() != expectedLen {
		t.Errorf("Unexpected deps length %v instead of %v", deps.Len(), expectedLen)
	}
}
Esempio n. 12
0
// windows version of envv
func (b *Builder) envvWindows() []string {
	start := map[string]string{
		"GOOS":         b.goos,
		"GOARCH":       b.goarch,
		"GOROOT_FINAL": "/c/go",
		// TODO(brainman): remove once we find make that does not hang.
		"MAKEFLAGS": "-j1",
	}
	for _, name := range extraEnv {
		s, err := os.Getenverror(name)
		if err == nil {
			start[name] = s
		}
	}
	skip := map[string]bool{
		"GOBIN":   true,
		"GOROOT":  true,
		"INCLUDE": true,
		"LIB":     true,
	}
	var e []string
	for name, v := range start {
		e = append(e, name+"="+v)
		skip[name] = true
	}
	for _, kv := range os.Environ() {
		s := strings.SplitN(kv, "=", 2)
		name := strings.ToUpper(s[0])
		switch {
		case name == "":
			// variables, like "=C:=C:\", just copy them
			e = append(e, kv)
		case !skip[name]:
			e = append(e, kv)
			skip[name] = true
		}
	}
	return e
}