You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I tried to use gexpect to test a CLI app and encountered an issue regarding expected and actual line endings (i.e. 0xa/0xd). On echo 'test\n' I was expecting to get test\n, but unfortunately I get test\r as a return value of the readLine function. If my target app outputs multiline go string with \n as a line separator, I simply can't use the same string as a test expectation since the concatenated result of the reading of all the lines will be separated with \rs.
Got some time to investigate this issue and discovered that in my terminal (MacOS Sierra 10.12.3, iTerm 2, Build 3.0.14 with zsh 5.3) I have such a behaviour:
So since any \n produces actual \r\n ReadUntil looks for one byte only and in a situation when I "echo 'test\n'" it matches the first char '\r' in a pair \r\n and leaves \n. Than's how I got this case:
So I suppose without changing ReadUntil's signature from one byte argument as a delimiter to an array of strings we couldn't actually match different CRs for different systems. Therefore I quickly patched it a little bit in my fork here: smileart@d09013d and it seems to work well.
Would be great to hear from you. Would you recon accepting it as a pull request? What about backward compatibility for ReadUntil function? Should I refactor those nested IFs and FORs into separate helper functions? Etc. Cheers! ✌️
Hey there! 👋
I tried to use
gexpect
to test a CLI app and encountered an issue regarding expected and actual line endings (i.e.0xa
/0xd
). Onecho 'test\n'
I was expecting to gettest\n
, but unfortunately I gettest\r
as a return value of thereadLine
function. If my target app outputs multiline go string with\n
as a line separator, I simply can't use the same string as a test expectation since the concatenated result of the reading of all the lines will be separated with\r
s.Here is a minimal code sample to reproduce:
On my machine (MacOS Sierra 10.12.2, zsh 5.3, go 1.7.4 darwin/amd64) it results in:
If I change the test string in above code to
test\r
the result will be:The text was updated successfully, but these errors were encountered: