|
1 | 1 | import assert from 'assert';
|
| 2 | +import { spawnSync } from 'child_process'; |
2 | 3 | import { existsSync, readFileSync, writeFileSync } from 'fs';
|
3 | 4 | import * as vscode from 'vscode';
|
4 | 5 | import {
|
5 | 6 | SimpleTaskProvider,
|
6 | 7 | findTaskByName,
|
7 | 8 | getConventionalTaskLabel,
|
8 | 9 | } from '../../src/taskProviders';
|
| 10 | +import { setTerminalEnvironment } from '../../src/helpers'; |
9 | 11 |
|
10 | 12 | /**
|
11 | 13 | * This function compares some actual output to an expected referenced stored in
|
@@ -155,7 +157,39 @@ export async function testTask(
|
155 | 157 | let msg = `Got status ${execStatus ?? "'undefined'"} for task '${taskName}'`;
|
156 | 158 | if (task.execution instanceof vscode.ShellExecution) {
|
157 | 159 | msg += ` with command line: ${getCmdLine(task.execution)}`;
|
| 160 | + |
| 161 | + try { |
| 162 | + /** |
| 163 | + * Let's try re-running the command line explicitlely to obtain its output. |
| 164 | + */ |
| 165 | + const cwd = vscode.workspace.workspaceFolders[0].uri.fsPath; |
| 166 | + msg += `\nTrying to re-run the command explicitly in: ${cwd}`; |
| 167 | + const env = { ...process.env }; |
| 168 | + setTerminalEnvironment(env); |
| 169 | + const cp = spawnSync( |
| 170 | + typeof task.execution.command == 'string' |
| 171 | + ? task.execution.command |
| 172 | + : task.execution.command.value, |
| 173 | + task.execution.args.map((arg) => { |
| 174 | + if (typeof arg == 'string') { |
| 175 | + return arg; |
| 176 | + } else { |
| 177 | + return arg.value; |
| 178 | + } |
| 179 | + }), |
| 180 | + { cwd: cwd, env: env } |
| 181 | + ); |
| 182 | + |
| 183 | + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions |
| 184 | + msg += `\nProcess ended with exit code ${cp.status} and output:\n`; |
| 185 | + // msg += cp.stdout.toString() + cp.stderr.toString(); |
| 186 | + msg += cp.output.map((b) => (b != null ? b.toString() : '')).join(''); |
| 187 | + } catch (error) { |
| 188 | + // eslint-disable-next-line @typescript-eslint/restrict-template-expressions |
| 189 | + msg += `\nEncountered an error: ${error}`; |
| 190 | + } |
158 | 191 | }
|
| 192 | + |
159 | 193 | assert.fail(msg);
|
160 | 194 | }
|
161 | 195 | }
|
|
0 commit comments