xref: /aosp_15_r20/external/rappor/pipeline/csv-to-html-test.sh (revision 2abb31345f6c95944768b5222a9a5ed3fc68cc00)
1#!/bin/bash
2#
3# Test for csv_to_html.py.
4#
5# Usage:
6#   ./csv-to-html-test.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12test-basic() {
13  ./csv_to_html.py <<EOF
14a_number,b
151,2
163,4
17NA,4
18EOF
19}
20
21test-col-format() {
22  ./csv_to_html.py \
23    --col-format 'b <a href="../{b}/metric.html">{b}</a>' <<EOF
24a,b
251,2015-05-01
263,2015-05-02
27EOF
28}
29
30test-var-def() {
31  ./csv_to_html.py \
32    --def 'v VALUE' \
33    --col-format 'b <a href="../{b}/metric.html">{v}</a>' <<EOF
34a,b
351,2
363,4
37EOF
38}
39
40test-as-percent() {
41  ./csv_to_html.py \
42    --as-percent b <<EOF
43a,b
44A,0.21
45B,0.001
46C,0.0009
47D,0.0001
48EOF
49}
50
51if test $# -eq 0; then
52  test-basic
53  echo '--'
54  test-col-format
55  echo '--'
56  test-var-def
57  echo '--'
58  test-as-percent
59  echo '--'
60  echo 'OK'
61else
62  "$@"
63fi
64