Skip to content

Commit

Permalink
Add support for SCRIPT_CALL_FMT
Browse files Browse the repository at this point in the history
  • Loading branch information
HenrikBengtsson committed Apr 30, 2024
1 parent 89307b2 commit 38ff421
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,15 @@ check-api: assert-SCRIPT_CALL assert-bats

## FIXME: How do I use node/npm so it finds the 'seguid' module?
check-api/seguid-javascript:
$(MAKE) check-api SCRIPT_CALL="node" SCRIPT_PREAMBLE="const { seguid, lsseguid, ldseguid, csseguid, cdseguid } = require('seguid')" SCRIPT_PRINT_FMT="console.log(%s)"
$(MAKE) check-api SCRIPT_CALL="node" SCRIPT_PREAMBLE="const { seguid, lsseguid, ldseguid, csseguid, cdseguid } = require('seguid')" SCRIPT_PRINT_FMT="console.log(%s)" SCRIPT_ARGS_SEP=", "

check-api/seguid-python:
$(MAKE) check-api SCRIPT_CALL="python" SCRIPT_PREAMBLE="from seguid import *" SCRIPT_PRINT_FMT="out=%s\nif isinstance(out, tuple):\n out=' '.join(out)\nprint(out)"
$(MAKE) check-api SCRIPT_CALL="python" SCRIPT_PREAMBLE="from seguid import *" SCRIPT_PRINT_FMT="out=%s\nif isinstance(out, tuple):\n out=' '.join(out)\nprint(out)" SCRIPT_ARGS_SEP=", "

check-api/seguid-r:
$(MAKE) check-api SCRIPT_CALL="Rscript --no-init-file" SCRIPT_PREAMBLE="library(seguid)" SCRIPT_PRINT_FMT="cat(%s)"
$(MAKE) check-api SCRIPT_CALL="Rscript --no-init-file" SCRIPT_PREAMBLE="library(seguid)" SCRIPT_PRINT_FMT="cat(%s)" SCRIPT_ARGS_SEP=", "

check-api/seguid-tcl:
$(MAKE) check-api SCRIPT_CALL="tclsh" SCRIPT_PREAMBLE="source ../src/base64.tcl; source ../src/sha1.tcl; source ../src/seguid.tcl;" SCRIPT_PRINT_FMT="puts stdout [%s]" SCRIPT_ARGS_SEP=" " SCRIPT_CALL_FMT="%s %s"

check-api/ALL: check-api/seguid-python check-api/seguid-r
12 changes: 9 additions & 3 deletions tests-api/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ setup_api_test() {
script_print_fmt="${SCRIPT_PRINT_FMT:-print(%s)}"
echo "script_print_fmt: ${script_print_fmt}"

script_args_sep="${SCRIPT_ARGS_SEP:-, }"
echo "script_args_sep: ${script_args_sep}"
script_args_sep="${SCRIPT_ARGS_SEP}"
if [[ -z ${script_args_sep} ]]; then
script_args_sep=" "
fi
echo "script_args_sep: '${script_args_sep}'"

script_call_fmt="${SCRIPT_CALL_FMT:-%s(%s)}"
echo "script_call_fmt: ${script_call_fmt}"
}


Expand Down Expand Up @@ -48,7 +54,7 @@ api_call() {
## Add script preamble
printf "%s\n" "${script_preamble[@]}" > "${tf}"
## Generate API call
call="${fcn}($(args_to_string "${args[@]}"))"
call=$(printf "${script_call_fmt}" "${fcn}" "$(args_to_string "${args[@]}")")
## Wrap API call in print statement
call=$(printf "${script_print_fmt}" "${call}")
printf "%s\n" "${call}" >> "${tf}"
Expand Down

0 comments on commit 38ff421

Please sign in to comment.