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