OILS / test / tsv-lib-test.sh View on Github | oilshell.org

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