NewFormatterTest sets up a new [task.Executor] with the given options and runs a task with the given [FormatterTestOption]s. The output of the task is written to a set of fixture files depending on the configuration of the test.
(t *testing.T, opts ...FormatterTestOption)
| 39 | // runs a task with the given [FormatterTestOption]s. The output of the task is |
| 40 | // written to a set of fixture files depending on the configuration of the test. |
| 41 | func NewFormatterTest(t *testing.T, opts ...FormatterTestOption) { |
| 42 | t.Helper() |
| 43 | tt := &FormatterTest{ |
| 44 | task: "default", |
| 45 | vars: map[string]any{}, |
| 46 | TaskTest: TaskTest{ |
| 47 | experiments: map[*experiments.Experiment]int{}, |
| 48 | fixtureTemplateData: map[string]any{}, |
| 49 | }, |
| 50 | } |
| 51 | // Apply the functional options |
| 52 | for _, opt := range opts { |
| 53 | opt.applyToFormatterTest(tt) |
| 54 | } |
| 55 | // Enable any experiments that have been set |
| 56 | for x, v := range tt.experiments { |
| 57 | prev := *x |
| 58 | *x = experiments.Experiment{ |
| 59 | Name: prev.Name, |
| 60 | AllowedValues: []int{v}, |
| 61 | Value: v, |
| 62 | } |
| 63 | t.Cleanup(func() { |
| 64 | *x = prev |
| 65 | }) |
| 66 | } |
| 67 | tt.run(t) |
| 68 | } |
| 69 | |
| 70 | // Functional options |
| 71 |
no test coverage detected
searching dependent graphs…