Skip to content

Commit 49528ab

Browse files
committed
Take failed test logs from file.
1 parent 622cea0 commit 49528ab

1 file changed

Lines changed: 61 additions & 28 deletions

File tree

  • rascal-vscode-extension/src/test/vscode-suite

rascal-vscode-extension/src/test/vscode-suite/utils.ts

Lines changed: 61 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
import { assert, expect } from "chai";
2929
import { createHash } from "crypto";
30-
import { readFile, stat, unlink, writeFile } from "fs/promises";
30+
import { existsSync } from "fs";
31+
import { readdir, readFile, stat, unlink, writeFile } from "fs/promises";
3132
import * as os from 'os';
3233
import path from "path/posix";
3334
import { env } from "process";
@@ -524,40 +525,72 @@ async function assureDebugLevelLoggingIsEnabled() {
524525
export function printRascalOutputOnFailure(channel: 'Language Parametric Rascal' | 'Rascal MPL') {
525526

526527
const ZOOM_OUT_FACTOR = 5;
528+
const N_LOG_LINES = 250;
529+
// We guess some locations where the logs can be, since we cannot easily retrieve those from VS Code.
530+
const TEST_STORAGE_DIRS = [
531+
path.join(path.resolve(), "uitests"), // typical CI path
532+
path.join(os.tmpdir(), "vscode-uitests") // typical local path
533+
];
534+
527535
afterEach("print output in case of failure", async function () {
528536
if (!this.currentTest || this.currentTest.state !== "failed") { return; }
529-
const bbp = new BottomBarPanel();
530-
try {
531-
for (let z = 0; z < ZOOM_OUT_FACTOR; z++) {
532-
await new Workbench().executeCommand('workbench.action.zoomOut');
533-
}
534-
await bbp.maximize();
535-
console.log('**********************************************');
536-
console.log('***** Rascal MPL output for the failed tests: ');
537-
let textLines: WebElement[] = [];
538-
let tries = 0;
539-
while (textLines.length === 0 && tries < 3) {
540-
await showRascalOutput(bbp, channel);
541-
textLines = await ignoreFails(bbp.findElements(By.className('view-line'))) ?? [];
542-
tries++;
543-
}
544-
if (textLines.length === 0) {
545-
console.log("We could not capture the output lines");
546-
}
547537

548-
for (const l of textLines) {
549-
console.log(await l.getText());
538+
console.log('**********************************************');
539+
console.log(`***** ${channel} output for the failed tests: `);
540+
541+
let foundLogs = false;
542+
for (const vsCodeDir of TEST_STORAGE_DIRS) {
543+
try {
544+
const logDir = path.join(vsCodeDir, "settings", "logs");
545+
if (existsSync(logDir)) {
546+
for (const entry of await readdir(logDir, {recursive: true})) {
547+
if (entry.includes("usethesource.rascalmpl") && entry.includes(channel)) {
548+
console.log(`***** ${entry}`);
549+
const contents = await readFile(path.join(logDir, entry), {encoding: "utf-8"});
550+
console.log(contents.split('\n').splice(-N_LOG_LINES).join('\n'));
551+
foundLogs = true;
552+
}
553+
}
554+
}
555+
} catch (e) {
556+
console.log(`Error capturing logs in ${vsCodeDir}: `, e);
550557
}
551-
} catch (e) {
552-
console.log('Error capturing output: ', e);
553558
}
554-
finally {
555-
console.log('*******End output*****************************');
556-
for (let z = 0; z < ZOOM_OUT_FACTOR; z++) {
557-
await new Workbench().executeCommand('workbench.action.zoomIn');
559+
560+
if (!foundLogs) {
561+
// Fall back to legacy copy-from-VS Code approach if there were no log files.
562+
const bbp = new BottomBarPanel();
563+
try {
564+
for (let z = 0; z < ZOOM_OUT_FACTOR; z++) {
565+
await new Workbench().executeCommand('workbench.action.zoomOut');
566+
}
567+
await bbp.maximize();
568+
let textLines: WebElement[] = [];
569+
let tries = 0;
570+
while (textLines.length === 0 && tries < 3) {
571+
await showRascalOutput(bbp, channel);
572+
textLines = await ignoreFails(bbp.findElements(By.className('view-line'))) ?? [];
573+
tries++;
574+
}
575+
if (textLines.length === 0) {
576+
console.log("We could not capture the output lines");
577+
}
578+
579+
for (const l of textLines) {
580+
console.log(await l.getText());
581+
}
582+
} catch (e) {
583+
console.log('Error capturing output: ', e);
584+
}
585+
finally {
586+
for (let z = 0; z < ZOOM_OUT_FACTOR; z++) {
587+
await new Workbench().executeCommand('workbench.action.zoomIn');
588+
}
589+
await bbp.closePanel();
558590
}
559-
await bbp.closePanel();
560591
}
592+
593+
console.log('*******End output*****************************');
561594
});
562595
}
563596

0 commit comments

Comments
 (0)