make test scripts standalone

This commit is contained in:
felixlohmeier 2022-12-03 00:30:01 +00:00
parent aea762f22f
commit 8b2e35ced2
7 changed files with 740 additions and 677 deletions

1340
orcli

File diff suppressed because it is too large Load Diff

View File

@ -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

View File

@ -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+=(${?})

4
tests/data/example.csv Normal file
View File

@ -0,0 +1,4 @@
a,b,c
1,2,3
0,0,0
$,\,'
1 a b c
2 1 2 3
3 0 0 0
4 $ \ '

4
tests/data/example.tsv Normal file
View File

@ -0,0 +1,4 @@
a b c
1 2 3
0 0 0
$ \ '
1 a b c
2 1 2 3
3 0 0 0
4 $ \ '

19
tests/help.sh Normal file
View File

@ -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"

View File

@ -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"