Skip to content

Commit ec87c93

Browse files
committed
Add support for function name containing dashes
This is not POSIX compliant but most shells do support it. https://unix.stackexchange.com/questions/482417/will-it-be-bad-that-a-function-or-script-name-contains-dash-instead-of-under [Fixes #93]
1 parent e805f57 commit ec87c93

3 files changed

Lines changed: 9 additions & 5 deletions

File tree

lib/bashcov/lexer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def relevant?(line)
106106
line.start_with?(*IGNORE_START_WITH) ||
107107
line.end_with?(*IGNORE_END_WITH)
108108

109-
relevant &= false if line =~ /\A[a-zA-Z_][a-zA-Z0-9_:]*\(\)/ # function declared without the `function` keyword
109+
relevant &= false if line =~ /\A[a-zA-Z_][a-zA-Z0-9_\-:]*\(\)/ # function declared without the `function` keyword
110110
relevant &= false if line =~ /\A[^)]+\)\Z/ # case statement selector, e.g. `--help)`
111111

112112
relevant

spec/support/test_app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def expected_coverage
2020
"#{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],
2121
"#{test_app}/scripts/comments.sh" => [nil, nil, 1, nil, 1, nil, nil, nil, 1, nil, 1],
2222
"#{test_app}/scripts/delete.sh" => [nil, nil, 1, 1, 1, 1, nil, 1, 1],
23-
"#{test_app}/scripts/function.sh" => [nil, nil, nil, 2, nil, nil, nil, 1, 1, nil, nil, nil, nil, 1, nil, nil, nil, 1, nil, nil, 1, 1, 1, 1],
23+
"#{test_app}/scripts/function.sh" => [nil, nil, nil, 2, nil, nil, nil, 1, 1, nil, nil, nil, nil, 1, nil, nil, nil, 0, nil, nil, nil, 1, nil, nil, 1, 1, 1, 1],
2424
"#{test_app}/scripts/long_line.sh" => [nil, nil, 1, 1, 1, 0],
2525
"#{test_app}/scripts/nested/simple.sh" => [nil, nil, nil, nil, 1, 1, nil, 0, nil, nil, 1],
2626
"#{test_app}/scripts/new\nline.sh" => [nil, nil, 1, nil, 2],

spec/test_app/scripts/function.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ f2() {
99
echo f2 # 1
1010
}
1111

12-
__a_bc()
12+
__a-bc()
1313
{
14-
echo __a_bc # 1
14+
echo __a-bc # 1
15+
}
16+
17+
put-team-key() {
18+
echo put-team-key # 0
1519
}
1620

1721
abc::def() {
@@ -20,5 +24,5 @@ abc::def() {
2024

2125
f1 # 1
2226
f2 # 1
23-
__a_bc # 1
27+
__a-bc # 1
2428
abc::def # 1

0 commit comments

Comments
 (0)