<HTML><BODY><div>Hi!</div><div>Thanks for the patch!</div><div>It, generally, LGTM, but with concerns about the skipcond-like<br>implementation, I mentioned in review for the previous commit.</div><div data-signature-widget="container"><div data-signature-widget="content"><div>--<br>Best regards,</div><div>Maxim Kokryashkin</div></div></div><div> </div><div> </div><blockquote style="border-left:1px solid #0857A6; margin:10px; padding:0 0 0 10px;">Среда, 15 марта 2023, 19:14 +03:00 от Sergey Kaplun <skaplun@tarantool.org>:<br> <div id=""><div class="js-helper js-readmsg-msg"><div><div id="style_16788968920463036309_BODY">This header contains generic init and close for tests and helpers for<br>loading auxiliary Lua script with functions to run inside a C test.<br><br>It will be properly used in the next commit.<br><br>Part of tarantool/tarantool#7900<br>---<br><br>Those introduced utils macros assume that we have the table on the top<br>of the Lua stack. So, after each test the stack should be stayed<br>"untouched". But if we push helper function or some value of the Lua<br>stack and them assertion fails, we exit from function without stack<br>cleaning. So we should try to avoid such situation whenever appropriate,<br>but don't be fanatical at this point -- if some assertion fails, we are<br>in troubles anyway.<br><br>Don't use __FILE__ here, because it may contain relative path to the<br>file depending on CMake version or -fmacro-prefix-map= flag.<br><br> test/tarantool-c-tests/utils.h | 63 ++++++++++++++++++++++++++++++++++<br> 1 file changed, 63 insertions(+)<br> create mode 100644 test/tarantool-c-tests/utils.h<br><br>diff --git a/test/tarantool-c-tests/utils.h b/test/tarantool-c-tests/utils.h<br>new file mode 100644<br>index 00000000..cf668006<br>--- /dev/null<br>+++ b/test/tarantool-c-tests/utils.h<br>@@ -0,0 +1,63 @@<br>+#include <limits.h><br>+#include <string.h><br>+<br>+#include "lauxlib.h"<br>+#include "lua.h"<br>+#include "luajit.h"<br>+#include "lualib.h"<br>+<br>+#include "test.h"<br>+<br>+/* Generic init for our tests. */<br>+static lua_State *utils_lua_init(void)<br>+{<br>+ lua_State *L = luaL_newstate();<br>+ if (!L)<br>+ bail_out("Can't init Lua state");<br>+ /* Stop collector during library initialization. */<br>+ lua_gc(L, LUA_GCSTOP, 0);<br>+ luaL_openlibs(L);<br>+ lua_gc(L, LUA_GCRESTART, -1);<br>+ return L;<br>+}<br>+<br>+/* Generic close for our tests. */<br>+static void utils_lua_close(lua_State *L)<br>+{<br>+ lua_close(L);<br>+}<br>+<br>+/*<br>+ * Load the pair to the test file <filename-script.lua>.<br>+ * Each file should return the table with functions (named the<br>+ * same as the corresponding unit tests) to call in unit tests.<br>+ * Push the table with those functions on the Lua stack.<br>+ */<br>+#define utils_load_aux_script(L) do { \<br>+ /* \<br>+ * Format script name. \<br>+ * `__ABS_FILENAME__` is set via CMake. \<br>+ */ \<br>+ char script[PATH_MAX] = __ABS_FILENAME__; \<br>+ char *file_suffix = strstr(script, ".test.c"); \<br>+ strcpy(file_suffix, "-script.lua"); \<br>+ \<br>+ if (luaL_dofile((L), script) != LUA_OK) { \<br>+ test_comment("Can't load %s: '%s'", script, \<br>+ lua_tostring((L), -1)); \<br>+ bail_out("Can't load auxiliary script"); \<br>+ } \<br>+ \<br>+ if (!lua_istable((L), -1)) \<br>+ bail_out("Returned value from script is not a table"); \<br>+} while (0)<br>+<br>+/*<br>+ * Accept a table on top of the Lua stack which containing the<br>+ * function named as the unit test we currently executing.<br>+ */<br>+#define utils_get_aux_lfunc(L) do { \<br>+ lua_getfield((L), -1, __func__); \<br>+ if (!lua_isfunction((L), -1)) \<br>+ bail_out("Can't get auxiliary test function"); \<br>+} while (0)<br>--<br>2.34.1</div></div></div></div></blockquote><div> </div></BODY></HTML>