diff --git a/steps/aggregate-repo.sh b/steps/aggregate-repo.sh index ff9a4d39..ef5e6bd7 100755 --- a/steps/aggregate-repo.sh +++ b/steps/aggregate-repo.sh @@ -26,14 +26,31 @@ set -o pipefail repo=$1 pos=$2 total=$3 -all=$4 +metrics=$4 start=$(date +%s%N) dir=${TARGET}/measurements/${repo} ddir=${TARGET}/data/${repo} if [ -e "${ddir}" ]; then - echo "${repo} already aggregated (${pos}/${total}): ${ddir}" + declare -i found=0 + declare -i missing=0 + for m in ${metrics}; do + if [ -e "${ddir}/${m}.csv" ]; then + found=$((found+1)) + else + missing=$((missing+1)) + fi + done + if [ "${missing}" = 0 ]; then + echo "All ${found} metrics in ${repo} already aggregated (${pos}/${total}): ${ddir}" + exit + fi + echo "Not all $((found+missing)) metrics aggregated in ${repo} (${pos}/${total}), ${missing} missing: ${ddir}" +fi + +if [ ! -e "${dir}" ]; then + echo "Nothing to aggregate in ${repo} (${pos}/${total}), no measurements in ${ddir}" exit fi @@ -55,14 +72,14 @@ find "${dir}" -name '*.m' | { mkdir -p "$(dirname "${csv}")" if [ ! -e "${csv}" ]; then printf 'java_file' > "${csv}" - for a in ${all}; do + for a in ${metrics}; do printf ",%s" "${a}" >> "${csv}" done printf '\n' >> "${csv}" fi java=$(echo "${m}" | sed "s|${dir}||" | sed "s|\.m$||") printf '%s' "$(echo "${java}" | "${LOCAL}/help/to-csv.sh")" >> "${csv}" - for a in ${all}; do + for a in ${metrics}; do if [ -e "${m}.${a}" ]; then value=$("${LOCAL}/help/float.sh" < "${m}.${a}") printf ",%s" "${value}" >> "${csv}" diff --git a/tests/steps/test-aggregate-repo.sh b/tests/steps/test-aggregate-repo.sh index 0eb007a5..075e00f9 100755 --- a/tests/steps/test-aggregate-repo.sh +++ b/tests/steps/test-aggregate-repo.sh @@ -35,11 +35,23 @@ msg=$("${LOCAL}/steps/aggregate-repo.sh" "${repo}" 1 1 'loc nhd') test "$(echo "${msg}" | grep -c "sum=0")" == 0 test "$(echo "${msg}" | grep -c "files=0")" == 0 test -e "${TARGET}/data/${repo}/all.csv" -grep "/a/Foo\\\\,Bar.java,42,0.75" "${TARGET}/data/${repo}/all.csv" >> "${stdout}" 2>&1 -grep "java_file,loc,nhd" "${TARGET}/data/${repo}/all.csv" >> "${stdout}" 2>&1 -test -e "${TARGET}/data/${repo}/loc.csv" -grep "java_file,loc" "${TARGET}/data/${repo}/loc.csv" >> "${stdout}" 2>&1 -grep "/a/Foo\\\\,Bar.java,42" "${TARGET}/data/${repo}/loc.csv" >> "${stdout}" 2>&1 -test -e "${TARGET}/data/${repo}/nhd.csv" -grep ",42" "${TARGET}/data/${repo}/loc.csv" >> "${stdout}" 2>&1 +{ + grep "/a/Foo\\\\,Bar.java,42,0.75" "${TARGET}/data/${repo}/all.csv" + grep "java_file,loc,nhd" "${TARGET}/data/${repo}/all.csv" + test -e "${TARGET}/data/${repo}/loc.csv" + grep "java_file,loc" "${TARGET}/data/${repo}/loc.csv" + grep "/a/Foo\\\\,Bar.java,42" "${TARGET}/data/${repo}/loc.csv" + test -e "${TARGET}/data/${repo}/nhd.csv" + grep ",42" "${TARGET}/data/${repo}/loc.csv" +} >> "${stdout}" 2>&1 echo "👍🏻 A repo aggregated correctly" + +repo="dog/cat" +dir="${TARGET}/data/${repo}" +mkdir -p "${dir}" +touch "${dir}/loc.csv" +msg=$("${LOCAL}/steps/aggregate-repo.sh" "${repo}" 1 1 'loc nhd') +{ + echo "${msg}" | grep "Not all 2 metrics aggregated" +} >> "${stdout}" 2>&1 +echo "👍🏻 A partially aggregated repo processed correctly"