move setup from test file to test command

This commit is contained in:
felixlohmeier 2022-12-01 22:43:52 +00:00
parent 6051f707ca
commit aea762f22f
4 changed files with 20 additions and 41 deletions

9
orcli
View File

@ -1050,7 +1050,7 @@ orcli_info_command() {
# :command.function # :command.function
orcli_test_command() { orcli_test_command() {
# src/test_command.sh # src/test_command.sh
# shellcheck shell=bash # shellcheck shell=bash disable=SC2154
# catch args, convert the space delimited string to an array # catch args, convert the space delimited string to an array
files=() files=()
@ -1099,11 +1099,16 @@ orcli_test_command() {
results=() results=()
for i in "${!files[@]}"; do for i in "${!files[@]}"; do
set +e set +e
bash <( 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+=(${?})

View File

@ -1,4 +1,4 @@
# shellcheck shell=bash # shellcheck shell=bash disable=SC2154
# catch args, convert the space delimited string to an array # catch args, convert the space delimited string to an array
files=() files=()
@ -47,11 +47,16 @@ export OPENREFINE_TMPDIR OPENREFINE_URL OPENREFINE_PID
results=() results=()
for i in "${!files[@]}"; do for i in "${!files[@]}"; do
set +e set +e
bash <( 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+=(${?})

View File

@ -1,29 +0,0 @@
#!/bin/bash
# environment
t=import-csv
mkdir "${OPENREFINE_TMPDIR}/${t}"
cd "${OPENREFINE_TMPDIR}/${t}" || exit 1
# data
cat << "DATA" > "test.csv"
a,b,c
1,2,3
0,0,0
$,\,'
DATA
# assertion
cat << "DATA" > "test.assert"
a b c
1 2 3
0 1 0
$ \ '
DATA
# action
orcli import csv "test.csv"
orcli export tsv "test csv" --output "test.output"
# test
diff -u "test.assert" "test.output"

View File

@ -1,12 +1,10 @@
#!/bin/bash #!/bin/bash
# environment # environment
t=import-csv t="$(basename "$(pwd)" .sh)"
mkdir "${OPENREFINE_TMPDIR}/${t}"
cd "${OPENREFINE_TMPDIR}/${t}" || exit 1
# data # data
cat << "DATA" > "test.csv" cat << "DATA" > "${t}.csv"
a,b,c a,b,c
1,2,3 1,2,3
0,0,0 0,0,0
@ -14,7 +12,7 @@ $,\,'
DATA DATA
# assertion # assertion
cat << "DATA" > "test.assert" cat << "DATA" > "${t}.assert"
a b c a b c
1 2 3 1 2 3
0 0 0 0 0 0
@ -22,8 +20,8 @@ $ \ '
DATA DATA
# action # action
orcli import csv "test.csv" orcli import csv "${t}.csv"
orcli export tsv "test csv" --output "test.output" orcli export tsv "${t} csv" --output "${t}.output"
# test # test
diff -u "test.assert" "test.output" diff -u "${t}.assert" "${t}.output"