From 6d53d574ee62e75117215a2a4b6dbad5433ec4f5 Mon Sep 17 00:00:00 2001 From: shenwei356 Date: Sat, 11 Mar 2017 00:14:50 +0800 Subject: [PATCH] begin to add functional tests --- .gitignore | 1 + .travis.yml | 11 +++++ testdata/test.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 .travis.yml create mode 100755 testdata/test.sh diff --git a/.gitignore b/.gitignore index 250573d..eaa99af 100755 --- a/.gitignore +++ b/.gitignore @@ -28,3 +28,4 @@ doc/site/* csvtk/csvtk* csvtk/binaries* doc/site +*ssshtest diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..39f8f9c --- /dev/null +++ b/.travis.yml @@ -0,0 +1,11 @@ +language: go + +os: + - linux + - osx + +go: + - 1.8 + +script: + - ./testdata/test.sh diff --git a/testdata/test.sh b/testdata/test.sh new file mode 100755 index 0000000..6cb18be --- /dev/null +++ b/testdata/test.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +test -e ssshtest || wget -q https://raw.githubusercontent.com/ryanlayer/ssshtest/master/ssshtest + +. ssshtest +set -e + + +cd csvtk; go build; cd ..; +app=./csvtk/csvtk + +set +e + + +# ---------------------------------------------------------------------------- +# csvtk headers +# ---------------------------------------------------------------------------- + +for n in 1 10 100 10000 1000000; do + fn() { + cat <(seq $n | awk '{print "c"$1}' | paste -sd,) <(seq $n | paste -sd,) \ + | $app headers + } + run "headers (n=$n)" fn + assert_no_stderr + assert_equal $(cat $STDOUT_FILE | grep -v '#' | wc -l) $n +done + +# ---------------------------------------------------------------------------- +# csvtk stats +# ---------------------------------------------------------------------------- + +for n in 1 10 100 10000 1000000; do + fn() { + cat <(seq $n | awk '{print "c"$1}' | paste -sd,) <(seq $n | paste -sd,) \ + | $app stats + } + run "stats (n=$n)" fn + assert_no_stderr + assert_equal $(cat $STDOUT_FILE | $app space2tab | sed 1d | cut -f 2 | sed 's/,//g') $n + assert_equal $(cat $STDOUT_FILE | $app space2tab | sed 1d | cut -f 3 | sed 's/,//g') 1 + + fn() { + cat <(seq $n | awk '{print "c"$1}' | paste -sd,) <(seq $n | paste -sd,) \ + | $app stats -H + } + run "stats -H (n=$n)" fn + assert_no_stderr + assert_equal $(cat $STDOUT_FILE | $app space2tab | sed 1d | cut -f 2 | sed 's/,//g') $n + assert_equal $(cat $STDOUT_FILE | $app space2tab | sed 1d | cut -f 3 | sed 's/,//g') 2 + + # ----------------------------------------------------------------------- + # transpose + # ----------------------------------------------------------------------- + fn() { + cat <(seq $n | awk '{print "c"$1}' | paste -sd,) <(seq $n | paste -sd,) \ + | $app transpose \ + | $app stats + } + run "transpose & stats (n=$n)" fn + assert_no_stderr + assert_equal $(cat $STDOUT_FILE | $app space2tab | sed 1d | cut -f 2 | sed 's/,//g') 2 + assert_equal $(cat $STDOUT_FILE | $app space2tab | sed 1d | cut -f 3 | sed 's/,//g') $(($n -1)) + + fn() { + cat <(seq $n | awk '{print "c"$1}' | paste -sd,) <(seq $n | paste -sd,) \ + | $app transpose \ + | $app stats -H + } + run "transpose & stats -H (n=$n)" fn + assert_no_stderr + assert_equal $(cat $STDOUT_FILE | $app space2tab | sed 1d | cut -f 2 | sed 's/,//g') 2 + assert_equal $(cat $STDOUT_FILE | $app space2tab | sed 1d | cut -f 3 | sed 's/,//g') $n +done + + +# ---------------------------------------------------------------------------- +# csvtk cut +# ---------------------------------------------------------------------------- + +for n in 1 10 100 10000 1000000; do + fn() { + seq $n | $app cut -H -f 1 + } + run "cut -H -f 1 (n=$n)" fn + assert_no_stderr + assert_equal $(cat $STDOUT_FILE | wc -l) $n + + fn() { + seq $n | $app cut -H -t -f 1 + } + run "cut -H -t -f 1 (n=$n)" fn + assert_no_stderr + assert_equal $(cat $STDOUT_FILE | wc -l) $n + + fn() { + cat <(echo head) <(seq $n) | $app cut -f head + } + run "cut -f head (n=$n)" fn + assert_no_stderr + assert_equal $(cat $STDOUT_FILE | wc -l) $(($n+1)) +done