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)
| 110 | // run is the main function for running the test. It sets up the task executor, |
| 111 | // runs the task, and writes the output to a fixture file. |
| 112 | func (tt *FormatterTest) run(t *testing.T) { |
| 113 | t.Helper() |
| 114 | f := func(t *testing.T) { |
| 115 | t.Helper() |
| 116 | var buf bytes.Buffer |
| 117 | |
| 118 | opts := append( |
| 119 | tt.executorOpts, |
| 120 | task.WithStdout(&buf), |
| 121 | task.WithStderr(&buf), |
| 122 | ) |
| 123 | |
| 124 | // Set up the task executor |
| 125 | e := task.NewExecutor(opts...) |
| 126 | |
| 127 | // Create a golden fixture file for the output |
| 128 | g := goldie.New(t, |
| 129 | goldie.WithFixtureDir(filepath.Join(e.Dir, "testdata")), |
| 130 | goldie.WithEqualFn(NormalizedEqual), |
| 131 | ) |
| 132 | |
| 133 | // Call setup and check for errors |
| 134 | if err := e.Setup(); tt.wantSetupError { |
| 135 | require.Error(t, err) |
| 136 | tt.writeFixtureErrSetup(t, g, err) |
| 137 | tt.writeFixtureBuffer(t, g, buf) |
| 138 | return |
| 139 | } else { |
| 140 | require.NoError(t, err) |
| 141 | } |
| 142 | |
| 143 | // Create the task call |
| 144 | vars := ast.NewVars() |
| 145 | for key, value := range tt.vars { |
| 146 | vars.Set(key, ast.Var{Value: value}) |
| 147 | } |
| 148 | |
| 149 | // Run the formatter and check for errors |
| 150 | if _, err := e.ListTasks(tt.listOptions); tt.wantListError { |
| 151 | require.Error(t, err) |
| 152 | tt.writeFixtureErrList(t, g, err) |
| 153 | tt.writeFixtureBuffer(t, g, buf) |
| 154 | return |
| 155 | } else { |
| 156 | require.NoError(t, err) |
| 157 | } |
| 158 | |
| 159 | tt.writeFixtureBuffer(t, g, buf) |
| 160 | } |
| 161 | |
| 162 | // Run the test (with a name if it has one) |
| 163 | if tt.name != "" { |
| 164 | t.Run(tt.name, f) |
| 165 | } else { |
| 166 | f(t) |
| 167 | } |
| 168 | } |
| 169 |
no test coverage detected