| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Usage:
|
| 4 | # test/tsv-lib-test.sh <function name>
|
| 5 |
|
| 6 | : ${LIB_OSH=stdlib/osh}
|
| 7 | source $LIB_OSH/bash-strict.sh
|
| 8 | source $LIB_OSH/no-quotes.sh
|
| 9 | source $LIB_OSH/task-five.sh
|
| 10 |
|
| 11 | REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
|
| 12 | source test/tsv-lib.sh
|
| 13 |
|
| 14 | test-concat-rows() {
|
| 15 | local status
|
| 16 |
|
| 17 | mkdir -p _tmp
|
| 18 | cat >_tmp/test1.csv <<EOF
|
| 19 | name,age
|
| 20 | alice,0
|
| 21 | bob,10
|
| 22 | EOF
|
| 23 |
|
| 24 | cat >_tmp/test2.csv <<EOF
|
| 25 | name,age
|
| 26 | carol,20
|
| 27 | EOF
|
| 28 |
|
| 29 | nq-run status \
|
| 30 | tsv-concat _tmp/test{1,2}.csv
|
| 31 | nq-assert 0 = "$status"
|
| 32 |
|
| 33 | cat >_tmp/bad.csv <<EOF
|
| 34 | name,age,another
|
| 35 | dave,30,oops
|
| 36 | EOF
|
| 37 |
|
| 38 | nq-run status \
|
| 39 | tsv-concat _tmp/test{1,2}.csv _tmp/bad.csv
|
| 40 | nq-assert 1 = "$status"
|
| 41 | }
|
| 42 |
|
| 43 | test-add-const-column() {
|
| 44 | here-schema-tsv >_tmp/add.tsv <<EOF
|
| 45 | name age
|
| 46 | alice 10
|
| 47 | bob 20
|
| 48 | EOF
|
| 49 | cat _tmp/add.tsv
|
| 50 |
|
| 51 | tsv-add-const-column host_name $(hostname) < _tmp/add.tsv
|
| 52 | }
|
| 53 |
|
| 54 | test-tsv2html() {
|
| 55 | cat >_tmp/test2.tsv <<EOF
|
| 56 | name
|
| 57 | carol
|
| 58 | EOF
|
| 59 |
|
| 60 | tsv2html _tmp/test2.tsv
|
| 61 |
|
| 62 | # This test passes on my desktop, but 'other-tests' Soil image doesn't have
|
| 63 | # python3 yet.
|
| 64 | #tsv2html3 _tmp/test2.tsv
|
| 65 | }
|
| 66 |
|
| 67 | soil-run() {
|
| 68 | devtools/byo.sh test $0
|
| 69 | }
|
| 70 |
|
| 71 | task-five "$@"
|