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

72 lines, 32 significant
1#!/usr/bin/env bash
2#
3# Usage:
4# devtools/tsv-lib-test.sh <function name>
5
6set -o nounset
7set -o pipefail
8set -o errexit
9
10REPO_ROOT=$(cd "$(dirname $0)/.."; pwd)
11source test/tsv-lib.sh
12source test/common.sh # fail
13
14test-concat-rows() {
15 set +o errexit
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 tsv-concat _tmp/test{1,2}.csv
30
31 cat >_tmp/bad.csv <<EOF
32name,age,another
33dave,30,oops
34EOF
35
36 tsv-concat _tmp/test{1,2}.csv _tmp/bad.csv
37 if test $? -eq 1; then
38 echo 'Expected failure OK'
39 else
40 fail 'Should have failed'
41 fi
42}
43
44test-add-const-column() {
45 here-schema-tsv >_tmp/add.tsv <<EOF
46name age
47alice 10
48bob 20
49EOF
50 cat _tmp/add.tsv
51
52 tsv-add-const-column host_name $(hostname) < _tmp/add.tsv
53}
54
55test-tsv2html() {
56 cat >_tmp/test2.tsv <<EOF
57name
58carol
59EOF
60
61 tsv2html _tmp/test2.tsv
62
63 # This test passes on my desktop, but 'other-tests' Soil image doesn't have
64 # python3 yet.
65 #tsv2html3 _tmp/test2.tsv
66}
67
68soil-run() {
69 run-test-funcs
70}
71
72"$@"