PR c++/85515
[official-gcc.git] / libgo / go / os / env_unix_test.go
blobf7b67ebbb80d6a77d609ab141e60e8f8551929f1
1 // Copyright 2013 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.
5 // +build darwin dragonfly freebsd linux netbsd openbsd solaris
7 package os_test
9 import (
10 "fmt"
11 . "os"
12 "testing"
15 var setenvEinvalTests = []struct {
16 k, v string
18 {"", ""}, // empty key
19 {"k=v", ""}, // '=' in key
20 {"\x00", ""}, // '\x00' in key
21 {"k", "\x00"}, // '\x00' in value
24 func TestSetenvUnixEinval(t *testing.T) {
25 for _, tt := range setenvEinvalTests {
26 err := Setenv(tt.k, tt.v)
27 if err == nil {
28 t.Errorf(`Setenv(%q, %q) == nil, want error`, tt.k, tt.v)
33 var shellSpecialVarTests = []struct {
34 k, v string
36 {"*", "asterisk"},
37 {"#", "pound"},
38 {"$", "dollar"},
39 {"@", "at"},
40 {"!", "exclamation mark"},
41 {"?", "question mark"},
42 {"-", "dash"},
45 func TestExpandEnvShellSpecialVar(t *testing.T) {
46 for _, tt := range shellSpecialVarTests {
47 Setenv(tt.k, tt.v)
48 defer Unsetenv(tt.k)
50 argRaw := fmt.Sprintf("$%s", tt.k)
51 argWithBrace := fmt.Sprintf("${%s}", tt.k)
52 if gotRaw, gotBrace := ExpandEnv(argRaw), ExpandEnv(argWithBrace); gotRaw != gotBrace {
53 t.Errorf("ExpandEnv(%q) = %q, ExpandEnv(%q) = %q; expect them to be equal", argRaw, gotRaw, argWithBrace, gotBrace)