Skip to content

Spying on "echo" breaks bashunit #607

@RevanProdigalKnight

Description

@RevanProdigalKnight
Q A
OS Linux (Cygwin on Windows)
Shell & version bash 5.2.21(1)-release
bashunit version 0.33.0

Summary

Spying on or mocking echo or printf causes unit tests to hang

Current behavior

Image

Didn't look until I tried using printf instead of echo but it looks like it's causing bashunit to infinitely spawn processes somewhere.

How to reproduce

function write_data_to_coproc() {
  if [ -z "$COPROC" ]; then
    return 1
  fi
  echo >&"${COPROC[0]}" "set_data: $*"
}

function test_write_data_to_coproc() {
  COPROC=(12 13)
  bashunit::spy echo

  write_data_to_coproc "hello world"
  assert_have_been_called_with echo "set_data: hello world"
}

Probable cause

Unprotected calls to echo/printf instead of using builtin echo/builtin printf

Expected behavior

Unit test completes and bashunit doesn't hang forever.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions