Skip to content

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

Open
@JussiPekonen

Description

@JussiPekonen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions