From 349bc58cf6d025e4e50a325bda48d318b23b55fb Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 27 Feb 2015 15:55:46 +0000 Subject: [PATCH] Reorganize lua tests. --- test/CMakeLists.txt | 14 ++++- test/{ => lua}/busted.lua | 0 test/{ => lua}/busted/compatibility.lua | 0 test/{ => lua}/busted/context.lua | 0 test/{ => lua}/busted/core.lua | 0 test/{ => lua}/busted/done.lua | 0 test/{ => lua}/busted/environment.lua | 0 test/{ => lua}/busted/init.lua | 0 test/{ => lua}/busted/languages/ar.lua | 0 test/{ => lua}/busted/languages/de.lua | 0 test/{ => lua}/busted/languages/en.lua | 0 test/{ => lua}/busted/languages/fr.lua | 0 test/{ => lua}/busted/languages/ja.lua | 0 test/{ => lua}/busted/languages/nl.lua | 0 test/{ => lua}/busted/languages/ru.lua | 0 test/{ => lua}/busted/languages/th.lua | 0 test/{ => lua}/busted/languages/ua.lua | 0 test/{ => lua}/busted/languages/zh.lua | 0 .../busted/modules/configuration_loader.lua | 0 test/{ => lua}/busted/modules/files/lua.lua | 0 .../busted/modules/files/moonscript.lua | 0 test/{ => lua}/busted/modules/files/terra.lua | 0 .../busted/modules/helper_loader.lua | 0 test/{ => lua}/busted/modules/luacov.lua | 0 .../busted/modules/output_handler_loader.lua | 0 .../busted/modules/test_file_loader.lua | 0 test/{ => lua}/busted/outputHandlers/TAP.lua | 0 test/{ => lua}/busted/outputHandlers/base.lua | 0 test/{ => lua}/busted/outputHandlers/json.lua | 0 .../{ => lua}/busted/outputHandlers/junit.lua | 0 .../busted/outputHandlers/plainTerminal.lua | 0 .../{ => lua}/busted/outputHandlers/sound.lua | 0 .../busted/outputHandlers/utfTerminal.lua | 0 test/{ => lua}/busted/runner.lua | 0 test/{ => lua}/busted/status.lua | 0 test/{ => lua}/busted/utils.lua | 0 test/lua/rsa.lua | 60 +++++++++++-------- test/rspamd_lua_test.c | 10 ++++ 38 files changed, 55 insertions(+), 29 deletions(-) rename test/{ => lua}/busted.lua (100%) rename test/{ => lua}/busted/compatibility.lua (100%) rename test/{ => lua}/busted/context.lua (100%) rename test/{ => lua}/busted/core.lua (100%) rename test/{ => lua}/busted/done.lua (100%) rename test/{ => lua}/busted/environment.lua (100%) rename test/{ => lua}/busted/init.lua (100%) rename test/{ => lua}/busted/languages/ar.lua (100%) rename test/{ => lua}/busted/languages/de.lua (100%) rename test/{ => lua}/busted/languages/en.lua (100%) rename test/{ => lua}/busted/languages/fr.lua (100%) rename test/{ => lua}/busted/languages/ja.lua (100%) rename test/{ => lua}/busted/languages/nl.lua (100%) rename test/{ => lua}/busted/languages/ru.lua (100%) rename test/{ => lua}/busted/languages/th.lua (100%) rename test/{ => lua}/busted/languages/ua.lua (100%) rename test/{ => lua}/busted/languages/zh.lua (100%) rename test/{ => lua}/busted/modules/configuration_loader.lua (100%) rename test/{ => lua}/busted/modules/files/lua.lua (100%) rename test/{ => lua}/busted/modules/files/moonscript.lua (100%) rename test/{ => lua}/busted/modules/files/terra.lua (100%) rename test/{ => lua}/busted/modules/helper_loader.lua (100%) rename test/{ => lua}/busted/modules/luacov.lua (100%) rename test/{ => lua}/busted/modules/output_handler_loader.lua (100%) rename test/{ => lua}/busted/modules/test_file_loader.lua (100%) rename test/{ => lua}/busted/outputHandlers/TAP.lua (100%) rename test/{ => lua}/busted/outputHandlers/base.lua (100%) rename test/{ => lua}/busted/outputHandlers/json.lua (100%) rename test/{ => lua}/busted/outputHandlers/junit.lua (100%) rename test/{ => lua}/busted/outputHandlers/plainTerminal.lua (100%) rename test/{ => lua}/busted/outputHandlers/sound.lua (100%) rename test/{ => lua}/busted/outputHandlers/utfTerminal.lua (100%) rename test/{ => lua}/busted/runner.lua (100%) rename test/{ => lua}/busted/status.lua (100%) rename test/{ => lua}/busted/utils.lua (100%) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9932fb87d..32d5334cb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -23,9 +23,17 @@ TARGET_LINK_LIBRARIES(rspamd-test ${RSPAMD_REQUIRED_LIBRARIES}) TARGET_LINK_LIBRARIES(rspamd-test stemmer) IF(NOT ${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) - FILE(COPY "${CMAKE_CURRENT_SOURCE_DIR}/busted.lua" - "${CMAKE_CURRENT_SOURCE_DIR}/busted" - "${CMAKE_CURRENT_SOURCE_DIR}/lua" + FILE(COPY "${CMAKE_CURRENT_SOURCE_DIR}/lua" DESTINATION ${CMAKE_CURRENT_BINARY_DIR}) + + # Also add dependencies for convenience + FILE(GLOB LUA_TESTS "${CMAKE_CURRENT_SOURCE_DIR}/lua/*") + FOREACH(_LF IN LISTS "${LUA_TESTS}") + GET_FILENAME_COMPONENT(_NM _LF NAME) + ADD_CUSTOM_COMMAND(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${_NM}" + "${CMAKE_COMMAND} -E copy_if_different ${_LF} ${CMAKE_CURRENT_BINARY_DIR}/${_NM}" + ) + ADD_DEPENDENCIES(rspamd-test "${CMAKE_CURRENT_BINARY_DIR}/${_NM}") + ENDFOREACH() ENDIF() \ No newline at end of file diff --git a/test/busted.lua b/test/lua/busted.lua similarity index 100% rename from test/busted.lua rename to test/lua/busted.lua diff --git a/test/busted/compatibility.lua b/test/lua/busted/compatibility.lua similarity index 100% rename from test/busted/compatibility.lua rename to test/lua/busted/compatibility.lua diff --git a/test/busted/context.lua b/test/lua/busted/context.lua similarity index 100% rename from test/busted/context.lua rename to test/lua/busted/context.lua diff --git a/test/busted/core.lua b/test/lua/busted/core.lua similarity index 100% rename from test/busted/core.lua rename to test/lua/busted/core.lua diff --git a/test/busted/done.lua b/test/lua/busted/done.lua similarity index 100% rename from test/busted/done.lua rename to test/lua/busted/done.lua diff --git a/test/busted/environment.lua b/test/lua/busted/environment.lua similarity index 100% rename from test/busted/environment.lua rename to test/lua/busted/environment.lua diff --git a/test/busted/init.lua b/test/lua/busted/init.lua similarity index 100% rename from test/busted/init.lua rename to test/lua/busted/init.lua diff --git a/test/busted/languages/ar.lua b/test/lua/busted/languages/ar.lua similarity index 100% rename from test/busted/languages/ar.lua rename to test/lua/busted/languages/ar.lua diff --git a/test/busted/languages/de.lua b/test/lua/busted/languages/de.lua similarity index 100% rename from test/busted/languages/de.lua rename to test/lua/busted/languages/de.lua diff --git a/test/busted/languages/en.lua b/test/lua/busted/languages/en.lua similarity index 100% rename from test/busted/languages/en.lua rename to test/lua/busted/languages/en.lua diff --git a/test/busted/languages/fr.lua b/test/lua/busted/languages/fr.lua similarity index 100% rename from test/busted/languages/fr.lua rename to test/lua/busted/languages/fr.lua diff --git a/test/busted/languages/ja.lua b/test/lua/busted/languages/ja.lua similarity index 100% rename from test/busted/languages/ja.lua rename to test/lua/busted/languages/ja.lua diff --git a/test/busted/languages/nl.lua b/test/lua/busted/languages/nl.lua similarity index 100% rename from test/busted/languages/nl.lua rename to test/lua/busted/languages/nl.lua diff --git a/test/busted/languages/ru.lua b/test/lua/busted/languages/ru.lua similarity index 100% rename from test/busted/languages/ru.lua rename to test/lua/busted/languages/ru.lua diff --git a/test/busted/languages/th.lua b/test/lua/busted/languages/th.lua similarity index 100% rename from test/busted/languages/th.lua rename to test/lua/busted/languages/th.lua diff --git a/test/busted/languages/ua.lua b/test/lua/busted/languages/ua.lua similarity index 100% rename from test/busted/languages/ua.lua rename to test/lua/busted/languages/ua.lua diff --git a/test/busted/languages/zh.lua b/test/lua/busted/languages/zh.lua similarity index 100% rename from test/busted/languages/zh.lua rename to test/lua/busted/languages/zh.lua diff --git a/test/busted/modules/configuration_loader.lua b/test/lua/busted/modules/configuration_loader.lua similarity index 100% rename from test/busted/modules/configuration_loader.lua rename to test/lua/busted/modules/configuration_loader.lua diff --git a/test/busted/modules/files/lua.lua b/test/lua/busted/modules/files/lua.lua similarity index 100% rename from test/busted/modules/files/lua.lua rename to test/lua/busted/modules/files/lua.lua diff --git a/test/busted/modules/files/moonscript.lua b/test/lua/busted/modules/files/moonscript.lua similarity index 100% rename from test/busted/modules/files/moonscript.lua rename to test/lua/busted/modules/files/moonscript.lua diff --git a/test/busted/modules/files/terra.lua b/test/lua/busted/modules/files/terra.lua similarity index 100% rename from test/busted/modules/files/terra.lua rename to test/lua/busted/modules/files/terra.lua diff --git a/test/busted/modules/helper_loader.lua b/test/lua/busted/modules/helper_loader.lua similarity index 100% rename from test/busted/modules/helper_loader.lua rename to test/lua/busted/modules/helper_loader.lua diff --git a/test/busted/modules/luacov.lua b/test/lua/busted/modules/luacov.lua similarity index 100% rename from test/busted/modules/luacov.lua rename to test/lua/busted/modules/luacov.lua diff --git a/test/busted/modules/output_handler_loader.lua b/test/lua/busted/modules/output_handler_loader.lua similarity index 100% rename from test/busted/modules/output_handler_loader.lua rename to test/lua/busted/modules/output_handler_loader.lua diff --git a/test/busted/modules/test_file_loader.lua b/test/lua/busted/modules/test_file_loader.lua similarity index 100% rename from test/busted/modules/test_file_loader.lua rename to test/lua/busted/modules/test_file_loader.lua diff --git a/test/busted/outputHandlers/TAP.lua b/test/lua/busted/outputHandlers/TAP.lua similarity index 100% rename from test/busted/outputHandlers/TAP.lua rename to test/lua/busted/outputHandlers/TAP.lua diff --git a/test/busted/outputHandlers/base.lua b/test/lua/busted/outputHandlers/base.lua similarity index 100% rename from test/busted/outputHandlers/base.lua rename to test/lua/busted/outputHandlers/base.lua diff --git a/test/busted/outputHandlers/json.lua b/test/lua/busted/outputHandlers/json.lua similarity index 100% rename from test/busted/outputHandlers/json.lua rename to test/lua/busted/outputHandlers/json.lua diff --git a/test/busted/outputHandlers/junit.lua b/test/lua/busted/outputHandlers/junit.lua similarity index 100% rename from test/busted/outputHandlers/junit.lua rename to test/lua/busted/outputHandlers/junit.lua diff --git a/test/busted/outputHandlers/plainTerminal.lua b/test/lua/busted/outputHandlers/plainTerminal.lua similarity index 100% rename from test/busted/outputHandlers/plainTerminal.lua rename to test/lua/busted/outputHandlers/plainTerminal.lua diff --git a/test/busted/outputHandlers/sound.lua b/test/lua/busted/outputHandlers/sound.lua similarity index 100% rename from test/busted/outputHandlers/sound.lua rename to test/lua/busted/outputHandlers/sound.lua diff --git a/test/busted/outputHandlers/utfTerminal.lua b/test/lua/busted/outputHandlers/utfTerminal.lua similarity index 100% rename from test/busted/outputHandlers/utfTerminal.lua rename to test/lua/busted/outputHandlers/utfTerminal.lua diff --git a/test/busted/runner.lua b/test/lua/busted/runner.lua similarity index 100% rename from test/busted/runner.lua rename to test/lua/busted/runner.lua diff --git a/test/busted/status.lua b/test/lua/busted/status.lua similarity index 100% rename from test/busted/status.lua rename to test/lua/busted/status.lua diff --git a/test/busted/utils.lua b/test/lua/busted/utils.lua similarity index 100% rename from test/busted/utils.lua rename to test/lua/busted/utils.lua diff --git a/test/lua/rsa.lua b/test/lua/rsa.lua index 83a6a9e45..073062fd1 100644 --- a/test/lua/rsa.lua +++ b/test/lua/rsa.lua @@ -1,39 +1,47 @@ -- Test rsa signing -local pubkey = 'testkey.pub' -local privkey = 'testkey' -local data = 'test.data' -local signature = 'test.sig' +require "busted" () --- Signing test -local rsa_key = rsa_privkey.load(string.format('%s/%s', test_dir, privkey)) +describe("rsa signarture test", function() + local rsa_privkey = require "rspamd_rsa_privkey" + local rsa_pubkey = require "rspamd_rsa_pubkey" + local rsa_signature = require "rspamd_rsa_signature" + local rsa = require "rspamd_rsa" + local pubkey = 'testkey.pub' + local privkey = 'testkey' + local data = 'test.data' + local signature = 'test.sig' -if not rsa_key then - return -1 -end + -- Signing test + local rsa_key = rsa_privkey.load(string.format('%s/%s', test_dir, privkey)) -local rsa_sig = rsa.sign_file(rsa_key, string.format('%s/%s', test_dir, data)) + if not rsa_key then + return -1 + end -if not rsa_sig then - return -1 -end + local rsa_sig = rsa.sign_file(rsa_key, string.format('%s/%s', test_dir, data)) -rsa_sig:save(string.format('%s/%s', test_dir, signature), true) + if not rsa_sig then + return -1 + end --- Verifying test -rsa_key = rsa_pubkey.load(string.format('%s/%s', test_dir, pubkey)) + rsa_sig:save(string.format('%s/%s', test_dir, signature), true) -if not rsa_key then - return -1 -end + -- Verifying test + rsa_key = rsa_pubkey.load(string.format('%s/%s', test_dir, pubkey)) -rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature)) + if not rsa_key then + return -1 + end -if not rsa_sig then - return -1 -end + rsa_sig = rsa_signature.load(string.format('%s/%s', test_dir, signature)) -if not rsa.verify_file(rsa_key, rsa_sig, string.format('%s/%s', test_dir, data)) then - return -1 -end + if not rsa_sig then + return -1 + end + if not rsa.verify_file(rsa_key, rsa_sig, string.format('%s/%s', test_dir, data)) then + return -1 + end + +end) diff --git a/test/rspamd_lua_test.c b/test/rspamd_lua_test.c index 46303b356..da9405fa5 100644 --- a/test/rspamd_lua_test.c +++ b/test/rspamd_lua_test.c @@ -37,6 +37,7 @@ rspamd_lua_test_func (void) glob_t globbuf; gchar *pattern; guint i, len; + struct stat st; msg_info ("Starting lua tests"); @@ -54,6 +55,15 @@ rspamd_lua_test_func (void) for (i = 0; i < globbuf.gl_pathc; i++) { lua_file = globbuf.gl_pathv[i]; + if (stat (lua_file, &st) == -1 || !S_ISREG (st.st_mode)) { + continue; + } + + if (strstr (lua_file, "busted") != NULL) { + /* Skip busted code itself */ + continue; + } + if (luaL_loadfile (L, lua_file) != 0) { msg_err ("load test from %s failed", lua_file); g_assert (0); -- 2.39.5