Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion lib/bashcov/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,17 @@ def initialize(filename, coverage)

# Process and complete initial coverage.
# @return [void]
def complete_coverage
def complete_coverage # rubocop:disable Metrics/MethodLength
lines = IO.read(@filename).encode("utf-8", invalid: :replace).lines

lines.each_with_index do |line, lineno|
# multi-line arrays
mark_multiline(
lines, lineno,
/\A[^\n]*\b=\([^()]*\)/,
forward: false
)

# heredoc
mark_multiline(
lines, lineno,
Expand All @@ -43,6 +50,12 @@ def complete_coverage
/\A[^\n]+\\$(\s*['"][^'"]*['"]\s*\\$){1,}\s*['"][^'"]*['"]\s*$/
)

# simple line continuations with backslashes
mark_multiline(
lines, lineno,
/\A([^\n&|;]*[^\\&|;](\\\\)*\\\n)+[^\n&|;]*[^\n\\&|;](\\\\)*$/
)

# multiline string concatenated with newlines
%w[' "].each do |char|
mark_multiline(
Expand Down
2 changes: 2 additions & 0 deletions spec/support/test_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def uncovered_files
def expected_coverage # rubocop:disable Metrics/MethodLength
{
"#{test_app}/never_called.sh" => [nil, nil, 0],
"#{test_app}/scripts/array.sh" => [nil, nil, 1, 1, 1, 1, 1, 1],
"#{test_app}/scripts/case.sh" => [nil, nil, nil, 2, nil, 1, nil, nil, 0, 1, nil, nil, nil, 1, 1],
"#{test_app}/scripts/cd.sh" => [nil, nil, 1, 2, nil, 3, 1, 3, nil, 2, nil, nil, 1, nil, 3, nil, 6, nil, 1, nil, 1],
"#{test_app}/scripts/delete.sh" => [nil, nil, 1, 1, 1, 1, nil, 1, 1],
Expand All @@ -31,6 +32,7 @@ def expected_coverage # rubocop:disable Metrics/MethodLength
"#{test_app}/scripts/unicode.sh" => [nil, nil, nil, 1, nil, 1],
"#{test_app}/scripts/multiline.sh" => [nil, nil, nil, 1, nil, 0, nil, 1, nil, 1, nil, 0, nil, nil, 1, 2, 1, 1, 0, nil, nil, 2, nil, nil, 1, 1, 1, 1, nil, 1, 1, 1, 1, 1, nil, 1, 1, 1, 1, nil, 1],
"#{test_app}/scripts/multiline2.sh" => [nil, nil, 1, 1, 1, 1, nil, 1, 1, 1, 1, nil, 1, 1, 1, 1, 1, 1, nil, 1, 1, 1, 1, 1, 1, 1, 1, nil, 1, 1, 1, nil, 1],
"#{test_app}/scripts/multiline3.sh" => [nil, nil, 1, 1, 1, 1],
"#{test_app}/scripts/executable" => [nil, nil, 1],
"#{test_app}/scripts/exit_non_zero.sh" => [nil, nil, 1],
"#{test_app}/scripts/no_shebang.sh" => [nil, nil, nil, nil, 0],
Expand Down
8 changes: 8 additions & 0 deletions spec/test_app/scripts/array.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

arr=(
foo
bar
baz
quux
)
6 changes: 6 additions & 0 deletions spec/test_app/scripts/multiline3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

echo 1 \
2 \
3 \
4