From 0f630d05afdbd8f1aa89b50d7e9629b7e3473bbb Mon Sep 17 00:00:00 2001 From: Andrew Scholer Date: Tue, 14 Oct 2025 17:53:16 -0700 Subject: [PATCH] Better handling of unit tests in visible or invisible suffix code --- .../runestone/activecode/js/activecode.js | 1 + .../runestone/activecode/js/livecode.js | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/bases/rsptx/interactives/runestone/activecode/js/activecode.js b/bases/rsptx/interactives/runestone/activecode/js/activecode.js index 774540881..4b9d6105d 100755 --- a/bases/rsptx/interactives/runestone/activecode/js/activecode.js +++ b/bases/rsptx/interactives/runestone/activecode/js/activecode.js @@ -1543,6 +1543,7 @@ Yet another is that there is an internal error. The internal error message is: } prog = pretext + prog; } + //any visible suffix already is included in editor code if (useSuffix && this.suffix) { prog = prog + this.suffix; } diff --git a/bases/rsptx/interactives/runestone/activecode/js/livecode.js b/bases/rsptx/interactives/runestone/activecode/js/livecode.js index e73e7695d..83198f527 100644 --- a/bases/rsptx/interactives/runestone/activecode/js/livecode.js +++ b/bases/rsptx/interactives/runestone/activecode/js/livecode.js @@ -52,9 +52,21 @@ export default class LiveCode extends ActiveCode { } createErrorOutput() { } + + getCombinedSuffixes() { + if (this.suffix && this.visibleSuffix) + return this.suffix + this.visibleSuffix; + else if (this.suffix) + return this.suffix; + else if (this.visibleSuffix) + return this.visibleSuffix; + return ""; + } + hasUnitTests() { - return this.language === "java" && this.suffix && this.suffix.indexOf("import org.junit") > -1 - || this.language === "cpp" && this.suffix && this.suffix.indexOf("[doctest]") > -1; + let combinedSuffix = this.getCombinedSuffixes(); + return this.language === "java" && combinedSuffix.indexOf("import org.junit") > -1 + || this.language === "cpp" && combinedSuffix.indexOf("doctest.h") > -1; } /* Main runProg method for livecode @@ -491,7 +503,7 @@ export default class LiveCode extends ActiveCode { let output = result.stdout ? result.stdout : ""; $(odiv).html(output); } - if (this.suffix) { + if (this.hasUnitTests() || this.iotests) { if (this.parsedOutput.pct === undefined) { this.parsedOutput.pct = this.parsedOutput.passed =