kward / shunit2

shUnit2 is a xUnit based unit test framework for Bourne based shell scripts.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

assertEquals failing with equal input

eedwards-sk opened this issue · comments

Added spacing to the variable list to show that it's identical.

assertEquals appears to be broken for this use case

shunit_expected_='2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world'
shunit_actual_=  '2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world'
+++ shunit_expected_='2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world'
+++ shunit_actual_='2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world'
+++ _shunit_assertFail 'expected:<2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world> but was:<2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world>'
+++ __shunit_testSuccess=1
++++ expr 0 + 1
+++ __shunit_assertsFailed=1
++++ expr 0 + 1
+++ __shunit_assertsTotal=1
+++ '[' 1 -gt 0 ']'
+++ echo -e '\033[1;31mASSERT:\033[0mexpected:<2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world> but was:<2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world>'
ASSERT:expected:<2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world> but was:<2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world>

More from the stacktrace:

+++ '[' '2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world' = '2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world' ']'
+++ failNotEquals '' '2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world' '2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world'

Something is really wonky... if I do the same comparison straight up in the shell I get a matched result.

if [ '2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world' = '2018-02-06T21:51:47Z | INFO | log_prefix_test.sh | test_example | hello world' ]; then
  echo "match"
else
  echo "not match"
fi
→ ./scratch.sh 
match

Okay, I think I may have solved it.

There's some color metadata getting added in my log function which the stack trace isn't surfacing at this point.