summaryrefslogtreecommitdiff
path: root/jstests/libs/golden_test.js
diff options
context:
space:
mode:
authorDavid Percy <david.percy@mongodb.com>2023-04-27 19:22:45 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2023-05-01 22:34:53 +0000
commit86bd5899b0db0681fd5cd2b2fae0452922958979 (patch)
tree2e633d3db5b1521c68a171939dce9921c12f9963 /jstests/libs/golden_test.js
parentfb043a73fa477d52121e351813c005519636bd4c (diff)
downloadmongo-86bd5899b0db0681fd5cd2b2fae0452922958979.tar.gz
SERVER-76620 Ensure golden output of each print() is newline-terminated
Diffstat (limited to 'jstests/libs/golden_test.js')
-rw-r--r--jstests/libs/golden_test.js14
1 files changed, 13 insertions, 1 deletions
diff --git a/jstests/libs/golden_test.js b/jstests/libs/golden_test.js
index f3e218f1795..d7ce9f6d5a9 100644
--- a/jstests/libs/golden_test.js
+++ b/jstests/libs/golden_test.js
@@ -21,7 +21,19 @@ print = (() => {
const original = print;
return function print(...args) {
// Imitate GlobalInfo::Functions::print::call.
- const str = args.map(a => a == null ? '[unknown type]' : a).join(' ');
+ let str = args.map(a => a == null ? '[unknown type]' : a).join(' ');
+
+ // Make sure each print() call ends in a newline.
+ //
+ // From manual testing, it seems (print('a'), print('b')) behaves the same as
+ // (print('a\n'), print('b\n')); that behavior must be to ensure each print call appears on
+ // its own line for readability. In the context of golden testing, we want to match that
+ // behavior, and this also ensures the test output is a proper text file
+ // (newline-terminated).
+ if (str.slice(-1) !== '\n') {
+ str += '\n';
+ }
+
_writeGoldenData(str);
return original(...args);