From 5f8b7d32c10120925de485fd0f5560af1a65100b Mon Sep 17 00:00:00 2001 From: liquidaty Date: Sun, 17 Nov 2024 00:09:03 -0800 Subject: [PATCH 1/6] sheet extension: fix example breakage, add test --- app/ext_example/Makefile | 18 +++++++++++++++++- app/ext_example/my_extension.c | 2 +- .../test/expected/test-sheet-extension.out | 5 +++++ include/zsv/ext.h | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 app/ext_example/test/expected/test-sheet-extension.out diff --git a/app/ext_example/Makefile b/app/ext_example/Makefile index dacbcba4..e3368af5 100644 --- a/app/ext_example/Makefile +++ b/app/ext_example/Makefile @@ -111,7 +111,7 @@ ${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 +test: test-1 test-2 test-3 test-4 test-5 test-thirdparty test-sheet-extension test-1: test-%: ${CLI} ${TARGET} @${RUN_CLI} my-echo < ${THIS_LIB_BASE}/data/quoted.csv > /tmp/zsvext-$@.out @@ -132,6 +132,22 @@ 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 +test-sheet-extension: ../test/worldcitiespop_mil.csv + @rm -f ${TMP_DIR}/zsvext-$@.out + @tmux kill-session -t $@ || echo + @${RUN_CLI} unregister my 2>/dev/null 1>/dev/null || [ 1==1 ] + @${RUN_CLI} register my 2>&1 | grep -v [.]so || [ 1==1 ] + @(tmux new-session -x 80 -y 5 -d -s $@ "${RUN_CLI} sheet ../test/worldcitiespop_mil.csv" && \ + 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} || ${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 diff --git a/app/ext_example/my_extension.c b/app/ext_example/my_extension.c index 95cf6660..7e409fc3 100644 --- a/app/ext_example/my_extension.c +++ b/app/ext_example/my_extension.c @@ -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); diff --git a/app/ext_example/test/expected/test-sheet-extension.out b/app/ext_example/test/expected/test-sheet-extension.out new file mode 100644 index 00000000..f14dde45 --- /dev/null +++ b/app/ext_example/test/expected/test-sheet-extension.out @@ -0,0 +1,5 @@ +Row # buffer # file name +1 2 ../test/worldcitiespop_mi + + +? for help 1 diff --git a/include/zsv/ext.h b/include/zsv/ext.h index 2ca1e3eb..3c9a9ec7 100644 --- a/include/zsv/ext.h +++ b/include/zsv/ext.h @@ -158,6 +158,7 @@ struct zsv_ext_callbacks { * Registering a custom `sheet` command * ****************************************/ zsvsheet_proc_id_t (*ext_sheet_register_proc)(const char *name, + const char *description, zsvsheet_status (*handler)(zsvsheet_proc_context_t ctx)); /** From 0768886a995f92ed5021ad2178bf7a25d5e73754 Mon Sep 17 00:00:00 2001 From: liquidaty Date: Sun, 17 Nov 2024 00:11:06 -0800 Subject: [PATCH 2/6] clang-format --- include/zsv/ext.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/zsv/ext.h b/include/zsv/ext.h index 3c9a9ec7..5d71d238 100644 --- a/include/zsv/ext.h +++ b/include/zsv/ext.h @@ -157,8 +157,7 @@ struct zsv_ext_callbacks { /**************************************** * Registering a custom `sheet` command * ****************************************/ - zsvsheet_proc_id_t (*ext_sheet_register_proc)(const char *name, - const char *description, + zsvsheet_proc_id_t (*ext_sheet_register_proc)(const char *name, const char *description, zsvsheet_status (*handler)(zsvsheet_proc_context_t ctx)); /** From 222136670e34e957cd4959a185a113f4b496e2b9 Mon Sep 17 00:00:00 2001 From: liquidaty Date: Sun, 17 Nov 2024 09:07:56 -0800 Subject: [PATCH 3/6] test-sheet-extension: more verbose output on fail --- app/ext_example/Makefile | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/ext_example/Makefile b/app/ext_example/Makefile index e3368af5..5a68ef2f 100644 --- a/app/ext_example/Makefile +++ b/app/ext_example/Makefile @@ -136,17 +136,22 @@ test-3: test-%: ${CLI} ${TARGET} 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 kill-session -t $@ || echo + @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 ] - @(tmux new-session -x 80 -y 5 -d -s $@ "${RUN_CLI} sheet ../test/worldcitiespop_mil.csv" && \ + @echo 'set-option default-terminal "${TMUX_TERM}"' > ~/.tmux.conf + @(tmux -v new-session -x 80 -y 5 -d -s $@ && \ + sleep 0.5 && \ + tmux send-keys -t $@ "${RUN_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} || ${TEST_FAIL}) + cmp ${TMP_DIR}/$@.out test/expected/$@.out && ${TEST_PASS} || (echo 'Incorrect output:' && \ + if [ -f ${TMP_DIR}/$@.out ]; then cat ${TMP_DIR}/$@.out; fi && for x in `ls tmux-*.log` ; do echo "Log $$x:" && cat $$x ; done && ${TEST_FAIL})) test-4: test-%: ${CLI} ${TARGET} @${RUN_CLI} unregister my 2>/dev/null 1>/dev/null || [ 1==1 ] From 25771b82d377478125f2807ef7388034b6f840a5 Mon Sep 17 00:00:00 2001 From: liquidaty Date: Sun, 17 Nov 2024 09:17:13 -0800 Subject: [PATCH 4/6] test-sheet-extension: change how env var is set to work in BSD --- app/ext_example/Makefile | 10 ++++++++-- app/test/Makefile | 3 ++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/ext_example/Makefile b/app/ext_example/Makefile index 5a68ef2f..bfd1ffb7 100644 --- a/app/ext_example/Makefile +++ b/app/ext_example/Makefile @@ -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 test-sheet-extension +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 @@ -145,7 +150,8 @@ test-sheet-extension: ../test/worldcitiespop_mil.csv @echo 'set-option default-terminal "${TMUX_TERM}"' > ~/.tmux.conf @(tmux -v new-session -x 80 -y 5 -d -s $@ && \ sleep 0.5 && \ - tmux send-keys -t $@ "${RUN_CLI} sheet ../test/worldcitiespop_mil.csv" ENTER && \ + tmux setenv ZSV_CONFIG_DIR /tmp && \ + 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 && \ diff --git a/app/test/Makefile b/app/test/Makefile index d2bb844e..f0b388d5 100644 --- a/app/test/Makefile +++ b/app/test/Makefile @@ -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 From 6cb351ca4f9707fd5c787dc5fc92966d2d873c75 Mon Sep 17 00:00:00 2001 From: liquidaty Date: Sun, 17 Nov 2024 09:38:44 -0800 Subject: [PATCH 5/6] try again --- app/ext_example/Makefile | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/ext_example/Makefile b/app/ext_example/Makefile index bfd1ffb7..94fb22e2 100644 --- a/app/ext_example/Makefile +++ b/app/ext_example/Makefile @@ -150,8 +150,7 @@ test-sheet-extension: ../test/worldcitiespop_mil.csv @echo 'set-option default-terminal "${TMUX_TERM}"' > ~/.tmux.conf @(tmux -v new-session -x 80 -y 5 -d -s $@ && \ sleep 0.5 && \ - tmux setenv ZSV_CONFIG_DIR /tmp && \ - tmux send-keys -t $@ "${CLI} sheet ../test/worldcitiespop_mil.csv" ENTER && \ + ZSV_CONFIG_DIR=/tmp 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 && \ From dc8eb7194bd4a388e445a5dba8eb8d845610f45d Mon Sep 17 00:00:00 2001 From: liquidaty Date: Sun, 17 Nov 2024 09:52:50 -0800 Subject: [PATCH 6/6] again x2 --- app/ext_example/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/ext_example/Makefile b/app/ext_example/Makefile index 94fb22e2..49fce34c 100644 --- a/app/ext_example/Makefile +++ b/app/ext_example/Makefile @@ -148,15 +148,15 @@ test-sheet-extension: ../test/worldcitiespop_mil.csv @${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 - @(tmux -v new-session -x 80 -y 5 -d -s $@ && \ + @(ZSV_CONFIG_DIR=/tmp tmux -v new-session -x 80 -y 5 -d -s $@ && \ sleep 0.5 && \ - ZSV_CONFIG_DIR=/tmp tmux send-keys -t $@ "${CLI} sheet ../test/worldcitiespop_mil.csv" ENTER && \ + 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 && for x in `ls tmux-*.log` ; do echo "Log $$x:" && cat $$x ; done && ${TEST_FAIL})) + 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 ]