Skip to content

Commit 1c3ab12

Browse files
committed
Merge remote-tracking branch 'origin/main' into codemirror
2 parents 155caab + 56c2358 commit 1c3ab12

File tree

3 files changed

+203
-24
lines changed

3 files changed

+203
-24
lines changed

src/plugins/terminal/src/android/TerminalService.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,24 @@ private void stopProcess(String pid) {
263263
}
264264
}
265265

266-
private void isProcessRunning(String pid, Messenger clientMessenger) {
267-
Process process = processes.get(pid);
268-
String status = process != null && ProcessUtils.isAlive(process) ? "running" : "not_found";
269-
sendMessageToClient(pid, "isRunning", status);
266+
private void isProcessRunning(String pid, Messenger clientMessenger) {
267+
boolean running =
268+
processes.containsKey(pid) &&
269+
ProcessUtils.isAlive(processes.get(pid));
270+
271+
try {
272+
Message reply = Message.obtain();
273+
Bundle bundle = new Bundle();
274+
bundle.putString("id", pid);
275+
bundle.putString("action", "isRunning");
276+
bundle.putString("data", running ? "running" : "stopped");
277+
reply.setData(bundle);
278+
clientMessenger.send(reply);
279+
} catch (RemoteException e) {
280+
// nothing else to do
270281
}
282+
}
283+
271284

272285
private void cleanup(String id) {
273286
processes.remove(id);

src/test/exec.tests.js

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import { TestRunner } from "./tester";
2+
3+
export async function runExecutorTests(writeOutput) {
4+
const runner = new TestRunner("Executor API Tests");
5+
6+
runner.test("Executor available", async (test) => {
7+
test.assert(
8+
typeof Executor !== "undefined",
9+
"Executor should be available globally",
10+
);
11+
});
12+
13+
runner.test("Background Executor available", async (test) => {
14+
test.assert(
15+
typeof Executor.BackgroundExecutor !== "undefined",
16+
"Background Executor should be available globally",
17+
);
18+
});
19+
20+
runner.test("execute()", async (test) => {
21+
test.assert(
22+
(await Executor.execute("echo test123")).includes("test123"),
23+
"Command output should match",
24+
);
25+
});
26+
27+
runner.test("execute() (BackgroundExecutor)", async (test) => {
28+
test.assert(
29+
(await Executor.BackgroundExecutor.execute("echo test123")).includes(
30+
"test123",
31+
),
32+
"Command output should match",
33+
);
34+
});
35+
36+
runner.test("start()", async (test) => {
37+
let stdout = "";
38+
39+
const uuid = await Executor.start("sh", (type, data) => {
40+
if (type === "stdout") stdout += data;
41+
});
42+
43+
await Executor.write(uuid, "echo hello\n");
44+
await new Promise((r) => setTimeout(r, 200));
45+
await Executor.stop(uuid);
46+
47+
await new Promise((r) => setTimeout(r, 200));
48+
49+
test.assert(stdout.includes("hello"), "Shell should echo output");
50+
});
51+
52+
runner.test("start() (BackgroundExecutor)", async (test) => {
53+
let stdout = "";
54+
55+
const uuid = await Executor.BackgroundExecutor.start("sh", (type, data) => {
56+
if (type === "stdout") stdout += data;
57+
});
58+
59+
await Executor.BackgroundExecutor.write(uuid, "echo hello\n");
60+
await new Promise((r) => setTimeout(r, 200));
61+
await Executor.BackgroundExecutor.stop(uuid);
62+
63+
await new Promise((r) => setTimeout(r, 200));
64+
65+
test.assert(stdout.includes("hello"), "Shell should echo output");
66+
});
67+
68+
runner.test("start/stop() (BackgroundExecutor)", async (test) => {
69+
let stdout = "";
70+
71+
const uuid = await Executor.BackgroundExecutor.start(
72+
"sh",
73+
(type, data) => {},
74+
);
75+
76+
await new Promise((r) => setTimeout(r, 200));
77+
78+
const isRunning = await Executor.BackgroundExecutor.isRunning(uuid);
79+
80+
test.assert(isRunning === true, "Executor must be running");
81+
82+
await new Promise((r) => setTimeout(r, 200));
83+
84+
await Executor.BackgroundExecutor.stop(uuid);
85+
86+
await new Promise((r) => setTimeout(r, 200));
87+
88+
test.assert(
89+
isRunning !== (await Executor.BackgroundExecutor.isRunning(uuid)),
90+
"Executor must be stopped",
91+
);
92+
test.assert(
93+
(await Executor.BackgroundExecutor.isRunning(uuid)) === false,
94+
"Executor must be stopped",
95+
);
96+
});
97+
98+
runner.test("start/stop()", async (test) => {
99+
let stdout = "";
100+
101+
const uuid = await Executor.start("sh", (type, data) => {});
102+
103+
await new Promise((r) => setTimeout(r, 200));
104+
105+
const isRunning = await Executor.isRunning(uuid);
106+
107+
test.assert(isRunning === true, "Executor must be running");
108+
109+
await new Promise((r) => setTimeout(r, 200));
110+
111+
await Executor.stop(uuid);
112+
113+
await new Promise((r) => setTimeout(r, 200));
114+
115+
test.assert(
116+
(await Executor.isRunning(uuid)) === false,
117+
"Executor must be stopped",
118+
);
119+
});
120+
121+
runner.test("FDROID env variable", async (test) => {
122+
const result = await Executor.execute("echo $FDROID");
123+
124+
const isSet = result.trim().length > 0;
125+
126+
test.assert(isSet, "FDROID env variable should be set");
127+
});
128+
129+
return await runner.run(writeOutput);
130+
}

src/test/tester.js

Lines changed: 56 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { runAceCompatibilityTests } from "./ace.test";
22
import { runCodeMirrorTests } from "./editor.tests";
3+
import { runExecutorTests } from "./exec.tests";
34
import { runSanityTests } from "./sanity.tests";
45

56
export async function runAllTests() {
@@ -18,6 +19,7 @@ export async function runAllTests() {
1819
await runSanityTests(write);
1920
await runCodeMirrorTests(write);
2021
await runAceCompatibilityTests(write);
22+
await runExecutorTests(write);
2123

2224
write("\x1b[36m\x1b[1mTests completed!\x1b[0m\n");
2325
} catch (error) {
@@ -82,6 +84,7 @@ class TestRunner {
8284
this.passed = 0;
8385
this.failed = 0;
8486
this.results = [];
87+
this.skipped = 0;
8588
}
8689

8790
/**
@@ -106,6 +109,10 @@ class TestRunner {
106109
}
107110
}
108111

112+
skip(reason = "Skipped") {
113+
throw new SkipTest(reason);
114+
}
115+
109116
async _runWithTimeout(fn, ctx, timeoutMs) {
110117
return new Promise((resolve, reject) => {
111118
let finished = false;
@@ -163,31 +170,49 @@ class TestRunner {
163170

164171
try {
165172
await delay(200);
166-
167-
await this._runWithTimeout(test.fn, this, 3000);
173+
await this._runWithTimeout(test.fn, this, 10000);
168174

169175
stopSpinner();
170176

171177
this.passed++;
172-
this.results.push({ name: test.name, status: "PASS", error: null });
178+
this.results.push({ name: test.name, status: "PASS" });
173179
line(` ${COLORS.GREEN}${COLORS.RESET} ${test.name}`, COLORS.GREEN);
174180
} catch (error) {
175181
stopSpinner();
176182

177-
this.failed++;
178-
this.results.push({
179-
name: test.name,
180-
status: "FAIL",
181-
error: error.message,
182-
});
183-
line(
184-
` ${COLORS.RED}${COLORS.RESET} ${test.name}`,
185-
COLORS.RED + COLORS.BRIGHT,
186-
);
187-
line(
188-
` ${COLORS.DIM}└─ ${error.message}${COLORS.RESET}`,
189-
COLORS.RED + COLORS.DIM,
190-
);
183+
if (error instanceof SkipTest) {
184+
this.skipped++;
185+
this.results.push({
186+
name: test.name,
187+
status: "SKIP",
188+
reason: error.message,
189+
});
190+
191+
line(
192+
` ${COLORS.YELLOW}?${COLORS.RESET} ${test.name}`,
193+
COLORS.YELLOW + COLORS.BRIGHT,
194+
);
195+
line(
196+
` ${COLORS.DIM}└─ ${error.message}${COLORS.RESET}`,
197+
COLORS.YELLOW + COLORS.DIM,
198+
);
199+
} else {
200+
this.failed++;
201+
this.results.push({
202+
name: test.name,
203+
status: "FAIL",
204+
error: error.message,
205+
});
206+
207+
line(
208+
` ${COLORS.RED}${COLORS.RESET} ${test.name}`,
209+
COLORS.RED + COLORS.BRIGHT,
210+
);
211+
line(
212+
` ${COLORS.DIM}└─ ${error.message}${COLORS.RESET}`,
213+
COLORS.RED + COLORS.DIM,
214+
);
215+
}
191216
}
192217
}
193218

@@ -196,15 +221,19 @@ class TestRunner {
196221
line("─────────────────────────────────────────────", COLORS.GRAY);
197222

198223
const total = this.tests.length;
199-
const percentage = total ? ((this.passed / total) * 100).toFixed(1) : "0.0";
224+
const effectiveTotal = total - this.skipped;
225+
226+
const percentage = effectiveTotal
227+
? ((this.passed / effectiveTotal) * 100).toFixed(1)
228+
: "0.0";
200229

201230
const statusColor = this.failed === 0 ? COLORS.GREEN : COLORS.YELLOW;
202231

203232
line(
204233
` Tests: ${COLORS.BRIGHT}${total}${COLORS.RESET} | ` +
205-
`${statusColor}Passed: ${this.passed}${COLORS.RESET} | ` +
234+
`${COLORS.GREEN}Passed: ${this.passed}${COLORS.RESET} | ` +
235+
`${COLORS.YELLOW}Skipped: ${this.skipped}${COLORS.RESET} | ` +
206236
`${COLORS.RED}Failed: ${this.failed}${COLORS.RESET}`,
207-
statusColor,
208237
);
209238

210239
line(
@@ -228,4 +257,11 @@ class TestRunner {
228257
}
229258
}
230259

260+
class SkipTest extends Error {
261+
constructor(message = "Skipped") {
262+
super(message);
263+
this.name = "SkipTest";
264+
}
265+
}
266+
231267
export { TestRunner };

0 commit comments

Comments
 (0)