bashunit icon indicating copy to clipboard operation
bashunit copied to clipboard

Add third optional parameter on asserts

Open khru opened this issue 2 years ago • 5 comments

Add 3º parameter optional that will override the error message Ex.: phpunit

khru avatar Sep 13 '23 18:09 khru

This is already for assertEquals. Or on which functions do you mean?

Chemaclass avatar Sep 13 '23 19:09 Chemaclass

@Chemaclass In fact, this functionality was implemented at the beginning but the other way around. What it did was allow you to customize the success message of the assert and not the failure one. When we changed so that success messages were for the tests and not for the asserts, it was lost.

antonio-gg-dev avatar Sep 14 '23 09:09 antonio-gg-dev

I also wanted this, and went to look at what it would take to implement it.

Isn't it mostly done? Nearly all the assert_* functions use constructs like

function assert_equals() {
...
  local label="${3:-$(helper::normalize_test_function_name "${FUNCNAME[1]}")}"
...
    console_results::print_failed_test "${label}" "${expected}" "but got" "${actual}"

so, for example, passing a third argument to assert_equals prints that when the assertion fails.

As far as I can tell, only the array and snapshot assertions are missing it.

apotterri avatar Jan 14 '24 11:01 apotterri

Yes and no @apotterri , what is implemented right now changes the name of the test when it fails, what should be modified is the reason for the error.

So, in reality, even though all the assertions have 'something similar to what we want', it is actually not working at all as we want.

antonio-gg-dev avatar Jan 15 '24 15:01 antonio-gg-dev

Ah, ok, I see. Thanks.

apotterri avatar Jan 15 '24 18:01 apotterri