Skip to content

read fails to stub, halts test runner #23

@SeanDez

Description

@SeanDez

When I attempt to run a test with a stub, the test runner gets stuck without throwing an error. It must be exited with CTRL + C

$ find -type f | entr ./node_modules/bats/bin/bats -r ./helpers/tests
 ✓ a/b matcher to ensure the asserts are working
 ✓ createConfigFile
 ✓ toLowercase
   gatherConfigOptions                    4/4

I need to stub read to allow automated testing to work. But this code is causing the halt:

# tests.bats
load "batsMock/stub" # saved via git submodule into this folder

@test "gatherConfigOptions" {
   # setup
   stub read \
      "echo 'returnValue1'" \
      "echo 'returnValue2'"

   # test execution & assert
   local options=$(gatherConfigOptions)
   assert_equal $options "wrongValue"

   # teardown
   unstub read
}

Also tried

  • Commenting out the unstub statement. No effect

I suspect that read is running unstubbed and causing the infinite delay. I could be wrong though.

Anyone able to tell what the issue is and how to overcome it?

Here is the function I am attempting to stub the internals of:

# ./helpers/helpers.sh

function gatherConfigOptions {
   declare -A configData

   read -p "prompt text here" "configData[languageCode]"
   read -p "prompt text here" "configData[numberOfRepeats]"

   echo "${configData[*]}"
}

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