From 24b355c51b40ad0ec8eab2af00e17de88c838380 Mon Sep 17 00:00:00 2001 From: IlnurHA <53339563+IlnurHA@users.noreply.github.com> Date: Tue, 5 Mar 2024 03:15:39 +0300 Subject: [PATCH 01/15] Hits of code metric --- metrics/hoc.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 metrics/hoc.py diff --git a/metrics/hoc.py b/metrics/hoc.py new file mode 100644 index 00000000..fb63c2d1 --- /dev/null +++ b/metrics/hoc.py @@ -0,0 +1,45 @@ +import pathlib +import sys + +import javalang.tree +from javalang import parse +import subprocess + + +def hoc(file_path: str, class_name: str) -> int | None: + path = pathlib.Path(file_path).name + dir_path = pathlib.Path(file_path).parent + command = (f'cd {dir_path} && git log -L:"\\sclass\\s{class_name}:{path}"' + ' -s | grep -o -E "commit\\s\\S{40}" | wc -l') + result = subprocess.run(command, text=True, shell=True, capture_output=True) + + # Expect error in case of inner class + if result.stderr: + return None + + return int(result.stdout) + + +if __name__ == '__main__': + JAVA = sys.argv[1] + METRICS = sys.argv[2] + + with open(JAVA, encoding='utf-8', errors='ignore') as f: + try: + to_return_hoc = {} + ast_var = parse.parse(f.read()) + for _, node in ast_var.filter(javalang.tree.ClassDeclaration): + + node_class_name = node.name + + if node_class_name not in to_return_hoc: + hoc_number = hoc(JAVA, node_class_name) + if hoc_number: + to_return_hoc[node_class_name] = hoc_number + + with open(METRICS, 'a', encoding='utf-8') as m: + for class_name in to_return_hoc: + m.write(f'hoc {class_name}:{to_return_hoc.get(class_name)} Hits Of Code for given class\n') + except FileNotFoundError as exception: + message = f"{type(exception).__name__} {str(exception)}: {JAVA}" + sys.exit(message) From 2b2124efd1e69664bc16a0fb5953284c3d5b8c19 Mon Sep 17 00:00:00 2001 From: IlnurHA <53339563+IlnurHA@users.noreply.github.com> Date: Tue, 5 Mar 2024 03:23:41 +0300 Subject: [PATCH 02/15] Update hoc.py Fix regex to find necessary class --- metrics/hoc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/hoc.py b/metrics/hoc.py index fb63c2d1..0fbd8bbc 100644 --- a/metrics/hoc.py +++ b/metrics/hoc.py @@ -9,7 +9,7 @@ def hoc(file_path: str, class_name: str) -> int | None: path = pathlib.Path(file_path).name dir_path = pathlib.Path(file_path).parent - command = (f'cd {dir_path} && git log -L:"\\sclass\\s{class_name}:{path}"' + command = (f'cd {dir_path} && git log -L:"class\\s{class_name}:{path}"' ' -s | grep -o -E "commit\\s\\S{40}" | wc -l') result = subprocess.run(command, text=True, shell=True, capture_output=True) From e7b25a00fe6dc265e51ed3cb323b39a9d89eac63 Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Tue, 5 Mar 2024 17:06:18 +0300 Subject: [PATCH 03/15] Shell script instead of python file --- metrics/hoc.py | 45 --------------------------------------------- metrics/hoc.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 45 deletions(-) delete mode 100644 metrics/hoc.py create mode 100644 metrics/hoc.sh diff --git a/metrics/hoc.py b/metrics/hoc.py deleted file mode 100644 index fb63c2d1..00000000 --- a/metrics/hoc.py +++ /dev/null @@ -1,45 +0,0 @@ -import pathlib -import sys - -import javalang.tree -from javalang import parse -import subprocess - - -def hoc(file_path: str, class_name: str) -> int | None: - path = pathlib.Path(file_path).name - dir_path = pathlib.Path(file_path).parent - command = (f'cd {dir_path} && git log -L:"\\sclass\\s{class_name}:{path}"' - ' -s | grep -o -E "commit\\s\\S{40}" | wc -l') - result = subprocess.run(command, text=True, shell=True, capture_output=True) - - # Expect error in case of inner class - if result.stderr: - return None - - return int(result.stdout) - - -if __name__ == '__main__': - JAVA = sys.argv[1] - METRICS = sys.argv[2] - - with open(JAVA, encoding='utf-8', errors='ignore') as f: - try: - to_return_hoc = {} - ast_var = parse.parse(f.read()) - for _, node in ast_var.filter(javalang.tree.ClassDeclaration): - - node_class_name = node.name - - if node_class_name not in to_return_hoc: - hoc_number = hoc(JAVA, node_class_name) - if hoc_number: - to_return_hoc[node_class_name] = hoc_number - - with open(METRICS, 'a', encoding='utf-8') as m: - for class_name in to_return_hoc: - m.write(f'hoc {class_name}:{to_return_hoc.get(class_name)} Hits Of Code for given class\n') - except FileNotFoundError as exception: - message = f"{type(exception).__name__} {str(exception)}: {JAVA}" - sys.exit(message) diff --git a/metrics/hoc.sh b/metrics/hoc.sh new file mode 100644 index 00000000..785e3327 --- /dev/null +++ b/metrics/hoc.sh @@ -0,0 +1,41 @@ + +#!/usr/bin/env bash +# The MIT License (MIT) +# +# Copyright (c) 2021-2024 Yegor Bugayenko +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +set -e +set -o pipefail + +java=$1 +output=$(realpath "$2") +class_name=$3 + +cd "$(dirname "${java}")" +base=$(basename "${java}") + +# To check that file was added in commit any time +if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; then + hoc=$(git log -L:"class\\s${class_name}:${java}" -s | grep -o -E "commit\\s\\S{40}" | wc -l) +else + hoc=0 +fi + +echo "hoc ${class_name}:${hoc} Hits Of Code for given class" > "${output}" From ccfcfc08a050554a372187233d3a70552df1c843 Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Tue, 5 Mar 2024 17:55:28 +0300 Subject: [PATCH 04/15] Test for hoc.sh --- metrics/hoc.sh | 1 - tests/metrics/test-hoc.sh | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) mode change 100644 => 100755 metrics/hoc.sh create mode 100644 tests/metrics/test-hoc.sh diff --git a/metrics/hoc.sh b/metrics/hoc.sh old mode 100644 new mode 100755 index 785e3327..652ee101 --- a/metrics/hoc.sh +++ b/metrics/hoc.sh @@ -22,7 +22,6 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. set -e -set -o pipefail java=$1 output=$(realpath "$2") diff --git a/tests/metrics/test-hoc.sh b/tests/metrics/test-hoc.sh new file mode 100644 index 00000000..159a528c --- /dev/null +++ b/tests/metrics/test-hoc.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash +# The MIT License (MIT) +# +# Copyright (c) 2021-2024 Yegor Bugayenko +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +set -e + +temp=$1 +stdout=$2 +current_dir="${PWD}" + +{ + cd "${temp}" + + git init --quiet . + git config user.email 'foo@example.com' + git config user.name 'Foo' + + java="${temp}/foo/dir/FooTest.java" + + mkdir -p "$(dirname "${java}")" + echo "class Foo {}" > "${java}" + touch "${temp}/stdout" + + git add "${java}" + git config commit.gpgsign false + git commit --quiet -m "first commit" + + "${current_dir}/metrics/hoc.sh" "${java}" "${temp}/stdout" "Foo" + grep "hoc Foo:1" "${temp}/stdout" +} > "${stdout}" 2>&1 +echo "👍🏻 Correctly calculated hits of code" From 26f1e3eaa251b0f67c1f78f9d525124279a61505 Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Tue, 5 Mar 2024 18:02:12 +0300 Subject: [PATCH 05/15] Fixed test and metric --- metrics/hoc.sh | 1 + tests/metrics/test-hoc.sh | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/metrics/hoc.sh b/metrics/hoc.sh index 652ee101..785e3327 100755 --- a/metrics/hoc.sh +++ b/metrics/hoc.sh @@ -22,6 +22,7 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. set -e +set -o pipefail java=$1 output=$(realpath "$2") diff --git a/tests/metrics/test-hoc.sh b/tests/metrics/test-hoc.sh index 159a528c..fd7cf3ff 100644 --- a/tests/metrics/test-hoc.sh +++ b/tests/metrics/test-hoc.sh @@ -21,10 +21,10 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. set -e +set -o pipefail temp=$1 stdout=$2 -current_dir="${PWD}" { cd "${temp}" @@ -43,7 +43,7 @@ current_dir="${PWD}" git config commit.gpgsign false git commit --quiet -m "first commit" - "${current_dir}/metrics/hoc.sh" "${java}" "${temp}/stdout" "Foo" + "${LOCAL}/metrics/hoc.sh" "${java}" "${temp}/stdout" "Foo" grep "hoc Foo:1" "${temp}/stdout" } > "${stdout}" 2>&1 echo "👍🏻 Correctly calculated hits of code" From 0cf9b3cdd391162149cd31112b35d34d4caec0f5 Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Tue, 5 Mar 2024 18:07:04 +0300 Subject: [PATCH 06/15] Rebase problem --- metrics/hoc.py | 45 --------------------------------------------- metrics/hoc.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 45 deletions(-) delete mode 100644 metrics/hoc.py create mode 100644 metrics/hoc.sh diff --git a/metrics/hoc.py b/metrics/hoc.py deleted file mode 100644 index 0fbd8bbc..00000000 --- a/metrics/hoc.py +++ /dev/null @@ -1,45 +0,0 @@ -import pathlib -import sys - -import javalang.tree -from javalang import parse -import subprocess - - -def hoc(file_path: str, class_name: str) -> int | None: - path = pathlib.Path(file_path).name - dir_path = pathlib.Path(file_path).parent - command = (f'cd {dir_path} && git log -L:"class\\s{class_name}:{path}"' - ' -s | grep -o -E "commit\\s\\S{40}" | wc -l') - result = subprocess.run(command, text=True, shell=True, capture_output=True) - - # Expect error in case of inner class - if result.stderr: - return None - - return int(result.stdout) - - -if __name__ == '__main__': - JAVA = sys.argv[1] - METRICS = sys.argv[2] - - with open(JAVA, encoding='utf-8', errors='ignore') as f: - try: - to_return_hoc = {} - ast_var = parse.parse(f.read()) - for _, node in ast_var.filter(javalang.tree.ClassDeclaration): - - node_class_name = node.name - - if node_class_name not in to_return_hoc: - hoc_number = hoc(JAVA, node_class_name) - if hoc_number: - to_return_hoc[node_class_name] = hoc_number - - with open(METRICS, 'a', encoding='utf-8') as m: - for class_name in to_return_hoc: - m.write(f'hoc {class_name}:{to_return_hoc.get(class_name)} Hits Of Code for given class\n') - except FileNotFoundError as exception: - message = f"{type(exception).__name__} {str(exception)}: {JAVA}" - sys.exit(message) diff --git a/metrics/hoc.sh b/metrics/hoc.sh new file mode 100644 index 00000000..785e3327 --- /dev/null +++ b/metrics/hoc.sh @@ -0,0 +1,41 @@ + +#!/usr/bin/env bash +# The MIT License (MIT) +# +# Copyright (c) 2021-2024 Yegor Bugayenko +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. +set -e +set -o pipefail + +java=$1 +output=$(realpath "$2") +class_name=$3 + +cd "$(dirname "${java}")" +base=$(basename "${java}") + +# To check that file was added in commit any time +if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; then + hoc=$(git log -L:"class\\s${class_name}:${java}" -s | grep -o -E "commit\\s\\S{40}" | wc -l) +else + hoc=0 +fi + +echo "hoc ${class_name}:${hoc} Hits Of Code for given class" > "${output}" From bfd5bdf3935f34ee5d18c89d79dc2e495564caaf Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Mon, 25 Mar 2024 19:29:35 +0300 Subject: [PATCH 07/15] Updated HOC --- metrics/hoc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 metrics/hoc.sh diff --git a/metrics/hoc.sh b/metrics/hoc.sh old mode 100644 new mode 100755 index e57730bc..553c94d0 --- a/metrics/hoc.sh +++ b/metrics/hoc.sh @@ -32,7 +32,7 @@ base=$(basename "${java}") # To check that file was added in commit any time if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; then - hoc=$(git log -L:"class\\s${class_name}:${java}" -s | grep -o -E "commit\\s\\S{40}" | wc -l) + hoc=$(git log -L:"class\s${class_name}:${java}" | grep -E "^[+-].*$" | grep -Ev "^\-\-\-\s\S+$" | grep -Ev "^\+\+\+\s\S+$" | wc -l) else hoc=0 fi From ad51f69b99f189ed2d27d55e43a3cb58b6b995f4 Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Mon, 25 Mar 2024 19:31:03 +0300 Subject: [PATCH 08/15] Updated tests for hoc --- tests/metrics/test-hoc.sh | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/tests/metrics/test-hoc.sh b/tests/metrics/test-hoc.sh index fd7cf3ff..10cbb2df 100644 --- a/tests/metrics/test-hoc.sh +++ b/tests/metrics/test-hoc.sh @@ -27,23 +27,42 @@ temp=$1 stdout=$2 { + hoc_script_path="/home/ilnur_ha/Documents/temp/cam/metrics/hoc.sh" cd "${temp}" + rm -rf ./* + rm -rf .git + git init --quiet . git config user.email 'foo@example.com' git config user.name 'Foo' + git config commit.gpgsign false - java="${temp}/foo/dir/FooTest.java" + java_dir="./foo/dir/" + java="FooTest.java" - mkdir -p "$(dirname "${java}")" - echo "class Foo {}" > "${java}" - touch "${temp}/stdout" + mkdir -p "${java_dir}" + cd ${java_dir} + touch "${java}" + touch "stdout" + + printf "class Foo {}" > "${java}" git add "${java}" - git config commit.gpgsign false git commit --quiet -m "first commit" + ${hoc_script_path} "${java}" "stdout" "Foo" + grep "hoc Foo:1" "stdout" - "${LOCAL}/metrics/hoc.sh" "${java}" "${temp}/stdout" "Foo" - grep "hoc Foo:1" "${temp}/stdout" + printf "class Foo {\n\tint x;\n\tbool y;\n}\n" > "${java}" + git add "${java}" + git commit --quiet -m "+second commit" + ${hoc_script_path} "${java}" "stdout" "Foo" + grep "hoc Foo:6" "stdout" + + printf "class Foo {\n\tbool z;\n}\n" > "${java}" + git add "${java}" + git commit --quiet -m "-third commit" + ${hoc_script_path} "${java}" "stdout" "Foo" + grep "hoc Foo:9" "stdout" } > "${stdout}" 2>&1 echo "👍🏻 Correctly calculated hits of code" From 4bfeb0b20c0a0590e467bba41fe18b6dc8caae77 Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Mon, 25 Mar 2024 19:41:17 +0300 Subject: [PATCH 09/15] Fix Pipeline error --- metrics/hoc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/hoc.sh b/metrics/hoc.sh index 553c94d0..558d1be7 100755 --- a/metrics/hoc.sh +++ b/metrics/hoc.sh @@ -32,7 +32,7 @@ base=$(basename "${java}") # To check that file was added in commit any time if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; then - hoc=$(git log -L:"class\s${class_name}:${java}" | grep -E "^[+-].*$" | grep -Ev "^\-\-\-\s\S+$" | grep -Ev "^\+\+\+\s\S+$" | wc -l) + hoc=$(git log -L:"class\s${class_name}:${java}" | grep -E "^[+-].*$" | grep -Ev "^\-\-\-\s\S+$" | grep -Evc "^\+\+\+\s\S+$") else hoc=0 fi From 3de484510ab024ab38cde6373556d6f5b66144d1 Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Mon, 25 Mar 2024 22:57:12 +0300 Subject: [PATCH 10/15] Fix access to be executable for make pipeline --- tests/metrics/test-hoc.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 tests/metrics/test-hoc.sh diff --git a/tests/metrics/test-hoc.sh b/tests/metrics/test-hoc.sh old mode 100644 new mode 100755 From 8e8b449f9293fe7431b46069a8fe14616568c2f6 Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Tue, 26 Mar 2024 11:16:15 +0300 Subject: [PATCH 11/15] Fixed path for script --- tests/metrics/test-hoc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/metrics/test-hoc.sh b/tests/metrics/test-hoc.sh index 10cbb2df..47fd1d6d 100755 --- a/tests/metrics/test-hoc.sh +++ b/tests/metrics/test-hoc.sh @@ -27,7 +27,7 @@ temp=$1 stdout=$2 { - hoc_script_path="/home/ilnur_ha/Documents/temp/cam/metrics/hoc.sh" + hoc_script_path="${LOCAL}/metrics/hoc.sh" cd "${temp}" rm -rf ./* From d2482bd25a64c6dfbff16b60524c29f42b0f247d Mon Sep 17 00:00:00 2001 From: IlnurHA <53339563+IlnurHA@users.noreply.github.com> Date: Tue, 26 Mar 2024 17:23:32 +0300 Subject: [PATCH 12/15] Output for hoc to be parsable --- metrics/hoc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metrics/hoc.sh b/metrics/hoc.sh index 558d1be7..49a18877 100755 --- a/metrics/hoc.sh +++ b/metrics/hoc.sh @@ -37,4 +37,4 @@ else hoc=0 fi -echo "hoc ${class_name}:${hoc} Hits Of Code for given class" > "${output}" +echo "hoc ${hoc} Hits Of Code for ${class_name} class" > "${output}" From 185b868c7bacfed5c5eca5a03d9d017ad94ad1cd Mon Sep 17 00:00:00 2001 From: IlnurHA Date: Thu, 28 Mar 2024 20:41:12 +0300 Subject: [PATCH 13/15] Fix Test for HOC and comment unused variable --- tests/metrics/test-hoc.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/metrics/test-hoc.sh b/tests/metrics/test-hoc.sh index 47fd1d6d..a81bf132 100755 --- a/tests/metrics/test-hoc.sh +++ b/tests/metrics/test-hoc.sh @@ -23,7 +23,7 @@ set -e set -o pipefail -temp=$1 +# temp=$1 stdout=$2 { @@ -51,18 +51,18 @@ stdout=$2 git add "${java}" git commit --quiet -m "first commit" ${hoc_script_path} "${java}" "stdout" "Foo" - grep "hoc Foo:1" "stdout" + grep "hoc 1" "stdout" printf "class Foo {\n\tint x;\n\tbool y;\n}\n" > "${java}" git add "${java}" git commit --quiet -m "+second commit" ${hoc_script_path} "${java}" "stdout" "Foo" - grep "hoc Foo:6" "stdout" + grep "hoc 6" "stdout" printf "class Foo {\n\tbool z;\n}\n" > "${java}" git add "${java}" git commit --quiet -m "-third commit" ${hoc_script_path} "${java}" "stdout" "Foo" - grep "hoc Foo:9" "stdout" + grep "hoc 9" "stdout" } > "${stdout}" 2>&1 echo "👍🏻 Correctly calculated hits of code" From 852ba5111dcfaa9e1a7e257d285ce9c09ced80d7 Mon Sep 17 00:00:00 2001 From: IlnurHA <53339563+IlnurHA@users.noreply.github.com> Date: Thu, 28 Mar 2024 20:44:16 +0300 Subject: [PATCH 14/15] Uncomment temp; It is actually used --- tests/metrics/test-hoc.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/metrics/test-hoc.sh b/tests/metrics/test-hoc.sh index a81bf132..6844a456 100755 --- a/tests/metrics/test-hoc.sh +++ b/tests/metrics/test-hoc.sh @@ -23,7 +23,7 @@ set -e set -o pipefail -# temp=$1 +temp=$1 stdout=$2 { From 841294de2c1f7f32e4f3c43dd0c83196bb8223df Mon Sep 17 00:00:00 2001 From: Ilnur Khadiev Date: Thu, 25 Apr 2024 13:01:37 +0300 Subject: [PATCH 15/15] remove class name from metric and test --- metrics/hoc.sh | 5 ++--- tests/metrics/test-hoc.sh | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/metrics/hoc.sh b/metrics/hoc.sh index 49a18877..2d223fca 100755 --- a/metrics/hoc.sh +++ b/metrics/hoc.sh @@ -25,16 +25,15 @@ set -o pipefail java=$1 output=$(realpath "$2") -class_name=$3 cd "$(dirname "${java}")" base=$(basename "${java}") # To check that file was added in commit any time if git status > /dev/null 2>&1 && test -n "$(git log --oneline -- "${base}")"; then - hoc=$(git log -L:"class\s${class_name}:${java}" | grep -E "^[+-].*$" | grep -Ev "^\-\-\-\s\S+$" | grep -Evc "^\+\+\+\s\S+$") + hoc=$(git log -L:"class\s:${java}" | grep -E "^[+-].*$" | grep -Ev "^\-\-\-\s\S+$" | grep -Evc "^\+\+\+\s\S+$") else hoc=0 fi -echo "hoc ${hoc} Hits Of Code for ${class_name} class" > "${output}" +echo "hoc ${hoc} Hits Of Code for file" > "${output}" diff --git a/tests/metrics/test-hoc.sh b/tests/metrics/test-hoc.sh index 6844a456..dfda33b5 100755 --- a/tests/metrics/test-hoc.sh +++ b/tests/metrics/test-hoc.sh @@ -50,19 +50,19 @@ stdout=$2 printf "class Foo {}" > "${java}" git add "${java}" git commit --quiet -m "first commit" - ${hoc_script_path} "${java}" "stdout" "Foo" + ${hoc_script_path} "${java}" "stdout" grep "hoc 1" "stdout" printf "class Foo {\n\tint x;\n\tbool y;\n}\n" > "${java}" git add "${java}" git commit --quiet -m "+second commit" - ${hoc_script_path} "${java}" "stdout" "Foo" + ${hoc_script_path} "${java}" "stdout" grep "hoc 6" "stdout" printf "class Foo {\n\tbool z;\n}\n" > "${java}" git add "${java}" git commit --quiet -m "-third commit" - ${hoc_script_path} "${java}" "stdout" "Foo" + ${hoc_script_path} "${java}" "stdout" grep "hoc 9" "stdout" } > "${stdout}" 2>&1 echo "👍🏻 Correctly calculated hits of code"