From 9cea2c3dd4b5798f7f6f0bf382e5eca1694f0eb2 Mon Sep 17 00:00:00 2001 From: Sergio Martins Date: Wed, 5 Jun 2024 22:21:43 +0100 Subject: [PATCH] fix: Fix JSON output from ctest not being received 'exit' spawn event does not wait for stdout to be closed. 'close' is the correct event Also fixes the tests being flaky --- .gitignore | 1 + out/cmake.js | 11 +++++++++-- src/cmake.ts | 12 ++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 718fe71..bd32015 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ *.tgz *.log /out/ +/src/*.js diff --git a/out/cmake.js b/out/cmake.js index d069f89..5df245b 100644 --- a/out/cmake.js +++ b/out/cmake.js @@ -49,9 +49,16 @@ class CMakeTests { child.stdout.on("data", (chunk) => { output += chunk.toString(); }); - child.on("exit", (code) => { + child.on("close", (code) => { if (code === 0) { - resolve(this.ctestJsonToList(output)); + if (output.length == 0) { + console.error("ctestJsonToList: Empty json output. Command was ctest --show-only=json-v1 , in " + + this.buildDirPath); + reject(new Error("Failed to get ctest JSON output")); + } + else { + resolve(this.ctestJsonToList(output)); + } } else { reject(new Error("Failed to run ctest")); diff --git a/src/cmake.ts b/src/cmake.ts index 81f068e..895c0b3 100644 --- a/src/cmake.ts +++ b/src/cmake.ts @@ -44,9 +44,17 @@ export class CMakeTests { output += chunk.toString(); }); - child.on("exit", (code) => { + child.on("close", (code) => { if (code === 0) { - resolve(this.ctestJsonToList(output)); + if (output.length == 0) { + console.error( + "ctestJsonToList: Empty json output. Command was ctest --show-only=json-v1 , in " + + this.buildDirPath, + ); + reject(new Error("Failed to get ctest JSON output")); + } else { + resolve(this.ctestJsonToList(output)); + } } else { reject(new Error("Failed to run ctest")); }