MCPcopy
hub / github.com/go-task/task / run

Method run

executor_test.go:142–218  ·  view source on GitHub ↗

run is the main function for running the test. It sets up the task executor, runs the task, and writes the output to a fixture file.

(t *testing.T)

Source from the content-addressed store, hash-verified

140// run is the main function for running the test. It sets up the task executor,
141// runs the task, and writes the output to a fixture file.
142func (tt *ExecutorTest) run(t *testing.T) {
143 t.Helper()
144 f := func(t *testing.T) {
145 t.Helper()
146 var buffer SyncBuffer
147
148 opts := append(
149 tt.executorOpts,
150 task.WithStdout(&buffer),
151 task.WithStderr(&buffer),
152 )
153
154 // If the test has input, create a reader for it and add it to the
155 // executor options
156 if tt.input != "" {
157 var reader bytes.Buffer
158 reader.WriteString(tt.input)
159 opts = append(opts, task.WithStdin(&reader))
160 }
161
162 // Set up the task executor
163 e := task.NewExecutor(opts...)
164
165 // Create a golden fixture file for the output
166 g := goldie.New(t,
167 goldie.WithFixtureDir(filepath.Join(e.Dir, "testdata")),
168 goldie.WithEqualFn(NormalizedEqual),
169 )
170
171 // Call setup and check for errors
172 if err := e.Setup(); tt.wantSetupError {
173 require.Error(t, err)
174 tt.writeFixtureErrSetup(t, g, err)
175 tt.writeFixtureBuffer(t, g, buffer.buf)
176 return
177 } else {
178 require.NoError(t, err)
179 }
180
181 // Create the task call
182 vars := ast.NewVars()
183 for key, value := range tt.vars {
184 vars.Set(key, ast.Var{Value: value})
185 }
186 call := &task.Call{
187 Task: tt.task,
188 Vars: vars,
189 }
190
191 // Run the task and check for errors
192 ctx := t.Context()
193 if err := e.Run(ctx, call); tt.wantRunError {
194 require.Error(t, err)
195 tt.writeFixtureErrRun(t, g, err)
196 tt.writeFixtureBuffer(t, g, buffer.buf)
197 return
198 } else {
199 require.NoError(t, err)

Callers 1

NewExecutorTestFunction · 0.95

Calls 10

SetupMethod · 0.95
SetMethod · 0.95
RunMethod · 0.95
writeFixtureErrRunMethod · 0.95
StatusMethod · 0.95
writeFixtureStatusMethod · 0.95
NewVarsFunction · 0.92
writeFixtureErrSetupMethod · 0.80
writeFixtureBufferMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected