2

Using perl 5.16 with the latest Test::More module.

I got a unit test being called like

is($ret, "ssh: connect to host 1.2.3.187 port 22: Network is unreachable\nCouldn't read packet: Connection reset by peer\n", "putFileWithSFTP bad server ret test");

Running the test fails with the following result:
#   Failed test 'putFileWithSFTP bad server ret test'
#   at t/Backup.t line 891.
#          got: 'ssh: connect to host 1.2.3.187 port 22: Network is unreachable
# Couldn't read packet: Connection reset by peer
# '
#     expected: 'ssh: connect to host 1.2.3.187 port 22: Network is unreachable
# Couldn't read packet: Connection reset by peer
# '

The strings should be equal and they also look like they are equal. What could be the cause of this?

noah
  • 312
  • 2
  • 13
  • MSWin line ends or some other invisible characters? Try running the strings through `join " ", map ord, split //, $string` or something similar. – choroba Oct 17 '22 at 09:24
  • Was (for whatever reason) MSWin line endings. Found it when comparing the hexdump. Writing an answer right now. – noah Oct 17 '22 at 09:31

1 Answers1

2

I figured it out:

When comparing the two strings with a hexdump, I noticed that, for whatever reason, the ssh ouput in $ret contains MSWin Line Endings, which I didn't include in my comparison.

More can be read here

noah
  • 312
  • 2
  • 13