Skip to content

Commit bd92295

Browse files
committed
Process: Enhance docs and tests related to newline handling
See #5083.
1 parent 5af1f17 commit bd92295

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

atest/robot/standard_libraries/process/newlines.robot

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ Trailing newline is removed
99
Internal newlines are preserved
1010
Check Test Case ${TESTNAME}
1111

12+
CRLF is converted to LF
13+
Check Test Case ${TESTNAME}
14+
1215
Newlines with custom stream
1316
Check Test Case ${TESTNAME}

atest/testdata/standard_libraries/process/newlines.robot

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@ Resource process_resource.robot
55
Trailing newline is removed
66
${result}= Run Process python -c import sys; sys.stdout.write('nothing to remove')
77
Result should equal ${result} stdout=nothing to remove
8-
${result}= Run Process python -c import sys; sys.stdout.write('one is removed\\n')
9-
Result should equal ${result} stdout=one is removed
8+
${result}= Run Process python -c import sys; sys.stdout.write('removed\\n')
9+
Result should equal ${result} stdout=removed
1010
${result}= Run Process python -c import sys; sys.stdout.write('only one is removed\\n\\n\\n')
1111
Result should equal ${result} stdout=only one is removed\n\n
1212

1313
Internal newlines are preserved
14-
${result}= Run Process python -c print('1\\n2\\n3')
14+
${result}= Run Process python -c import sys; sys.stdout.write('1\\n2\\n3\\n')
1515
Result should equal ${result} stdout=1\n2\n3
1616

17+
CRLF is converted to LF
18+
${result}= Run Process python -c import sys; sys.stdout.write('1\\r\\n2\\r3\\n4')
19+
# On Windows \r\n is turned \r\r\n when writing and thus the result is \r\n.
20+
# Elsewhere \r\n is not changed when writing and thus the result is \n.
21+
# ${\n} is \r\n or \n depending on the OS and thus works as the expected result.
22+
Result should equal ${result} stdout=1${\n}2\r3\n4
23+
1724
Newlines with custom stream
18-
${result}= Run Process python -c print('1\\n2\\n3') stdout=${STDOUT}
19-
Result should equal ${result} stdout=1\n2\n3 stdout_path=${STDOUT}
25+
${result}= Run Process python -c import sys; sys.stdout.write('1\\n2\\n3\\n')
26+
Result should equal ${result} stdout=1\n2\n3
27+
${result}= Run Process python -c import sys; sys.stdout.write('1\\n2\\r\\n3\\n') stdout=${STDOUT}
28+
Result should equal ${result} stdout=1\n2${\n}3 stdout_path=${STDOUT}
29+
${output} = Get Binary File ${STDOUT}
30+
Should Be Equal ${output} 1${\n}2\r${\n}3${\n} type=bytes
2031
[Teardown] Safe Remove File ${STDOUT}

src/robot/libraries/Process.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,10 @@ class Process:
279279
| `Should Be Equal` | ${stdout} | ${result.stdout} |
280280
| `File Should Be Empty` | ${result.stderr_path} | |
281281
282-
Notice that possible trailing newlines in captured``stdout`` and ``stderr``
283-
are removed automatically.
282+
Notice that in ``stdout`` and ``stderr`` content possible trailing newline
283+
is removed and ``\\r\\n`` converted to ``\\n`` automatically. If you
284+
need to see the original process output, redirect it to a file using
285+
`process configuration` and read it from there.
284286
285287
= Boolean arguments =
286288

0 commit comments

Comments
 (0)