shunit2 icon indicating copy to clipboard operation
shunit2 copied to clipboard

Warning "can only `return' from a function or sourced script" when executing in standalone mode (in Bash shell)

Open JussiPekonen opened this issue 2 years ago • 1 comments

Description

When shunit2 is executed in standalone mode (in Bash shell) and there are failing test cases, there will be a warning message "can only `return' from a function or sourced script" printed out to the shell after the execution.

Steps to reproduce

  1. Test file
#!/bin/bash

testFailure() {
  assertEquals "${SHUNIT_TRUE}" "${SHUNIT_FALSE}"
}
  1. Use the latest version from the master branch
  2. Run the test in standalone mode, ./shunit2 <file>

Expected result

The command will exit with a non-zero exit code and the test report contains only details of the tests and where they failed.

Actual result

The report printout contains an unnecessary warning "can only `return' from a function or sourced script" in addition to the test results.

Notes

There is no issue when the test file (given above) sources the shunit2 file. Therefore, this issue affects only the standalone mode.

JussiPekonen avatar Jun 27 '22 20:06 JussiPekonen

Fix available in #159.

JussiPekonen avatar Jun 27 '22 20:06 JussiPekonen