Skip to content

Commit

Permalink
feat: Allow the caller to pass a output callback
Browse files Browse the repository at this point in the history
The caller can now get the QtTest executable output when running it
  • Loading branch information
iamsergio committed Apr 24, 2024
1 parent 09bc85c commit ec7f597
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
2 changes: 1 addition & 1 deletion out/qttest.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export declare class QtTest {
linksToQtTestLib(): Promise<boolean> | undefined;
isQtTestViaHelp(): Promise<boolean | undefined>;
slotByName(name: string): QtTestSlot | undefined;
runTest(slot?: QtTestSlot, cwd?: string): Promise<boolean>;
runTest(slot?: QtTestSlot, cwd?: string, outputFunc?: LoggerFunction | undefined): Promise<boolean>;
tapOutputFileName(slot?: QtTestSlot): string;
txtOutputFileName(slot?: QtTestSlot): string;
command(): {
Expand Down
11 changes: 10 additions & 1 deletion out/qttest.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class QtTest {
return undefined;
}
/// Runs this test
runTest(slot, cwd = "") {
runTest(slot, cwd = "", outputFunc = undefined) {
return __awaiter(this, void 0, void 0, function* () {
let args = [];
if (slot) {
Expand All @@ -219,6 +219,15 @@ class QtTest {
let cwdDir = cwd.length > 0 ? cwd : this.buildDirPath;
logMessage("Running " + this.filename + " " + args.join(" ") + " with cwd=" + cwdDir);
const child = (0, child_process_1.spawn)(this.filename, args, { cwd: cwdDir });
if (outputFunc) {
// Callers wants the process output:
child.stdout.on("data", (chunk) => {
outputFunc(chunk.toString());
});
child.stderr.on("data", (chunk) => {
outputFunc(chunk.toString());
});
}
child.on("exit", (code) => __awaiter(this, void 0, void 0, function* () {
/// Can code even be null ?
if (code == undefined)
Expand Down
13 changes: 12 additions & 1 deletion src/qttest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export class QtTest {
}

/// Runs this test
public async runTest(slot?: QtTestSlot, cwd: string = ""): Promise<boolean> {
public async runTest(slot?: QtTestSlot, cwd: string = "", outputFunc: LoggerFunction | undefined = undefined): Promise<boolean> {
let args: string[] = [];
if (slot) {
// Runs a single Qt test instead
Expand All @@ -216,6 +216,17 @@ export class QtTest {
logMessage("Running " + this.filename + " " + args.join(" ") + " with cwd=" + cwdDir);
const child = spawn(this.filename, args, { cwd: cwdDir });

if (outputFunc) {
// Callers wants the process output:
child.stdout.on("data", (chunk) => {
outputFunc(chunk.toString());
});

child.stderr.on("data", (chunk) => {
outputFunc(chunk.toString());
});
}

child.on("exit", async (code) => {
/// Can code even be null ?
if (code == undefined) code = -1;
Expand Down

0 comments on commit ec7f597

Please sign in to comment.