Skip to content

Commit

Permalink
sheet extension: fix example breakage, add test (#291)
Browse files Browse the repository at this point in the history
* sheet extension: fix example breakage, add test
* only perform sheet tests when sheet is built
  • Loading branch information
liquidaty authored Nov 17, 2024
1 parent ef5a55f commit aed475d
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 4 deletions.
28 changes: 27 additions & 1 deletion app/ext_example/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ ${BUILD_DIR}/bin/cli:
${BUILD_DIR}/objs/utils/%.o:
(cd .. && ${MAKE} CONFIGFILE=${CONFIGFILEPATH} CC=${CC} DEBUG=${DEBUG} $@ )

test: test-1 test-2 test-3 test-4 test-5 test-thirdparty
TESTS=test-1 test-2 test-3 test-4 test-5 test-thirdparty
ifeq ($(ZSVSHEET_BUILD),1)
TESTS+=test-sheet-extension
endif

test: ${TESTS}

test-1: test-%: ${CLI} ${TARGET}
@${RUN_CLI} my-echo < ${THIS_LIB_BASE}/data/quoted.csv > /tmp/zsvext-$@.out
Expand All @@ -132,6 +137,27 @@ test-3: test-%: ${CLI} ${TARGET}
@${RUN_CLI} help 2>&1 | grep -v [.]so >> /tmp/zsvext-$@.out || [ 1==1 ]
@cmp /tmp/zsvext-$@.out 2>&1 test/expected/zsvext-$@.out && ${TEST_PASS} || ${TEST_FAIL}

../test/worldcitiespop_mil.csv:
make -C ../test worldcitiespop_mil.csv

TMP_DIR=/tmp
TMUX_TERM=xterm-256color
test-sheet-extension: ../test/worldcitiespop_mil.csv
@rm -f ${TMP_DIR}/zsvext-$@.out tmux-*.log
@tmux kill-session -t $@ || echo 'No tmux session to kill'
@${RUN_CLI} unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${RUN_CLI} register my 2>&1 | grep -v [.]so || [ 1==1 ]
@echo 'set-option default-terminal "${TMUX_TERM}"' > ~/.tmux.conf
@(ZSV_CONFIG_DIR=/tmp tmux -v new-session -x 80 -y 5 -d -s $@ && \
sleep 0.5 && \
tmux send-keys -t $@ "${CLI} sheet ../test/worldcitiespop_mil.csv" ENTER && \
sleep 0.5 && \
tmux send-keys -t $@ "t" "hello" Enter && \
tmux capture-pane -t $@ -p > ${TMP_DIR}/$@.out && \
tmux kill-session -t $@ && \
cmp ${TMP_DIR}/$@.out test/expected/$@.out && ${TEST_PASS} || (echo 'Incorrect output:' && \
if [ -f ${TMP_DIR}/$@.out ]; then cat ${TMP_DIR}/$@.out; fi && ${TEST_FAIL}))

test-4: test-%: ${CLI} ${TARGET}
@${RUN_CLI} unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${RUN_CLI} license > /tmp/zsvext-$@.out 2>> /tmp/zsvext-$@.err
Expand Down
2 changes: 1 addition & 1 deletion app/ext_example/my_extension.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ enum zsv_ext_status zsv_ext_init(struct zsv_ext_callbacks *cb, zsv_execution_con
zsv_cb.ext_add_command(ctx, "echo", "print the input data back to stdout", echo_main);

#ifdef ZSVSHEET_BUILD
int proc_id = zsv_cb.ext_sheet_register_proc("my-test-command", my_test_command_handler);
int proc_id = zsv_cb.ext_sheet_register_proc("my-test-command", "my test command", my_test_command_handler);
if (proc_id < 0)
return zsv_ext_status_error;
zsv_cb.ext_sheet_register_proc_key_binding('t', proc_id);
Expand Down
5 changes: 5 additions & 0 deletions app/ext_example/test/expected/test-sheet-extension.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Row # buffer # file name
1 2 ../test/worldcitiespop_mi


? for help 1
3 changes: 2 additions & 1 deletion app/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,14 @@ TEST_DATA_DIR=${THIS_LIB_BASE}/data
SOURCES=echo count count-pull select select-pull sql 2json serialize flatten pretty desc stack 2db 2tsv jq compare overwrite
TARGETS=$(addprefix ${BUILD_DIR}/bin/zsv_,$(addsuffix ${EXE},${SOURCES}))

TESTS=test-blank-leading-rows $(addprefix test-,${SOURCES}) test-rm test-mv test-2json-help test-sheet test-paste
TESTS=test-blank-leading-rows $(addprefix test-,${SOURCES}) test-rm test-mv test-2json-help test-paste

ifeq ($(ZSV_BUILD_SHEET),1)
SOURCES+=sheet
CFLAGS+=-DZSV_BUILD_SHEET
CFLAGS+=${CFLAGS_NCURSES}
LDFLAGS+=${LDFLAGS_NCURSES}
TESTS+=test-sheet
endif

COLOR_NONE=\033[0m
Expand Down
2 changes: 1 addition & 1 deletion include/zsv/ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ struct zsv_ext_callbacks {
/****************************************
* Registering a custom `sheet` command *
****************************************/
zsvsheet_proc_id_t (*ext_sheet_register_proc)(const char *name,
zsvsheet_proc_id_t (*ext_sheet_register_proc)(const char *name, const char *description,
zsvsheet_status (*handler)(zsvsheet_proc_context_t ctx));

/**
Expand Down

0 comments on commit aed475d

Please sign in to comment.