diff --git a/tests/run-tests.py b/tests/run-tests.py
index 9a9312e84e4e5bfed1e9089dc9cb14dd48cf05d3_dGVzdHMvcnVuLXRlc3RzLnB5..9a2de8dae27baa4b46717310d7e51c26699bd85d_dGVzdHMvcnVuLXRlc3RzLnB5 100755
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -487,6 +487,8 @@
             # non-command/result - queue up for merged output
             after.setdefault(pos, []).append(l)
 
+    if script and not script[-1].endswith('\n'):
+        script[-1] = script[-1] + '\n'
     script.append('echo %s %s $?\n' % (salt, n + 1))
 
     fd, name = tempfile.mkstemp(suffix='hg-tst')