Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sheet extension: fix example breakage, add test #291

Merged
merged 6 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]
Expand All @@ -132,6 +137,27 @@ test-3: test-%: ${CLI} ${TARGET}
@${RUN_CLI} help 2>&1 | grep -v [.]so >> /tmp/[email protected] || [ 1==1 ]
@cmp /tmp/[email protected] 2>&1 test/expected/[email protected] && ${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}/[email protected] 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}/[email protected] && \
tmux kill-session -t $@ && \
cmp ${TMP_DIR}/[email protected] test/expected/[email protected] && ${TEST_PASS} || (echo 'Incorrect output:' && \
if [ -f ${TMP_DIR}/[email protected] ]; then cat ${TMP_DIR}/[email protected]; fi && ${TEST_FAIL}))

test-4: test-%: ${CLI} ${TARGET}
@${RUN_CLI} unregister my 2>/dev/null 1>/dev/null || [ 1==1 ]
@${RUN_CLI} license > /tmp/[email protected] 2>> /tmp/[email protected]
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