Mercurial > irccd
changeset 532:c59b87f66b67
CMake: share same resources, closes #725
author | David Demelier <markand@malikania.fr> |
---|---|
date | Thu, 16 Nov 2017 23:59:37 +0100 |
parents | d71c59eb04c3 |
children | d5b6dd7c2311 |
files | cmake/function/IrccdDefineTest.cmake libirccd-test/irccd/js_test.hpp tests/CMakeLists.txt tests/js-directory/main.cpp tests/js-file/CMakeLists.txt tests/js-file/main.cpp tests/js/main.cpp tests/plugin-history/main.cpp tests/plugin-logger/main.cpp tests/root/file-1.txt tests/root/level-1/level-2/file-2.txt tests/root/lines.txt tests/util/main.cpp |
diffstat | 13 files changed, 59 insertions(+), 121 deletions(-) [+] |
line wrap: on
line diff
--- a/cmake/function/IrccdDefineTest.cmake Thu Nov 16 23:55:19 2017 +0100 +++ b/cmake/function/IrccdDefineTest.cmake Thu Nov 16 23:59:37 2017 +0100 @@ -71,13 +71,10 @@ PRIVATE ${TEST_FLAGS} BOOST_TEST_DYN_LINK + CMAKE_BINARY_DIR="${CMAKE_BINARY_DIR}" CMAKE_SOURCE_DIR="${CMAKE_SOURCE_DIR}" CMAKE_CURRENT_BINARY_DIR="${CMAKE_CURRENT_BINARY_DIR}" CMAKE_CURRENT_SOURCE_DIR="${CMAKE_CURRENT_SOURCE_DIR}" - TESTS_BINARY_DIR="${tests_BINARY_DIR}" - SOURCEDIR="${CMAKE_CURRENT_SOURCE_DIR}" - BINARYDIR="${CMAKE_CURRENT_BINARY_DIR}" - IRCCD_TESTS_DIRECTORY="${CMAKE_BINARY_DIR}/tests" ) # Tests are all in the same directory
--- a/libirccd-test/irccd/js_test.hpp Thu Nov 16 23:55:19 2017 +0100 +++ b/libirccd-test/irccd/js_test.hpp Thu Nov 16 23:59:37 2017 +0100 @@ -74,8 +74,14 @@ plugin_->on_load(irccd_); // Add some CMake variables. - duk_push_string(plugin_->context(), TESTS_BINARY_DIR); - duk_put_global_string(plugin_->context(), "TESTS_BINARY_DIR"); + duk_push_string(plugin_->context(), CMAKE_BINARY_DIR); + duk_put_global_string(plugin_->context(), "CMAKE_BINARY_DIR"); + duk_push_string(plugin_->context(), CMAKE_SOURCE_DIR); + duk_put_global_string(plugin_->context(), "CMAKE_SOURCE_DIR"); + duk_push_string(plugin_->context(), CMAKE_CURRENT_BINARY_DIR); + duk_put_global_string(plugin_->context(), "CMAKE_CURRENT_BINARY_DIR"); + duk_push_string(plugin_->context(), CMAKE_CURRENT_SOURCE_DIR); + duk_put_global_string(plugin_->context(), "CMAKE_CURRENT_SOURCE_DIR"); } };
--- a/tests/CMakeLists.txt Thu Nov 16 23:55:19 2017 +0100 +++ b/tests/CMakeLists.txt Thu Nov 16 23:59:37 2017 +0100 @@ -20,13 +20,6 @@ project(tests) if (WITH_TESTS) - # Create some hierarchy. - file(MAKE_DIRECTORY ${tests_BINARY_DIR}/root) - file(MAKE_DIRECTORY ${tests_BINARY_DIR}/root/level-a) - file(MAKE_DIRECTORY ${tests_BINARY_DIR}/root/level-a/level-1) - file(WRITE ${tests_BINARY_DIR}/root/file-1.txt "\n") - file(WRITE ${tests_BINARY_DIR}/root/level-a/level-1/file-2.txt) - # add_subdirectory(cmd-plugin-config) # add_subdirectory(cmd-plugin-info) # add_subdirectory(cmd-plugin-list)
--- a/tests/js-directory/main.cpp Thu Nov 16 23:55:19 2017 +0100 +++ b/tests/js-directory/main.cpp Thu Nov 16 23:59:37 2017 +0100 @@ -30,7 +30,7 @@ BOOST_AUTO_TEST_CASE(constructor) { const std::string script( - "d = new Irccd.Directory(TESTS_BINARY_DIR + \"/root\");" + "d = new Irccd.Directory(CMAKE_SOURCE_DIR + \"/tests/root\");" "p = d.path;" "l = d.entries.length;" ); @@ -39,7 +39,7 @@ throw dukx_exception(plugin_->context(), -1); duk_get_global_string(plugin_->context(), "l"); - BOOST_TEST(duk_get_int(plugin_->context(), -1) == 2); + BOOST_TEST(duk_get_int(plugin_->context(), -1) == 3); } BOOST_AUTO_TEST_SUITE_END()
--- a/tests/js-file/CMakeLists.txt Thu Nov 16 23:55:19 2017 +0100 +++ b/tests/js-file/CMakeLists.txt Thu Nov 16 23:59:37 2017 +0100 @@ -21,21 +21,3 @@ SOURCES main.cpp LIBRARIES libirccd-js ) - -# -# Create following tree: -# -# CMAKE_BINARY_DIR -# | tests -# | |-- file.txt -# | |-- lines.txt -# | |-- level-1 -# | | | -- file-1.txt -# | | | -- level-2 -# | | | | -- file-2.txt -# -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/tests/level-1/level-2) -file(WRITE ${CMAKE_BINARY_DIR}/tests/file.txt "file.txt") -file(WRITE ${CMAKE_BINARY_DIR}/tests/lines.txt "a\nb\nc\n") -file(WRITE ${CMAKE_BINARY_DIR}/tests/level-1/file-1.txt "file-1.txt") -file(WRITE ${CMAKE_BINARY_DIR}/tests/level-1/level-2/file-2.txt "file-2.txt")
--- a/tests/js-file/main.cpp Thu Nov 16 23:55:19 2017 +0100 +++ b/tests/js-file/main.cpp Thu Nov 16 23:59:37 2017 +0100 @@ -50,10 +50,7 @@ BOOST_AUTO_TEST_CASE(function_exists) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - - if (duk_peval_string(plugin_->context(), "result = Irccd.File.exists(directory + '/file.txt')")) + if (duk_peval_string(plugin_->context(), "result = Irccd.File.exists(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt')")) throw dukx_exception(plugin_->context(), -1); BOOST_TEST(duk_get_global_string(plugin_->context(), "result")); @@ -84,11 +81,8 @@ BOOST_AUTO_TEST_CASE(method_basename) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/level-1/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "result = f.basename();" ); @@ -101,11 +95,8 @@ BOOST_AUTO_TEST_CASE(method_basename_closed) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/level-1/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "f.close();" "result = f.basename();" ); @@ -119,11 +110,8 @@ BOOST_AUTO_TEST_CASE(method_dirname) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/level-1/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "result = f.dirname();" ); @@ -131,16 +119,13 @@ throw dukx_exception(plugin_->context(), -1); BOOST_TEST(duk_get_global_string(plugin_->context(), "result")); - BOOST_TEST(IRCCD_TESTS_DIRECTORY "/level-1" == duk_get_string(plugin_->context(), -1)); + BOOST_TEST(CMAKE_SOURCE_DIR "/tests/root" == duk_get_string(plugin_->context(), -1)); } BOOST_AUTO_TEST_CASE(method_dirname_closed) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/level-1/file-1.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "f.close();" "result = f.dirname();" ); @@ -149,16 +134,13 @@ throw dukx_exception(plugin_->context(), -1); BOOST_TEST(duk_get_global_string(plugin_->context(), "result")); - BOOST_TEST(IRCCD_TESTS_DIRECTORY "/level-1" == duk_get_string(plugin_->context(), -1)); + BOOST_TEST(CMAKE_SOURCE_DIR "/tests/root" == duk_get_string(plugin_->context(), -1)); } BOOST_AUTO_TEST_CASE(method_lines) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "result = new Irccd.File(directory + '/lines.txt', 'r').lines();" + "result = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/lines.txt', 'r').lines();" ); if (ret != 0) @@ -172,12 +154,9 @@ BOOST_AUTO_TEST_CASE(method_seek1) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/file.txt', 'r');" - "f.seek(Irccd.File.SeekSet, 4);" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" + "f.seek(Irccd.File.SeekSet, 6);" "result = f.read(1);" ); @@ -190,11 +169,8 @@ BOOST_AUTO_TEST_CASE(method_seek1_closed) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/file.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "f.close();" "f.seek(Irccd.File.SeekSet, 4);" "result = f.read(1);" @@ -210,13 +186,10 @@ BOOST_AUTO_TEST_CASE(method_seek2) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/file.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "f.seek(Irccd.File.SeekSet, 2);" - "f.seek(Irccd.File.SeekCur, 2);" + "f.seek(Irccd.File.SeekCur, 4);" "result = f.read(1);" ); @@ -229,11 +202,8 @@ BOOST_AUTO_TEST_CASE(method_seek2c_losed) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/file.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "f.close();" "f.seek(Irccd.File.SeekSet, 2);" "f.seek(Irccd.File.SeekCur, 2);" @@ -250,11 +220,8 @@ BOOST_AUTO_TEST_CASE(method_seek3) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/file.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "f.seek(Irccd.File.SeekEnd, -2);" "result = f.read(1);" ); @@ -263,16 +230,13 @@ throw dukx_exception(plugin_->context(), -1); BOOST_TEST(duk_get_global_string(plugin_->context(), "result")); - BOOST_TEST("x" == duk_get_string(plugin_->context(), -1)); + BOOST_TEST("t" == duk_get_string(plugin_->context(), -1)); } BOOST_AUTO_TEST_CASE(method_seek3_closed) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/file.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "f.close();" "f.seek(Irccd.File.SeekEnd, -2);" "result = f.read(1);" @@ -288,11 +252,8 @@ BOOST_AUTO_TEST_CASE(method_read1) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), - "f = new Irccd.File(directory + '/file.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/file-1.txt', 'r');" "result = f.read();" ); @@ -300,17 +261,14 @@ throw dukx_exception(plugin_->context(), -1); BOOST_TEST(duk_get_global_string(plugin_->context(), "result")); - BOOST_TEST("file.txt" == duk_get_string(plugin_->context(), -1)); + BOOST_TEST("file-1.txt\n" == duk_get_string(plugin_->context(), -1)); } BOOST_AUTO_TEST_CASE(method_readline) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), "result = [];" - "f = new Irccd.File(directory + '/lines.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/lines.txt', 'r');" "for (var s; s = f.readline(); ) {" " result.push(s);" "}" @@ -325,14 +283,11 @@ BOOST_TEST(expected == dukx_get_array(plugin_->context(), -1, dukx_get_std_string)); } -BOOST_AUTO_TEST_CASE(methodReadlineClosed) +BOOST_AUTO_TEST_CASE(method_readline_closed) { - duk_push_string(plugin_->context(), IRCCD_TESTS_DIRECTORY); - duk_put_global_string(plugin_->context(), "directory"); - auto ret = duk_peval_string(plugin_->context(), "result = [];" - "f = new Irccd.File(directory + '/lines.txt', 'r');" + "f = new Irccd.File(CMAKE_SOURCE_DIR + '/tests/root/lines.txt', 'r');" "f.close();" "for (var s; s = f.readline(); ) {" " result.push(s);"
--- a/tests/js/main.cpp Thu Nov 16 23:55:19 2017 +0100 +++ b/tests/js/main.cpp Thu Nov 16 23:59:37 2017 +0100 @@ -52,10 +52,10 @@ BOOST_AUTO_TEST_CASE(syntax_error) { - BOOST_REQUIRE_THROW(dukx_peval_file(ctx_, SOURCEDIR "/syntax-error.js"), Exception); + BOOST_REQUIRE_THROW(dukx_peval_file(ctx_, CMAKE_CURRENT_SOURCE_DIR "/syntax-error.js"), Exception); try { - dukx_peval_file(ctx_, SOURCEDIR "/syntax-error.js"); + dukx_peval_file(ctx_, CMAKE_CURRENT_SOURCE_DIR "/syntax-error.js"); } catch (const Exception& ex) { BOOST_REQUIRE_EQUAL("SyntaxError", ex.name); BOOST_REQUIRE_EQUAL("syntax-error.js", fs_util::base_name(ex.fileName));
--- a/tests/plugin-history/main.cpp Thu Nov 16 23:55:19 2017 +0100 +++ b/tests/plugin-history/main.cpp Thu Nov 16 23:59:37 2017 +0100 @@ -46,7 +46,7 @@ { // Add file if not there. if (config.count("file") == 0) - config.emplace("file", SOURCEDIR "/words.conf"); + config.emplace("file", CMAKE_CURRENT_SOURCE_DIR "/words.conf"); plugin_->set_config(config); plugin_->on_load(irccd_); @@ -57,7 +57,7 @@ BOOST_AUTO_TEST_CASE(format_error) { - load({{"file", SOURCEDIR "/broken-conf.json"}}); + load({{"file", CMAKE_CURRENT_SOURCE_DIR "/broken-conf.json"}}); plugin_->on_command(irccd_, {server_, "jean!jean@localhost", "#history", "seen francis"}); @@ -72,8 +72,8 @@ { const std::regex rule("seen=history:!history:test:#history:destructor!dst@localhost:destructor:jean:\\d{2}:\\d{2}"); - remove(BINARYDIR "/seen.json"); - load({{ "file", BINARYDIR "/seen.json" }}); + remove(CMAKE_CURRENT_BINARY_DIR "/seen.json"); + load({{ "file", CMAKE_CURRENT_BINARY_DIR "/seen.json" }}); plugin_->on_message(irccd_, {server_, "jean!jean@localhost", "#history", "hello"}); plugin_->on_command(irccd_, {server_, "destructor!dst@localhost", "#history", "seen jean"}); @@ -89,8 +89,8 @@ { std::regex rule("said=history:!history:test:#history:destructor!dst@localhost:destructor:jean:hello:\\d{2}:\\d{2}"); - remove(BINARYDIR "/said.json"); - load({{ "file", BINARYDIR "/said.json" }}); + remove(CMAKE_CURRENT_BINARY_DIR "/said.json"); + load({{ "file", CMAKE_CURRENT_BINARY_DIR "/said.json" }}); plugin_->on_message(irccd_, {server_, "jean!jean@localhost", "#history", "hello"}); plugin_->on_command(irccd_, {server_, "destructor!dst@localhost", "#history", "said jean"}); @@ -104,8 +104,8 @@ BOOST_AUTO_TEST_CASE(format_unknown) { - remove(BINARYDIR "/unknown.json"); - load({{ "file", BINARYDIR "/unknown.json" }}); + remove(CMAKE_CURRENT_BINARY_DIR "/unknown.json"); + load({{ "file", CMAKE_CURRENT_BINARY_DIR "/unknown.json" }}); plugin_->on_message(irccd_, {server_, "jean!jean@localhost", "#history", "hello"}); plugin_->on_command(irccd_, {server_, "destructor!dst@localhost", "#history", "seen nobody"}); @@ -121,8 +121,8 @@ { const std::regex rule("said=history:!history:test:#history:destructor!dst@localhost:destructor:jean:hello:\\d{2}:\\d{2}"); - remove(BINARYDIR "/case.json"); - load({{"file", BINARYDIR "/case.json"}}); + remove(CMAKE_CURRENT_BINARY_DIR "/case.json"); + load({{"file", CMAKE_CURRENT_BINARY_DIR "/case.json"}}); plugin_->on_message(irccd_, {server_, "JeaN!JeaN@localhost", "#history", "hello"});
--- a/tests/plugin-logger/main.cpp Thu Nov 16 23:55:19 2017 +0100 +++ b/tests/plugin-logger/main.cpp Thu Nov 16 23:59:37 2017 +0100 @@ -35,7 +35,7 @@ protected: std::string last() const { - std::ifstream file(BINARYDIR "/log.txt"); + std::ifstream file(CMAKE_CURRENT_BINARY_DIR "/log.txt"); return std::string(std::istreambuf_iterator<char>(file.rdbuf()), {}); } @@ -44,7 +44,7 @@ logger_test() : plugin_test(PLUGIN_NAME, PLUGIN_PATH) { - remove(BINARYDIR "/log.txt"); + remove(CMAKE_CURRENT_BINARY_DIR "/log.txt"); plugin_->set_formats({ { "cmode", "cmode=#{server}:#{channel}:#{origin}:#{nickname}:#{mode}:#{arg}" }, @@ -64,7 +64,7 @@ void load(plugin_config config = plugin_config()) { if (config.count("path") == 0) - config.emplace("path", BINARYDIR "/log.txt"); + config.emplace("path", CMAKE_CURRENT_BINARY_DIR "/log.txt"); plugin_->set_config(config); plugin_->on_load(irccd_);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/root/file-1.txt Thu Nov 16 23:59:37 2017 +0100 @@ -0,0 +1,1 @@ +file-1.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/root/level-1/level-2/file-2.txt Thu Nov 16 23:59:37 2017 +0100 @@ -0,0 +1,1 @@ +file-2.txt
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/root/lines.txt Thu Nov 16 23:59:37 2017 +0100 @@ -0,0 +1,3 @@ +a +b +c
--- a/tests/util/main.cpp Thu Nov 16 23:55:19 2017 +0100 +++ b/tests/util/main.cpp Thu Nov 16 23:59:37 2017 +0100 @@ -482,8 +482,8 @@ BOOST_AUTO_TEST_CASE(not_recursive) { - auto file1 = fs_util::find(TESTS_BINARY_DIR "/root", "file-1.txt", false); - auto file2 = fs_util::find(TESTS_BINARY_DIR "/root", "file-2.txt", false); + auto file1 = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", "file-1.txt", false); + auto file2 = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", "file-2.txt", false); BOOST_TEST(file1.find("file-1.txt") != std::string::npos); BOOST_TEST(file2.empty()); @@ -491,8 +491,8 @@ BOOST_AUTO_TEST_CASE(recursive) { - auto file1 = fs_util::find(TESTS_BINARY_DIR "/root", "file-1.txt", true); - auto file2 = fs_util::find(TESTS_BINARY_DIR "/root", "file-2.txt", true); + auto file1 = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", "file-1.txt", true); + auto file2 = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", "file-2.txt", true); BOOST_TEST(file1.find("file-1.txt") != std::string::npos); BOOST_TEST(file2.find("file-2.txt") != std::string::npos); @@ -511,7 +511,7 @@ { const std::regex regex("file-[12]\\.txt"); - auto file = fs_util::find(TESTS_BINARY_DIR "/root", regex, false); + auto file = fs_util::find(CMAKE_SOURCE_DIR "/tests/root", regex, false); BOOST_TEST(file.find("file-1.txt") != std::string::npos); } @@ -520,7 +520,7 @@ { const std::regex regex("file-[12]\\.txt"); - auto file = fs_util::find(TESTS_BINARY_DIR "/root/level-a", regex, true); + auto file = fs_util::find(CMAKE_SOURCE_DIR "/tests/root/level-1", regex, true); BOOST_TEST(file.find("file-2.txt") != std::string::npos); }