Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created an AllCaps format test (Issue #237) #261

Merged
merged 18 commits into from
Apr 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 27 additions & 27 deletions metrics/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,69 +440,69 @@ class NotClassError(Exception):
if not (tree_class := list((value for value in tree))):
raise NotClassError('This is not a class')
with open(metrics, 'a', encoding='utf-8') as metric:
metric.write(f'nooa {attrs(tree_class)} '
metric.write(f'NoOA {attrs(tree_class)} '
f'Number of Non-Static (Object) Attributes\n')
metric.write(f'nosa {sattrs(tree_class)} '
metric.write(f'NoSA {sattrs(tree_class)} '
f'Number of Static Attributes\n')
metric.write(f'nocc {ctors(tree_class)} '
metric.write(f'NoCC {ctors(tree_class)} '
f'Number of Class Constructors\n')
metric.write(f'noom {methods(tree_class)} '
metric.write(f'NoOM {methods(tree_class)} '
f'Number of Non-Static (Object) Methods\n')
metric.write(f'nocm {smethods(tree_class)} '
metric.write(f'NoCM {smethods(tree_class)} '
f'Number of Static (Class) Methods\n')
metric.write(f'ncss {ncss(raw)} '
metric.write(f'NCSS {ncss(raw)} '
f'Non-Commenting Source Statements (NCSS)\n')
metric.write(f'noii {impls(tree_class)} '
metric.write(f'NoII {impls(tree_class)} '
f'Number of Implemented Interfaces\n')
metric.write(f'napc {extnds(tree_class)} '
metric.write(f'NAPC {extnds(tree_class)} '
f'Number of Ancestor (Parent) Classes\n')
metric.write(f'notp {gnrcs(tree_class)} '
metric.write(f'NoTP {gnrcs(tree_class)} '
f'Number of Type Parameters (Generics)\n')
metric.write(f'final {final(tree_class)} '
metric.write(f'Final {final(tree_class)} '
f'Class is ``final\'\' (1) or not (0)\n')
metric.write(f'noca {annts(tree_class)} '
metric.write(f'NoCA {annts(tree_class)} '
f'Number of Class Annotations\n')
metric.write(f'pvn {pvn(tree_class)} '
metric.write(f'PVN {pvn(tree_class)} '
f'Average number of parts in variable names\n')
metric.write(f'mxpvn {mxpvn(tree_class)} '
metric.write(f'MxPVN {mxpvn(tree_class)} '
f'Maximum number of parts in variable names\n')
metric.write(f'mnpvn {mnpvn(tree_class)} '
metric.write(f'MnPVN {mnpvn(tree_class)} '
f'Minimum number of parts in variable names\n')
metric.write(f'pcn {pcn(tree_class)} '
metric.write(f'PCN {pcn(tree_class)} '
f'Number of words in the name of a class\n')
metric.write(f'mhf {mhf(tree_class)} '
metric.write(f'MHF {mhf(tree_class)} '
f'Method Hiding Factor (MHF), which is the ratio of private \
and protected methods to total methods\n')
metric.write(f'smhf {smhf(tree_class)} '
metric.write(f'SMHF {smhf(tree_class)} '
f'Static Method Hiding Factor (MHF), which is the ratio of private \
and protected static methods to total static methods\n')
metric.write(f'ahf {ahf(tree_class)} '
metric.write(f'AHF {ahf(tree_class)} '
f'Attribute Hiding Factor (AHF), which is the ratio of private \
and protected attributes to total attributes\n')
metric.write(f'sahf {sahf(tree_class)} '
metric.write(f'SAHF {sahf(tree_class)} '
f'Static Attribute Hiding Factor (SAHF), which is the ratio of private \
and protected static attributes to total static attributes\n')
metric.write(f'nomp {nomp(tree_class)} '
metric.write(f'NoMP {nomp(tree_class)} '
f'Number of Method Parameters (NOMP), which is the count of \
all parameters in all methods in a class\n')
metric.write(f'nosmp {nosmp(tree_class)} '
metric.write(f'NoSMP {nosmp(tree_class)} '
f'Number of Static Method Parameters (NOSMP), which is the count of all \
parameters in all static methods in a class\n')
metric.write(f'mxnomp {mxnomp(tree_class)} '
metric.write(f'MxNOMP {mxnomp(tree_class)} '
f'Maximum of Method Parameters (MxNOMP), which is the largest amount \
of parameters in some method in a class\n')
metric.write(f'mxnosmp {mxnosmp(tree_class)} '
metric.write(f'MxNOSMP {mxnosmp(tree_class)} '
f'Maximum of Static Method Parameters (MxNOSMP), which is the largest \
amount of parameters in some static method in a class\n')
metric.write(f'nom {nom(tree_class)} '
metric.write(f'NOM {nom(tree_class)} '
f'Number of Overriding Methods (NOM), which is the number of methods \
with the \\texttt{{@Override}} annotation\n')
metric.write(f'nop {nop(tree_class)} '
metric.write(f'NOP {nop(tree_class)} '
f'Number of Polymorphic Methods (NOP), which is the count of methods \
that are overloaded at least once --- have similar names but different parameters\n')
metric.write(f'nulls {nulls(tree_class)} '
metric.write(f'NULLs {nulls(tree_class)} '
f'Number of NULL References\n')
metric.write(f'doer {doer(tree_class)} '
metric.write(f'DOER {doer(tree_class)} '
f'Data vs Object Encapsulation Ratio\n')
except FileNotFoundError as exception:
message = f"{type(exception).__name__} {str(exception)}: {java}"
Expand Down
2 changes: 1 addition & 1 deletion metrics/authors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ else
noca=0
fi

echo "noga ${noca} Number of unique Git committers of a file" > "${output}"
echo "NoGA ${noca} Number of unique Git committers of a file" > "${output}"
6 changes: 3 additions & 3 deletions metrics/cloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ output=$2
out=$(cloc --timeout 0 --quiet --csv "${java}" | tail -1)
IFS=',' read -r -a M <<< "${out}"
cat <<EOT> "${output}"
nobl ${M[2]} Number of Blank Lines
nocl ${M[3]} Number of Commenting Lines
loc ${M[4]} Total physical lines of source code, including commenting lines and blank lines
NoBL ${M[2]} Number of Blank Lines
NoCL ${M[3]} Number of Commenting Lines
LoC ${M[4]} Total physical lines of source code, including commenting lines and blank lines
EOT
2 changes: 1 addition & 1 deletion metrics/cyclomatic_complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def branches(parser_class: tree.CompilationUnit) -> int:
for path, node in ast:
complexity += branches(node)
with open(metrics, 'a', encoding='utf-8') as m:
m.write(f'cc {complexity} Total \
m.write(f'CC {complexity} Total \
\\href{{https://en.wikipedia.org/wiki/Cyclomatic_complexity}}{{Cyclomatic Complexity}} \
of all methods\n')
except FileNotFoundError as exception:
Expand Down
10 changes: 5 additions & 5 deletions metrics/multimetric.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ temp="${TARGET}/temp/multimetric.json"
mkdir -p "$(dirname "${temp}")"
echo "${body}" > "${temp}"
cat <<EOT> "${output}"
hsd $(echo "${body}" | jq '.halstead_difficulty' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Difficulty}
hse $(echo "${body}" | jq '.halstead_effort' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Effort}
hsv $(echo "${body}" | jq '.halstead_volume' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Volume}
midx $(echo "${body}" | jq '.maintainability_index' | "${LOCAL}/help/float.sh") \href{https://ieeexplore.ieee.org/abstract/document/303623/}{Maintainability Index}
fout $(echo "${body}" | jq '.fanout_external' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Fan-out_(software)}{Fan-Out}
HSD $(echo "${body}" | jq '.halstead_difficulty' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Difficulty}
HSE $(echo "${body}" | jq '.halstead_effort' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Effort}
HSV $(echo "${body}" | jq '.halstead_volume' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Halstead_complexity_measures}{Halstead Volume}
MIdx $(echo "${body}" | jq '.maintainability_index' | "${LOCAL}/help/float.sh") \href{https://ieeexplore.ieee.org/abstract/document/303623/}{Maintainability Index}
FOut $(echo "${body}" | jq '.fanout_external' | "${LOCAL}/help/float.sh") \href{https://en.wikipedia.org/wiki/Fan-out_(software)}{Fan-Out}
EOT
8 changes: 4 additions & 4 deletions metrics/pmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ sed 's/xmlns=".*"//g' "${tmp}/result.xml" | \
ruby -e "
a = STDIN.read.split(' ').map(&:to_i)
sum = a.inject(&:+)
puts \"coco #{a.empty? ? 0 : sum} Summary of ${tail}\"
puts \"acoco #{a.empty? ? 0 : sum / a.count} Average of ${tail}\"
puts \"mxcoco #{a.empty? ? 0 : a.max} Maximum ${tail}\"
puts \"mncoco #{a.empty? ? 0 : a.min} Minimum ${tail}\"
puts \"CoCo #{a.empty? ? 0 : sum} Summary of ${tail}\"
puts \"ACoCo #{a.empty? ? 0 : sum / a.count} Average of ${tail}\"
puts \"MxCoCo #{a.empty? ? 0 : a.max} Maximum ${tail}\"
puts \"MnCoCo #{a.empty? ? 0 : a.min} Minimum ${tail}\"
" > "${output}"

rm -rf "${tmp}"
Expand Down
2 changes: 1 addition & 1 deletion metrics/raf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ else
raf=0
fi

echo "raf ${raf} Relative Age of File (in the entire timeframe of repository existence), \
echo "RAF ${raf} Relative Age of File (in the entire timeframe of repository existence), \
where 0.0 means the file was added in the first commit and 1.0 means that \
the file was added in the last commit" > "${output}"
52 changes: 26 additions & 26 deletions tests/metrics/test-ast.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,31 +39,31 @@ stdout=$2
}" > "${java}"
"${LOCAL}/metrics/ast.py" "${java}" "${temp}/stdout"
cat "${temp}/stdout"
grep "nooa 2 " "${temp}/stdout"
grep "nosa 2 " "${temp}/stdout"
grep "noca 1 " "${temp}/stdout"
grep "noom 3 " "${temp}/stdout"
grep "noii 2 " "${temp}/stdout"
grep "napc 1 " "${temp}/stdout"
grep "notp 1 " "${temp}/stdout"
grep "final 1 " "${temp}/stdout"
grep "noca 1 " "${temp}/stdout"
grep "pvn 2.75 " "${temp}/stdout"
grep "mxpvn 6 " "${temp}/stdout"
grep "mnpvn 1 " "${temp}/stdout"
grep "pcn 1" "${temp}/stdout"
grep "mhf 1.0 " "${temp}/stdout"
grep "smhf 0 " "${temp}/stdout"
grep "ahf 0.25 " "${temp}/stdout"
grep "sahf 0.0 " "${temp}/stdout"
grep "nomp 0 " "${temp}/stdout"
grep "nosmp 0 " "${temp}/stdout"
grep "mxnomp 0 " "${temp}/stdout"
grep "mxnosmp 0 " "${temp}/stdout"
grep "nom 0 " "${temp}/stdout"
grep "nop 0 " "${temp}/stdout"
grep "nulls 0 " "${temp}/stdout"
grep "doer 0.5 " "${temp}/stdout"
grep "NoOA 2 " "${temp}/stdout"
grep "NoSA 2 " "${temp}/stdout"
grep "NoCC 0 " "${temp}/stdout"
grep "NoOM 3 " "${temp}/stdout"
grep "NoII 2 " "${temp}/stdout"
grep "NAPC 1 " "${temp}/stdout"
grep "NoTP 1 " "${temp}/stdout"
grep "Final 1 " "${temp}/stdout"
grep "NoCA 1 " "${temp}/stdout"
grep "PVN 2.75 " "${temp}/stdout"
grep "MxPVN 6 " "${temp}/stdout"
grep "MnPVN 1 " "${temp}/stdout"
grep "PCN 1" "${temp}/stdout"
grep "MHF 1.0 " "${temp}/stdout"
grep "SMHF 0 " "${temp}/stdout"
grep "AHF 0.25 " "${temp}/stdout"
grep "SAHF 0.0 " "${temp}/stdout"
grep "NoMP 0 " "${temp}/stdout"
grep "NoSMP 0 " "${temp}/stdout"
grep "MxNOMP 0 " "${temp}/stdout"
grep "MxNOSMP 0 " "${temp}/stdout"
grep "NOM 0 " "${temp}/stdout"
grep "NOP 0 " "${temp}/stdout"
grep "NULLs 0 " "${temp}/stdout"
grep "DOER 0.5 " "${temp}/stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Correctly collected AST metrics"

Expand All @@ -75,7 +75,7 @@ echo "👍🏻 Correctly collected AST metrics"
}" > "${java}"
"${LOCAL}/metrics/ast.py" "${java}" "${temp}/stdout"
cat "${temp}/stdout"
grep "nulls 1 " "${temp}/stdout"
grep "NULLs 1 " "${temp}/stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Correctly counted NULL references"

Expand Down
4 changes: 2 additions & 2 deletions tests/metrics/test-authors.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ stdout=$2
{
tmp=$(mktemp -d /tmp/XXXX)
"${LOCAL}/metrics/authors.sh" "${tmp}" "${temp}/stdout"
grep "noga 0 " "${temp}/stdout"
grep "NoGA 0 " "${temp}/stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Didn't fail in non-git directory"

Expand All @@ -45,6 +45,6 @@ echo "👍🏻 Didn't fail in non-git directory"
git config commit.gpgsign false
git commit --quiet -am start
"${LOCAL}/metrics/authors.sh" "${java}" stdout
grep "noga 1 " stdout
grep "NoGA 1 " stdout
} > "${stdout}" 2>&1
echo "👍🏻 Correctly calculated authors"
6 changes: 3 additions & 3 deletions tests/metrics/test-cloc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ stdout=$2
java="${temp}/Foo long 'weird' name (--).java"
echo "class Foo {}" > "${java}"
"${LOCAL}/metrics/cloc.sh" "${java}" "${temp}/stdout"
grep "loc 1 " "${temp}/stdout"
grep "nobl 0 " "${temp}/stdout"
grep "nocl 0 " "${temp}/stdout"
grep "LoC 1 " "${temp}/stdout"
grep "NoBL 0 " "${temp}/stdout"
grep "NoCL 0 " "${temp}/stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Correctly counted lines of code"
2 changes: 1 addition & 1 deletion tests/metrics/test-cyclomatic_complexity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ stdout=$2
mkdir -p "$(dirname "${java}")"
echo "class Foo {}" > "${java}"
"${LOCAL}/metrics/cyclomatic_complexity.py" "${java}" "${temp}/stdout"
grep "cc 1 " "${temp}/stdout"
grep "CC 1 " "${temp}/stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Correctly calculated cyclomatic complexity"

Expand Down
10 changes: 5 additions & 5 deletions tests/metrics/test-multimetric.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ EOT
"${LOCAL}/metrics/multimetric.sh" "${java}" "${temp}/stdout"
cat "${TARGET}/temp/multimetric.json"
cat "${temp}/stdout"
grep "hsd 6 " "${temp}/stdout"
grep "hse 1133.21789508 " "${temp}/stdout"
grep "hsv 188.86964918 " "${temp}/stdout"
grep "midx 100 " "${temp}/stdout"
grep "fout 0 " "${temp}/stdout"
grep "HSD 6 " "${temp}/stdout"
grep "HSE 1133.21789508 " "${temp}/stdout"
grep "HSV 188.86964918 " "${temp}/stdout"
grep "MIdx 100 " "${temp}/stdout"
grep "FOut 0 " "${temp}/stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Correctly counted a few metrics"
2 changes: 1 addition & 1 deletion tests/metrics/test-pmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ echo "👍🏻 PMD dependencies are installed"
mkdir -p "$(dirname "${java}")"
echo "class Foo {}" > "${java}"
"${LOCAL}/metrics/pmd.sh" "${java}" "${temp}/stdout"
grep "coco 0 " "${temp}/stdout"
grep "CoCo 0 " "${temp}/stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Correctly calculated congitive complexity"
8 changes: 4 additions & 4 deletions tests/metrics/test-raf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ stdout=$2
touch "temp_file"
mkdir -p "${LOCAL}/${temp}"
"${LOCAL}/metrics/raf.sh" "temp_file" "${LOCAL}/${temp}/stdout"
grep "raf 0 " "${LOCAL}/${temp}/stdout"
grep "RAF 0 " "${LOCAL}/${temp}/stdout"
} > "${stdout}" 2>&1
echo "👍🏻 Didn't fail in non-git directory"

Expand Down Expand Up @@ -60,8 +60,8 @@ echo "👍🏻 Didn't fail in non-git directory"
git add "${file3}"
git commit --quiet -m "third"
"${LOCAL}/metrics/raf.sh" "${file3}" "t3"
grep "raf 1.0 " "t1" # File is created with repo
grep "raf 0.5 " "t2" # File created right now
grep "raf 0.0 " "t3" # File created exactly in the middle
grep "RAF 1.0 " "t1" # File is created with repo
grep "RAF 0.5 " "t2" # File created right now
grep "RAF 0.0 " "t3" # File created exactly in the middle
} > "${stdout}" 2>&1
echo "👍🏻 Correctly calculated the Relative Age of File"
57 changes: 57 additions & 0 deletions tests/steps/test-allcaps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/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

temp=$1
stdout=$2

{
java="${temp}/Foo(xls;)';ого привет '\".java"
cat > "${java}" <<EOT
class Foo extends Boo implements Bar {
// This is static
private static int X = 1;
private String z;

Foo(String zz) {
this.z = zz;
}
private final boolean boom() { return true; }
}
EOT
"${LOCAL}/steps/measure-file.sh" "${java}" "${temp}/m1"
set -x
all=$(find "${temp}" -name 'm1.*' -type f -exec basename {} \; | sort)
expected=$(echo "${all}" | wc -l | xargs)
actual=$(echo "${all}" | grep -E -c 'm1.([A-Z][A-Za-z0-9]*)+(-cvc)?$' | xargs)
if [ ! "${actual}" = "${expected}" ]; then
echo "Exactly ${expected} metrics were expected to be named in AllCaps format, but ${actual} actually were"
exit 1
fi
set +x
} > "${stdout}" 2>&1
echo "👍🏻 All metrics are correctly named in AllCaps format"