make test scripts standalone
This commit is contained in:
parent
aea762f22f
commit
8b2e35ced2
162
orcli
162
orcli
|
@ -1,5 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
# This script was generated by bashly 0.8.10 (https://bashly.dannyb.co)
|
||||
# This script was generated by bashly 0.9.0 (https://bashly.dannyb.co)
|
||||
# Modifying it manually is not recommended
|
||||
|
||||
# :wrapper.bash3_bouncer
|
||||
|
@ -377,7 +377,7 @@ orcli_test_usage() {
|
|||
fi
|
||||
|
||||
printf "Usage:\n"
|
||||
printf " orcli test [FILE...]\n"
|
||||
printf " orcli test\n"
|
||||
printf " orcli test --help | -h\n"
|
||||
echo
|
||||
|
||||
|
@ -390,15 +390,6 @@ orcli_test_usage() {
|
|||
printf " Show this help\n"
|
||||
echo
|
||||
|
||||
# :command.usage_args
|
||||
printf "Arguments:\n"
|
||||
|
||||
# :argument.usage
|
||||
echo " FILE..."
|
||||
printf " Path to one or more files\n"
|
||||
printf " Default: tests/*.sh\n"
|
||||
echo
|
||||
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -1052,16 +1043,12 @@ orcli_test_command() {
|
|||
# src/test_command.sh
|
||||
# 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)!"
|
||||
if ! [[ -f "tests/help.sh" ]]; then
|
||||
error "Cannot open test files!"
|
||||
fi
|
||||
done
|
||||
cd "tests"
|
||||
files=(*.sh)
|
||||
|
||||
# locate orcli and OpenRefine
|
||||
scriptpath=$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")
|
||||
|
@ -1100,15 +1087,10 @@ orcli_test_command() {
|
|||
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+=(${?})
|
||||
|
@ -1379,6 +1361,7 @@ orcli_run_command() {
|
|||
# :command.parse_requirements
|
||||
parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--version | -v)
|
||||
version_command
|
||||
|
@ -1391,18 +1374,24 @@ parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.environment_variables_filter
|
||||
# :command.environment_variables_default
|
||||
export OPENREFINE_URL="${OPENREFINE_URL:-http://localhost:3333}"
|
||||
|
||||
# :command.dependencies_filter
|
||||
if ! [[ -x "$(command -v curl)" ]]; then
|
||||
if ! command -v curl >/dev/null 2>&1; then
|
||||
printf "missing dependency: curl\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
if ! [[ -x "$(command -v jq)" ]]; then
|
||||
|
||||
if ! command -v jq >/dev/null 2>&1; then
|
||||
printf "missing dependency: jq\n" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
@ -1509,6 +1498,7 @@ parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_completions_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -1516,7 +1506,12 @@ orcli_completions_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="completions"
|
||||
|
@ -1547,6 +1542,7 @@ orcli_completions_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_import_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -1554,7 +1550,12 @@ orcli_import_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action=${1:-}
|
||||
|
@ -1616,6 +1617,7 @@ orcli_import_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_import_csv_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -1623,7 +1625,12 @@ orcli_import_csv_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="import csv"
|
||||
|
@ -1724,6 +1731,7 @@ orcli_import_csv_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_import_tsv_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -1731,7 +1739,12 @@ orcli_import_tsv_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="import tsv"
|
||||
|
@ -1816,6 +1829,7 @@ orcli_import_tsv_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_list_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -1823,7 +1837,12 @@ orcli_list_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="list"
|
||||
|
@ -1854,6 +1873,7 @@ orcli_list_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_info_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -1861,7 +1881,12 @@ orcli_info_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="info"
|
||||
|
@ -1904,6 +1929,7 @@ orcli_info_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_test_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -1911,7 +1937,12 @@ orcli_test_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="test"
|
||||
|
@ -1928,29 +1959,21 @@ orcli_test_parse_requirements() {
|
|||
|
||||
*)
|
||||
# :command.parse_requirements_case
|
||||
# :command.parse_requirements_case_repeatable
|
||||
if [[ -z ${args[file]+x} ]]; then
|
||||
|
||||
args[file]="\"$1\""
|
||||
shift
|
||||
else
|
||||
args[file]="${args[file]} \"$1\""
|
||||
shift
|
||||
fi
|
||||
# :command.parse_requirements_case_simple
|
||||
printf "invalid argument: %s\n" "$key" >&2
|
||||
exit 1
|
||||
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.default_assignments
|
||||
[[ -n ${args[file]:-} ]] || args[file]="tests/*.sh"
|
||||
|
||||
}
|
||||
|
||||
# :command.parse_requirements
|
||||
orcli_transform_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -1958,7 +1981,12 @@ orcli_transform_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="transform"
|
||||
|
@ -2015,6 +2043,7 @@ orcli_transform_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_export_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -2022,7 +2051,12 @@ orcli_export_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action=${1:-}
|
||||
|
@ -2077,6 +2111,7 @@ orcli_export_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_export_tsv_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -2084,7 +2119,12 @@ orcli_export_tsv_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="export tsv"
|
||||
|
@ -2167,6 +2207,7 @@ orcli_export_tsv_parse_requirements() {
|
|||
# :command.parse_requirements
|
||||
orcli_run_parse_requirements() {
|
||||
# :command.fixed_flags_filter
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "${1:-}" in
|
||||
--help | -h)
|
||||
long_usage=yes
|
||||
|
@ -2174,7 +2215,12 @@ orcli_run_parse_requirements() {
|
|||
exit
|
||||
;;
|
||||
|
||||
*)
|
||||
break
|
||||
;;
|
||||
|
||||
esac
|
||||
done
|
||||
|
||||
# :command.command_filter
|
||||
action="run"
|
||||
|
@ -2279,97 +2325,111 @@ run() {
|
|||
normalize_input "$@"
|
||||
parse_requirements "${input[@]}"
|
||||
|
||||
if [[ $action == "completions" ]]; then
|
||||
case "$action" in
|
||||
"completions")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_completions_usage
|
||||
else
|
||||
orcli_completions_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "import" ]]; then
|
||||
"import")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_import_usage
|
||||
else
|
||||
orcli_import_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "import csv" ]]; then
|
||||
"import csv")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_import_csv_usage
|
||||
else
|
||||
orcli_import_csv_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "import tsv" ]]; then
|
||||
"import tsv")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_import_tsv_usage
|
||||
else
|
||||
orcli_import_tsv_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "list" ]]; then
|
||||
"list")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_list_usage
|
||||
else
|
||||
orcli_list_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "info" ]]; then
|
||||
"info")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_info_usage
|
||||
else
|
||||
orcli_info_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "test" ]]; then
|
||||
"test")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_test_usage
|
||||
else
|
||||
orcli_test_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "transform" ]]; then
|
||||
"transform")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_transform_usage
|
||||
else
|
||||
orcli_transform_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "export" ]]; then
|
||||
"export")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_export_usage
|
||||
else
|
||||
orcli_export_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "export tsv" ]]; then
|
||||
"export tsv")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_export_tsv_usage
|
||||
else
|
||||
orcli_export_tsv_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "run" ]]; then
|
||||
"run")
|
||||
if [[ ${args[--help]:-} ]]; then
|
||||
long_usage=yes
|
||||
orcli_run_usage
|
||||
else
|
||||
orcli_run_command
|
||||
fi
|
||||
;;
|
||||
|
||||
elif [[ $action == "root" ]]; then
|
||||
"root")
|
||||
root_command
|
||||
fi
|
||||
;;
|
||||
|
||||
esac
|
||||
}
|
||||
|
||||
initialize
|
||||
|
|
|
@ -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)!"
|
||||
if ! [[ -f "tests/help.sh" ]]; then
|
||||
error "Cannot open test files!"
|
||||
fi
|
||||
done
|
||||
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,23 +1,13 @@
|
|||
#!/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"
|
||||
|
|
Loading…
Reference in New Issue