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

View File

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

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 #!/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"