From 4427eb2940e2d3f8e5397a3e6b81fd1795d66799 Mon Sep 17 00:00:00 2001 From: Sam Spilsbury Date: Tue, 24 Mar 2015 12:08:58 +0800 Subject: [PATCH] xtrace: Use readlink to get absolute path. 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. --- lib/bashcov/xtrace.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/bashcov/xtrace.rb b/lib/bashcov/xtrace.rb index e4709df..801827d 100644 --- a/lib/bashcov/xtrace.rb +++ b/lib/bashcov/xtrace.rb @@ -1,3 +1,5 @@ +require 'mkmf' + module Bashcov # This class manages +xtrace+ output. # @@ -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]}(?.+)\/(?\d+): /