diff --git a/help/to-csv.sh b/help/to-csv.sh index d08cede7..50500e15 100755 --- a/help/to-csv.sh +++ b/help/to-csv.sh @@ -27,4 +27,4 @@ set -o pipefail # suitable for CSV: replacing commas. data=$(cat) -printf '%s' "${data}" | sed 's/,/\\,/' \ No newline at end of file +printf '%s' "${data}" | sed 's/,/\\,/g' \ No newline at end of file diff --git a/tests/help/test-to-csv.sh b/tests/help/test-to-csv.sh new file mode 100755 index 00000000..2031ab62 --- /dev/null +++ b/tests/help/test-to-csv.sh @@ -0,0 +1,32 @@ +#!/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 + +stdout=$2 + +test "$(echo 'a b c' | "${LOCAL}/help/to-csv.sh")" = 'a b c' > "${stdout}" +echo "👍🏻 Correctly formatted simple text" + +test "$(echo 'a,b,c' | "${LOCAL}/help/to-csv.sh")" = 'a\,b\,c' > "${stdout}" +echo "👍🏻 Correctly formatted commas" diff --git a/tests/steps/test-aggregate-repo.sh b/tests/steps/test-aggregate-repo.sh index 16d72c20..fc90aa83 100755 --- a/tests/steps/test-aggregate-repo.sh +++ b/tests/steps/test-aggregate-repo.sh @@ -26,8 +26,8 @@ set -o pipefail stdout=$2 { - repo="foo/bar test ; " - dir="${TARGET}/measurements/${repo}/a" + repo="foo/bar test, ; " + dir="${TARGET}/measurements/${repo}/a, ; -" mkdir -p "${dir}" m="Foo,- ;Bar.java.m" touch "${dir}/${m}" @@ -37,11 +37,11 @@ stdout=$2 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" + 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" + 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