SimonKagstrom / kcov

Code coverage tool for compiled programs, Python and Bash which uses debugging information to collect and report data without special compilation options
http://simonkagstrom.github.io/kcov/
GNU General Public License v2.0
720 stars 110 forks source link

Handle the bash version properly to support non-English and bash 5.0 #291

Closed ko1nksm closed 5 years ago

ko1nksm commented 5 years ago

(I tested on Ubuntu 18.04, bash 4.4.19 and Ubuntu 19.04, bash 5.0.3)

First, I noticed that the BASH_XTRACEFD revert to 2 when LANG=ja_JP.UTF-8.

# xtracedfd.sh
echo $BASH_XTRACEFD > /dev/tty
$ LANG=C kcov /tmp/out/ xtracedfd.sh
782

$ LANG=C bash --version
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ LANG=ja_JP.UTF-8 kcov /tmp/out/ xtracedfd.sh
2

$ LANG=ja_JP.UTF-8 bash --version
GNU bash, バージョン 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
ライセンス GPLv3+: GNU GPL バージョン 3 またはそれ以降 <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

When LANG=ja_JP.UTF-8, bash --version was translated into Japanese, and the string of version is not displayed.

bashCanHandleXtraceFd() function find for the string version, so version can not be detected. https://github.com/SimonKagstrom/kcov/blob/af13dcc42d12bd78599cd53dced6ebacaa7626dc/src/engines/bash-engine.cc#L460-L501

Second, I noticed that this code can not handle bash version 5.0. (e.g. 5.0.3(1)-release) https://github.com/SimonKagstrom/kcov/blob/af13dcc42d12bd78599cd53dced6ebacaa7626dc/src/engines/bash-engine.cc#L492-L495

I currently use kcov --bash-method=DEBUG as workaround for this problem.

This pull request handle the bash version properly to support non-English and bash 5.0.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.003%) to 70.174% when pulling b1329bc9222e2a329b7c86ae657ef453ffcd70aa on ko1nksm:fix-bash-version-handling into af13dcc42d12bd78599cd53dced6ebacaa7626dc on SimonKagstrom:master.

SimonKagstrom commented 5 years ago

Great! Thanks a lot!