Skip to content

Commit

Permalink
#185 fix in csv formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Mar 4, 2024
1 parent 49885dd commit c19c387
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
2 changes: 1 addition & 1 deletion help/to-csv.sh
Expand Up @@ -27,4 +27,4 @@ set -o pipefail
# suitable for CSV: replacing commas.

data=$(cat)
printf '%s' "${data}" | sed 's/,/\\,/'
printf '%s' "${data}" | sed 's/,/\\,/g'
32 changes: 32 additions & 0 deletions 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"
8 changes: 4 additions & 4 deletions tests/steps/test-aggregate-repo.sh
Expand Up @@ -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}"
Expand All @@ -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
Expand Down

0 comments on commit c19c387

Please sign in to comment.