From ed795fc777c69400beea164e7324ecbd507588bd Mon Sep 17 00:00:00 2001 From: Niall Byrne <9848926+niall-byrne@users.noreply.github.com> Date: Fri, 8 Aug 2025 14:32:06 -0400 Subject: [PATCH 1/2] feat(LEXER): support function names containing the at sign --- .tool-versions | 1 + lib/bashcov/lexer.rb | 2 +- spec/support/test_app.rb | 2 +- spec/test_app/scripts/function.sh | 4 ++-- 4 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 .tool-versions diff --git a/.tool-versions b/.tool-versions new file mode 100644 index 0000000..f2a971a --- /dev/null +++ b/.tool-versions @@ -0,0 +1 @@ +ruby 3.2.2 diff --git a/lib/bashcov/lexer.rb b/lib/bashcov/lexer.rb index c406a54..9f4025e 100644 --- a/lib/bashcov/lexer.rb +++ b/lib/bashcov/lexer.rb @@ -104,7 +104,7 @@ def relevant?(line) line.start_with?(*IGNORE_START_WITH) || line.end_with?(*IGNORE_END_WITH) - return false if line =~ /\A[a-zA-Z_][a-zA-Z0-9_\-:\.]*\(\)/ # function declared without the `function` keyword + return false if line =~ /\A[a-zA-Z_@][a-zA-Z0-9_@\-:\.]*\(\)/ # function declared without the `function` keyword return false if line =~ /\A[^)]+\)\Z/ # case statement selector, e.g. `--help)` true diff --git a/spec/support/test_app.rb b/spec/support/test_app.rb index 191c4ca..7ae11c3 100644 --- a/spec/support/test_app.rb +++ b/spec/support/test_app.rb @@ -20,7 +20,7 @@ def expected_coverage "#{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/comments.sh" => [nil, nil, 1, nil, 1, nil, nil, nil, 1, nil, 1], "#{test_app}/scripts/delete.sh" => [nil, nil, 1, 1, 1, 1, nil, 1, 1], - "#{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], + "#{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, 0, nil, nil, 1, 1, 1, 1], "#{test_app}/scripts/long_line.sh" => [nil, nil, 1, 1, 1, 0], "#{test_app}/scripts/nested/simple.sh" => [nil, nil, nil, nil, 1, 1, nil, 0, nil, nil, 1], "#{test_app}/scripts/new\nline.sh" => [nil, nil, 1, nil, 2], diff --git a/spec/test_app/scripts/function.sh b/spec/test_app/scripts/function.sh index bed4701..86cecb8 100755 --- a/spec/test_app/scripts/function.sh +++ b/spec/test_app/scripts/function.sh @@ -18,11 +18,11 @@ put-team-key() { echo put-team-key # 0 } -abc::def.fn() { +abc::def.@fn() { echo "${FUNCNAME[0]}" # 1 } f1 # 1 f2 # 1 __a-bc # 1 -abc::def.fn # 1 +abc::def.@fn # 1 From 0bcb0ed9e1067028b9043932b381c657158c9e4e Mon Sep 17 00:00:00 2001 From: Niall Byrne <9848926+niall-byrne@users.noreply.github.com> Date: Fri, 8 Aug 2025 18:13:30 -0400 Subject: [PATCH 2/2] feat(LEXER): support multiline subshells --- lib/bashcov/lexer.rb | 2 +- spec/support/test_app.rb | 2 +- spec/test_app/scripts/multiline.sh | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/bashcov/lexer.rb b/lib/bashcov/lexer.rb index 9f4025e..f4f0536 100644 --- a/lib/bashcov/lexer.rb +++ b/lib/bashcov/lexer.rb @@ -13,7 +13,7 @@ class Lexer IGNORE_END_WITH = %w[(].freeze # Lines containing only one of these keywords are irrelevant for coverage - IGNORE_IS = %w[esac if then else elif fi while do done { } ;;].freeze + IGNORE_IS = %w[esac if then else elif fi while do done { } ;; ( )].freeze # @param [String] filename File to analyze # @param [Hash] coverage Coverage with executed lines marked diff --git a/spec/support/test_app.rb b/spec/support/test_app.rb index 7ae11c3..d6a474b 100644 --- a/spec/support/test_app.rb +++ b/spec/support/test_app.rb @@ -31,7 +31,7 @@ def expected_coverage "#{test_app}/scripts/source.sh" => [nil, nil, 1, nil, 2], "#{test_app}/scripts/sourced.txt" => [nil, nil, 1], "#{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/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, 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, nil, nil, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, nil, nil, 1], "#{test_app}/scripts/multiline3.sh" => [nil, nil, 1, 1, 1, 1], "#{test_app}/scripts/multiline4.sh" => [nil, nil, 1, 1], diff --git a/spec/test_app/scripts/multiline.sh b/spec/test_app/scripts/multiline.sh index 8a18696..87e9a6a 100755 --- a/spec/test_app/scripts/multiline.sh +++ b/spec/test_app/scripts/multiline.sh @@ -38,4 +38,6 @@ hello there ' # nil -echo the end # 1 +( # nil + echo the end # 1 +) # nil