Skip to content

Commit

Permalink
begin to add functional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
shenwei356 committed Mar 10, 2017
1 parent be2cdba commit 6d53d57
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ doc/site/*
csvtk/csvtk*
csvtk/binaries*
doc/site
*ssshtest
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
language: go

os:
- linux
- osx

go:
- 1.8

script:
- ./testdata/test.sh
102 changes: 102 additions & 0 deletions testdata/test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6d53d57

Please sign in to comment.