make test scripts standalone
This commit is contained in:
parent
aea762f22f
commit
8b2e35ced2
|
@ -118,11 +118,6 @@ commands:
|
|||
|
||||
- name: test
|
||||
help: run functional tests on tmp OpenRefine workspace
|
||||
args:
|
||||
- name: file
|
||||
help: Path to one or more files
|
||||
default: "tests/*.sh"
|
||||
repeatable: true
|
||||
|
||||
- name: transform
|
||||
help: apply undo/redo JSON file(s) to an OpenRefine project
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
# shellcheck shell=bash disable=SC2154
|
||||
|
||||
# catch args, convert the space delimited string to an array
|
||||
files=()
|
||||
eval "files=(${args[file]})"
|
||||
|
||||
# check existence of files
|
||||
for i in "${!files[@]}"; do
|
||||
if ! [[ -f "${files[$i]}" ]]; then
|
||||
error "cannot open ${files[$i]} (no such file)!"
|
||||
fi
|
||||
done
|
||||
if ! [[ -f "tests/help.sh" ]]; then
|
||||
error "Cannot open test files!"
|
||||
fi
|
||||
cd "tests"
|
||||
files=(*.sh)
|
||||
|
||||
# locate orcli and OpenRefine
|
||||
scriptpath=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
|
||||
|
@ -48,15 +44,10 @@ results=()
|
|||
for i in "${!files[@]}"; do
|
||||
set +e
|
||||
bash -e <(
|
||||
# support ./orcli
|
||||
if ! command -v orcli &>/dev/null; then
|
||||
echo "shopt -s expand_aliases"
|
||||
echo "alias orcli=${scriptpath}/orcli"
|
||||
fi
|
||||
# separate subdirectory for each test
|
||||
echo "mkdir -p ${OPENREFINE_TMPDIR}/${files[$i]}"
|
||||
echo "cd ${OPENREFINE_TMPDIR}/${files[$i]} || exit 1"
|
||||
# echo test file
|
||||
awk 1 "${files[$i]}"
|
||||
) &>"$OPENREFINE_TMPDIR/test.log"
|
||||
results+=(${?})
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
a,b,c
|
||||
1,2,3
|
||||
0,0,0
|
||||
$,\,'
|
|
|
@ -0,0 +1,4 @@
|
|||
a b c
|
||||
1 2 3
|
||||
0 0 0
|
||||
$ \ '
|
|
|
@ -0,0 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
t="help"
|
||||
|
||||
# environment
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||
cd "${tmpdir}" || exit 1
|
||||
|
||||
# assertion
|
||||
cat << "DATA" > "${t}.assert"
|
||||
orcli - OpenRefine command-line interface written in Bash
|
||||
DATA
|
||||
|
||||
# action
|
||||
orcli --help | head -n1 > "${t}.output"
|
||||
|
||||
# test
|
||||
diff -u "${t}.assert" "${t}.output"
|
|
@ -1,27 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
t="import-csv"
|
||||
|
||||
# environment
|
||||
t="$(basename "$(pwd)" .sh)"
|
||||
|
||||
# data
|
||||
cat << "DATA" > "${t}.csv"
|
||||
a,b,c
|
||||
1,2,3
|
||||
0,0,0
|
||||
$,\,'
|
||||
DATA
|
||||
|
||||
# assertion
|
||||
cat << "DATA" > "${t}.assert"
|
||||
a b c
|
||||
1 2 3
|
||||
0 0 0
|
||||
$ \ '
|
||||
DATA
|
||||
tmpdir="$(mktemp -d)"
|
||||
trap '{ rm -rf "${tmpdir}"; }' 0 2 3 15
|
||||
cp data/example.csv "${tmpdir}"/${t}.csv
|
||||
cp data/example.tsv "${tmpdir}"/${t}.assert
|
||||
cd "${tmpdir}" || exit 1
|
||||
|
||||
# action
|
||||
orcli import csv "${t}.csv"
|
||||
orcli export tsv "${t} csv" --output "${t}.output"
|
||||
|
||||
# test
|
||||
diff -u "${t}.assert" "${t}.output"
|
||||
diff -u "${t}.assert" "${t}.output"
|
||||
|
|
Loading…
Reference in New Issue