chruby icon indicating copy to clipboard operation
chruby copied to clipboard

Fix Issue #367: Value of $_ overwritten in bash

Open HaleTom opened this issue 9 years ago • 11 comments

Fix Issue #367 based on this answer

HaleTom avatar Dec 03 '16 08:12 HaleTom

I don't think how we hook in chruby_auto works within the unit-test functions. I had to explicitly invoke chruby_auto to simulate it running after other commands.

postmodern avatar Dec 04 '16 03:12 postmodern

@postmodern how should I deal with that in this PR?

HaleTom avatar Dec 07 '16 23:12 HaleTom

@postmodern Merry Festivus. Where to from here?

HaleTom avatar Dec 20 '16 22:12 HaleTom

@HaleTom so trap '...' DEBUG does not capture commands invoked from inside of functions, only at the top level. This means chruby_auto is automatically invoked in your unit-test. We need to device a test that actually exercises this somehow.

#!/bin/sh

trap 'echo "Command: $BASH_COMMAND"' DEBUG

func() {
	echo 'inside of a function'
}

echo 'outside of a function'
func

postmodern avatar Dec 23 '16 09:12 postmodern

set -o functrace is what you're after.

Adding this, the output is:

Command: echo 'outside of a function'
outside of a function
Command: func
Command: func
Command: echo 'inside of a function'
inside of a function

I'm not sure why Command: func is duplicated... let me know if it's an issue. This may help.

I'm having a brain-fart: how do I run the tests again? (I couldn't see anything in CONTRIBUTING about it).

Let me know if I can help out with anything from here.

HaleTom avatar Feb 07 '17 12:02 HaleTom

@postmodern Here is the code you want:

#!/bin/bash
set +o functrace
trap 'trap_func' DEBUG

trap_func() {
  [[ $BASH_COMMAND != "${FUNCNAME:0}" ]] && echo "Command: $BASH_COMMAND"
}

func() {
  echo 'inside of a function'
}

echo 'outside of a function'
func

Please let me know what the next step is.

HaleTom avatar May 19 '17 03:05 HaleTom

@postmodern, @steakknife, Any blockers to merge this?

HaleTom avatar Oct 27 '17 10:10 HaleTom

Just checking in on this as it's been one human gestation since the last comment.

What is the next step here? @postmodern @steakknife

HaleTom avatar Jul 20 '18 14:07 HaleTom

I see that Travis on Apple didn't seem to run correctly - it has null output.

Is this expected? Any other blockers to merging?

HaleTom avatar Aug 25 '21 08:08 HaleTom

@HaleTom Apple (still) ships with Bash 3, so unfortunately all code has to be Bash 3 compatible. I have since switched to GitHub Actions, however I still need to fix how the test suite downloads/installs the macOS test ruby, which must be compatible with GitHub Action version of macOS.

postmodern avatar Aug 25 '21 09:08 postmodern