Skip to content

Commit

Permalink
xtrace: Use readlink to get absolute path.
Browse files Browse the repository at this point in the history
BASH_SOURCE isn't always guaranteed to give an absolute path, so
use readlink to ensure that we get the absolute path to the source
file.
  • Loading branch information
smspillaz committed Mar 24, 2015
1 parent 55a8a91 commit 4427eb2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/bashcov/xtrace.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'mkmf'

module Bashcov
# This class manages +xtrace+ output.
#
Expand All @@ -13,7 +15,10 @@ class Xtrace
# @see http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
# @note We use a forward slash as delimiter since it's the only forbidden
# character in filenames on Unix and Windows.
PS4 = %Q{#{PREFIX}${BASH_SOURCE[0]}/${LINENO}: }
_READLINK = find_executable('readlink')
_GREADLINK = find_executable('greadlink')
READLINK = _GREADLINK.nil? ? _READLINK : _GREADLINK
PS4 = %Q{#{PREFIX}$(#{READLINK} -f ${BASH_SOURCE[0]})/${LINENO}: }

# Regexp to match xtrace elements.
LINE_REGEXP = /\A#{Regexp.escape(PREFIX[0])}+#{PREFIX[1..-1]}(?<filename>.+)\/(?<lineno>\d+): /
Expand Down

0 comments on commit 4427eb2

Please sign in to comment.