@@ -39,13 +39,28 @@ var testWork = flag.Bool("testwork", false, "")
3939
4040// Env holds the environment to use at the start of a test script invocation.
4141type Env struct {
42+ // WorkDir holds the path to the root directory of the
43+ // extracted files.
4244 WorkDir string
43- Vars []string
44- Cd string
45+ // Vars holds the initial set environment variables that will be passed to the
46+ // testscript commands.
47+ Vars []string
48+ // Cd holds the initial current working directory.
49+ Cd string
50+ // Values holds a map of arbitrary values for use by custom
51+ // testscript commands. This enables Setup to pass arbitrary
52+ // values (not just strings) through to custom commands.
53+ Values map [interface {}]interface {}
4554
4655 ts * TestScript
4756}
4857
58+ // Value returns a value from Env.Values, or nil if no
59+ // value was set by Setup.
60+ func (ts * TestScript ) Value (key interface {}) interface {} {
61+ return ts .values [key ]
62+ }
63+
4964// Defer arranges for f to be called at the end
5065// of the test. If Defer is called multiple times, the
5166// defers are executed in reverse order (similar
@@ -171,23 +186,24 @@ type TestScript struct {
171186 params Params
172187 t T
173188 testTempDir string
174- workdir string // temporary work dir ($WORK)
175- log bytes.Buffer // test execution log (printed at end of test)
176- mark int // offset of next log truncation
177- cd string // current directory during test execution; initially $WORK/gopath/src
178- name string // short name of test ("foo")
179- file string // full file name ("testdata/script/foo.txt")
180- lineno int // line number currently executing
181- line string // line currently executing
182- env []string // environment list (for os/exec)
183- envMap map [string ]string // environment mapping (matches env; on Windows keys are lowercase)
184- stdin string // standard input to next 'go' command; set by 'stdin' command.
185- stdout string // standard output from last 'go' command; for 'stdout' command
186- stderr string // standard error from last 'go' command; for 'stderr' command
187- stopped bool // test wants to stop early
188- start time.Time // time phase started
189- background []backgroundCmd // backgrounded 'exec' and 'go' commands
190- deferred func () // deferred cleanup actions.
189+ workdir string // temporary work dir ($WORK)
190+ log bytes.Buffer // test execution log (printed at end of test)
191+ mark int // offset of next log truncation
192+ cd string // current directory during test execution; initially $WORK/gopath/src
193+ name string // short name of test ("foo")
194+ file string // full file name ("testdata/script/foo.txt")
195+ lineno int // line number currently executing
196+ line string // line currently executing
197+ env []string // environment list (for os/exec)
198+ envMap map [string ]string // environment mapping (matches env; on Windows keys are lowercase)
199+ values map [interface {}]interface {} // values for custom commands
200+ stdin string // standard input to next 'go' command; set by 'stdin' command.
201+ stdout string // standard output from last 'go' command; for 'stdout' command
202+ stderr string // standard error from last 'go' command; for 'stderr' command
203+ stopped bool // test wants to stop early
204+ start time.Time // time phase started
205+ background []backgroundCmd // backgrounded 'exec' and 'go' commands
206+ deferred func () // deferred cleanup actions.
191207
192208 ctxt context.Context // per TestScript context
193209}
@@ -213,6 +229,7 @@ func (ts *TestScript) setup() string {
213229 ":=" + string (os .PathListSeparator ),
214230 },
215231 WorkDir : ts .workdir ,
232+ Values : make (map [interface {}]interface {}),
216233 Cd : ts .workdir ,
217234 ts : ts ,
218235 }
@@ -242,6 +259,7 @@ func (ts *TestScript) setup() string {
242259 }
243260 ts .cd = env .Cd
244261 ts .env = env .Vars
262+ ts .values = env .Values
245263
246264 ts .envMap = make (map [string ]string )
247265 for _ , kv := range ts .env {
0 commit comments