Skip to content

PS4 has a 100 character limit, causing shcov to fail with deep directories #6

@GoogleCodeExporter

Description

@GoogleCodeExporter
I realize that this is really a bash issue, but it showed up when we were 
trying to use shcov, so I'm hoping someone here has a solution.

What steps will reproduce the problem?
1. mkdir -p 
/tmp/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/subdir9
2. cd 
/tmp/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/subdir9
3. echo "echo Hi" > test2.sh ; chmod +x test2.sh
4. shcov ${PWD}/test2.sh

What is the expected output? 
"Hi"

What do you see instead?
Hi
Traceback (most recent call last):
  File "/ascldap/users/mhamilt/shcov-5/scripts/shcov", line 177, in <module>
    out = sc.parse_output()
  File "/ascldap/users/mhamilt/shcov-5/scripts/shcov", line 118, in parse_output
    self.handle_line(line)
  File "/ascldap/users/mhamilt/shcov-5/scripts/shcov", line 77, in handle_line
    file.add_to_line(line_nr)
  File "/home/mhamilt/shcov-5/shcov/file.py", line 103, in add_to_line
    line_nr = int(line_nr)
ValueError: invalid literal for int() with base 10: '1::echo Hi\n'


What version of the product are you using? On what operating system?
shcov-5 on an RHEL6 machine with Python 2.7.4

Please provide any additional information below.

Taking shcov out of the equation we can demonstrate that bash shortens the 
results of the expansion of PS4 to 100 characters:

% export PS4='SHCOV:::${BASH_SOURCE}:::${LINENO}::: SHCOV:'
% bash -x ${PWD}/test2.sh
SHCOV:::/tmp/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/sub
dir9/test2.sh:::1::echo Hi
Hi
%

Counting characters to the 'echo Hi' at the end gives 100.

If I add 'print line' to shcov at line 51 I get this:

SHCOV:::/tmp/subdir1/subdir2/subdir3/subdir4/subdir5/subdir6/subdir7/subdir8/sub
dir9/test2.sh:::1::echo Hi

and since the parser is using ':::' as the separator the last field ends up 
with '1::echo Hi', instead of '1'. (Clearly it gets worse the deeper the 
hierarchy becomes.)

We can't really flatten out our hierarchy, so I'm unsure of how this might be 
corrected.

Mark E. Hamilton





Original issue reported on code.google.com by hami...@comcast.net on 4 Feb 2014 at 9:27

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions