...
Source file
src/os/env_unix_test.go
Documentation: os
1
2
3
4
5
6
7
8 package os_test
9
10 import (
11 "fmt"
12 . "os"
13 "testing"
14 )
15
16 var setenvEinvalTests = []struct {
17 k, v string
18 }{
19 {"", ""},
20 {"k=v", ""},
21 {"\x00", ""},
22 {"k", "\x00"},
23 }
24
25 func TestSetenvUnixEinval(t *testing.T) {
26 for _, tt := range setenvEinvalTests {
27 err := Setenv(tt.k, tt.v)
28 if err == nil {
29 t.Errorf(`Setenv(%q, %q) == nil, want error`, tt.k, tt.v)
30 }
31 }
32 }
33
34 var shellSpecialVarTests = []struct {
35 k, v string
36 }{
37 {"*", "asterisk"},
38 {"#", "pound"},
39 {"$", "dollar"},
40 {"@", "at"},
41 {"!", "exclamation mark"},
42 {"?", "question mark"},
43 {"-", "dash"},
44 }
45
46 func TestExpandEnvShellSpecialVar(t *testing.T) {
47 for _, tt := range shellSpecialVarTests {
48 Setenv(tt.k, tt.v)
49 defer Unsetenv(tt.k)
50
51 argRaw := fmt.Sprintf("$%s", tt.k)
52 argWithBrace := fmt.Sprintf("${%s}", tt.k)
53 if gotRaw, gotBrace := ExpandEnv(argRaw), ExpandEnv(argWithBrace); gotRaw != gotBrace {
54 t.Errorf("ExpandEnv(%q) = %q, ExpandEnv(%q) = %q; expect them to be equal", argRaw, gotRaw, argWithBrace, gotBrace)
55 }
56 }
57 }
58
View as plain text