1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
import type { Context } from ".";
import * as vscode from "vscode";
import * as assert from "assert";
import { targetToExecution } from "../../src/tasks";
export async function getTests(ctx: Context) {
await ctx.suite("Tasks", (suite) => {
suite.addTest("cargo targetToExecution", async () => {
assert.deepStrictEqual(
await targetToExecution({
type: "cargo",
command: "check",
args: ["foo"],
}).then(executionToSimple),
{
process: "cargo",
args: ["check", "foo"],
},
);
});
suite.addTest("shell targetToExecution", async () => {
assert.deepStrictEqual(
await targetToExecution({
type: "shell",
command: "thing",
args: ["foo"],
}).then(executionToSimple),
{
process: "thing",
args: ["foo"],
},
);
});
suite.addTest("base tasks", async () => {
const tasks = await vscode.tasks.fetchTasks({ type: "cargo" });
const expectedTasks = [
{
definition: { type: "cargo", command: "build" },
name: "cargo build",
execution: {
process: "cargo",
args: ["build"],
},
},
{
definition: {
type: "cargo",
command: "check",
},
name: "cargo check",
execution: {
process: "cargo",
args: ["check"],
},
},
{
definition: { type: "cargo", command: "clippy" },
name: "cargo clippy",
execution: {
process: "cargo",
args: ["clippy"],
},
},
{
definition: { type: "cargo", command: "test" },
name: "cargo test",
execution: {
process: "cargo",
args: ["test"],
},
},
{
definition: {
type: "cargo",
command: "clean",
},
name: "cargo clean",
execution: {
process: "cargo",
args: ["clean"],
},
},
{
definition: { type: "cargo", command: "run" },
name: "cargo run",
execution: {
process: "cargo",
args: ["run"],
},
},
];
tasks.map(f).forEach((actual, i) => {
const expected = expectedTasks[i];
assert.deepStrictEqual(actual, expected);
});
});
});
}
function f(task: vscode.Task): {
definition: vscode.TaskDefinition;
name: string;
execution: {
args: string[];
} & ({ command: string } | { process: string });
} {
const execution = executionToSimple(task.execution!);
return {
definition: task.definition,
name: task.name,
execution,
};
}
function executionToSimple(
taskExecution: vscode.ProcessExecution | vscode.ShellExecution | vscode.CustomExecution,
): {
args: string[];
} & ({ command: string } | { process: string }) {
const exec = taskExecution as vscode.ProcessExecution | vscode.ShellExecution;
if (exec instanceof vscode.ShellExecution) {
return {
command: typeof exec.command === "string" ? exec.command : (exec.command?.value ?? ""),
args: (exec.args ?? []).map((arg) => {
if (typeof arg === "string") {
return arg;
}
return arg.value;
}),
};
} else {
return {
process: exec.process,
args: exec.args,
};
}
}
|