Skip to content

Commit

Permalink
Fix bug where trap_remove would only remove from $TRAP_APPEND_CMDS
Browse files Browse the repository at this point in the history
  • Loading branch information
andsens committed May 25, 2024
1 parent 7dff40e commit cef58d8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions trap.bats
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,13 @@ last command'
kill -s USR2 \$BASHPID
")" $'should run first\nshould run second\nshould run third\nshould run last'
}

@test 'trap_remove removes from the right array' {
assert_equal "$(bash -ec "source $BATS_TEST_DIRNAME/trap.sh
trap_append \"echo 'should not run'\" USR2
trap_remove \$TRAP_POINTER
trap_prepend \"echo 'should not run'\" USR2
trap_remove \$TRAP_POINTER
kill -s USR2 \$BASHPID
")" ''
}
3 changes: 2 additions & 1 deletion trap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ trap_remove() {
local pointer=$1
if [[ $pointer = a* ]]; then
pointer=${pointer#a}
unset "TRAP_APPEND_CMDS[pointer]"
else
pointer=${pointer#p}
unset "TRAP_PREPEND_CMDS[pointer]"
fi
unset "TRAP_APPEND_CMDS[pointer]"
}

0 comments on commit cef58d8

Please sign in to comment.