Source file
src/os/env_unix_test.go
1
2
3
4
5
6
7 package os_test
8
9 import (
10 "fmt"
11 . "os"
12 "testing"
13 )
14
15 var setenvEinvalTests = []struct {
16 k, v string
17 }{
18 {"", ""},
19 {"k=v", ""},
20 {"\x00", ""},
21 {"k", "\x00"},
22 }
23
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)
29 }
30 }
31 }
32
33 var shellSpecialVarTests = []struct {
34 k, v string
35 }{
36 {"*", "asterisk"},
37 {"#", "pound"},
38 {"$", "dollar"},
39 {"@", "at"},
40 {"!", "exclamation mark"},
41 {"?", "question mark"},
42 {"-", "dash"},
43 }
44
45 func TestExpandEnvShellSpecialVar(t *testing.T) {
46 for _, tt := range shellSpecialVarTests {
47 Setenv(tt.k, tt.v)
48 defer Unsetenv(tt.k)
49
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)
54 }
55 }
56 }
57
View as plain text