Skip to content

Funky behavior on the assertion count #50

@khru

Description

@khru
Q A
OS MacOS / Linux / Windows
Shell sh / bash / ...
bashunit version x.y.z

Summary

Adding a new creation I did not add the assertion counter, but the counter had already been counted for

Peek 2023-09-11 00-25

Current behavior

adding a test like:

function assertExitCode() {
  local actual_exit_code=$?
  local expected_exit_code="$1"
  local label="${3:-$(normalizeFunctionName "${FUNCNAME[1]}")}"
  if [ $actual_exit_code -eq "$expected_exit_code" ]; then
    return 0
  else
    ((_ASSERTIONS_FAILED++))
    printFailedTest  "${label}" "${actual_exit_code}" "to not match" "${expected_exit_code}"
    return 1
  fi
}

Without incrementing the $_ASSERTIONS_PASSED somehow it's counting it

How to reproduce

Create a new assertion like:

function assertExitCode() {
  local actual_exit_code=$?
  local expected_exit_code="$1"
  local label="${3:-$(normalizeFunctionName "${FUNCNAME[1]}")}"
  if [ $actual_exit_code -eq "$expected_exit_code" ]; then
    #((_ASSERTIONS_PASSED++))
    return 0
  else
    ((_ASSERTIONS_FAILED++))
    printFailedTest  "${label}" "${actual_exit_code}" "to not match" "${expected_exit_code}"
    return 1
  fi
}

Run the test and look at the number of assertions, uncomment the #((_ASSERTIONS_PASSED++)) and run it again and you will see that the number does not change

Expected behavior

It should not count assertions that are not accounted for

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions